Re: [PATCH mptcp-next] selftests: mptcp: print stats before socket closure

Matthieu Baerts <[email protected]>
Newsgroups dev.linux.lists.mptcp
Organization NGI0 Core
Message-ID <[email protected]>
Hi Paolo,

On 14/08/2026 18:44, Paolo Abeni wrote:
> On 8/14/26 4:07 PM, Matthieu Baerts (NGI0) wrote:
>> In case of poll timeout, it might be too late to print the stats after
>> the socket closure.
>>
>> Now, in case of poll timeout, 'ss' and 'nstat' are invoked from
>> mptcp_connect to print the stats before exiting. This should help
>> debugging poll timeout issues.
>>
>> Note: for this "workaround", system() is used for debugging purposes
>> only. The returned result can then be safely ignored.
>>
>> Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
>> ---
>>  tools/testing/selftests/net/mptcp/mptcp_connect.c | 15 +++++++++++++++
>>  1 file changed, 15 insertions(+)
>>
>> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
>> index ea4cb6c1bd5e..842c0eb99aa9 100644
>> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
>> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
>> @@ -210,6 +210,19 @@ static void xgetaddrinfo(const char *node, const char *service,
>>  	}
>>  }
>>  
>> +static void print_err_stats(void)
>> +{
>> +	char cmd[128];
>> +
>> +	snprintf(cmd, sizeof(cmd), "ss -Menitam -o '%cport = :%s' >&2",
>> +		 listen_mode ? 's' : 'd', cfg_port);
>> +
>> +	fprintf(stderr, "socket stats before socket closure:\n");
>> +	(void)!system(cmd);
>> +	(void)!system("NSTAT_HISTORY='/tmp/$(ip netns id).nstat' nstat -s | "
>> +		      "grep Tcp >&2");
> 
> Overall LGTM. I tried something similar in the past, but the correct
> redirection always fouled me. A couple of questions:

Thank you for having checked!

> - Is the '!' operator needed?

Yes, to avoid a warning because the results are unused. Only using
(void) is not enough from what I saw.

> - Can we avoid the pipe? with something alike the following:
> 	(void)system("NSTAT_HISTORY='/tmp/$(ip netns id).nstat' nstat -s *Tcp*

Oh nice, I didn't think about that. Yes it works except it keeps the
header (#kernel). Maybe fine here, but we don't change that in the .sh
scripts?

I can send a v2 with that and an extra explanation.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.