Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: timestamp in every output line #909

Closed
cleo-yin opened this issue Sep 2, 2019 · 5 comments · Fixed by #1028
Closed

enhancement: timestamp in every output line #909

cleo-yin opened this issue Sep 2, 2019 · 5 comments · Fixed by #1028
Assignees

Comments

@cleo-yin
Copy link

cleo-yin commented Sep 2, 2019

  • Version of iperf3:
    iperf 3.7 (cJSON 1.5.2)

Enhancement Request

sometimes especially in wireless roaming test, we need the timestamp in the output per second, so we can know the exact time(in millisecond) that the throughput is going down, it's very helpful in the wireless roaming debugging.

  • Current behavior
    no timestamp for every output line
    $ iperf3 -c 127.0.0.1 -t 3 -u
    Connecting to host 127.0.0.1, port 5201
    warning: Block size 16332 > sending socket buffer size 9216
    Increasing socket buffer size to 17356
    [ 5] local 127.0.0.1 port 62057 connected to 127.0.0.1 port 5201
    [ ID] Interval Transfer Bitrate Total Datagrams
    [ 5] 0.00-1.00 sec 144 KBytes 1.18 Mbits/sec 9
    [ 5] 1.00-2.00 sec 128 KBytes 1.05 Mbits/sec 8
    [ 5] 2.00-3.00 sec 128 KBytes 1.05 Mbits/sec 8

[ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
[ 5] 0.00-3.00 sec 399 KBytes 1.09 Mbits/sec 0.000 ms 0/25 (0%) sender
[ 5] 0.00-3.00 sec 399 KBytes 1.09 Mbits/sec 0.019 ms 0/25 (0%) receiver

  • Desired behavior
    $ iperf3 -c 127.0.0.1 -t 3 -u --timestamp
    Connecting to host 127.0.0.1, port 5201
    warning: Block size 16332 > sending socket buffer size 9216
    Increasing socket buffer size to 17356
    [ 5] local 127.0.0.1 port 62878 connected to 127.0.0.1 port 5201
    Sep 02 15:19:31.524 [ ID] Interval Transfer Bitrate Total Datagrams
    Sep 02 15:19:31.524 [ 5] 0.00-1.00 sec 144 KBytes 1.18 Mbits/sec 9
    Sep 02 15:19:32.524 [ 5] 1.00-2.00 sec 128 KBytes 1.05 Mbits/sec 8
    Sep 02 15:19:33.525 [ 5] 2.00-3.00 sec 128 KBytes 1.05 Mbits/sec 8

Sep 02 15:19:33.525 [ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
Sep 02 15:19:33.525 [ 5] 0.00-3.00 sec 399 KBytes 1.09 Mbits/sec 0.000 ms 0/25 (0%) sender
Sep 02 15:19:33.525 [ 5] 0.00-3.00 sec 399 KBytes 1.09 Mbits/sec 0.018 ms 0/25 (0%) receiver

@buscseik
Copy link

buscseik commented Sep 5, 2019

I also would be very happy for this option

@justoneliu
Copy link

On windows, you can use powershell to add the timestamp
iperf -s -u -e -i 5 | Foreach{"{0}-{1}" -f (get-date),$_}
or save the log at the same time
iperf -s -u -e -i 5 | Foreach{"{0}-{1}" -f (get-date),$_} | tee /path/to/file

@bmah888
Copy link
Contributor

bmah888 commented Apr 27, 2020

This should be pretty easy for someone to do if they felt like hacking on iperf3. See iperf_print in src/iperf_api.c.

@davidBar-On
Copy link
Contributor

Assuming that accuracy of seconds is sufficient (millisec accuracy is no needed) then the following changes to iperf_printf() can be done to add current time at the beginning of each line (proposed changes are in bold):

**time_t now;
time(&now);**

if (test->role == 'c') {
    **fprintf(test->outfile, "%s ", ctime(&now));**
    if (test->title)
	....
}
else if (test->role == 's') {
    char linebuffer[1024];
    **int i;
    i = sprintf(linebuffer, "%s ", ctime(&now));**
    va_start(argp, format);
    r = vsnprintf(&**linebuffer[i]**, sizeof(linebuffer)**-i**, format, argp);
    va_end(argp);
    ....

It would be useful to also add the time in iperf_err() and iperf_errexit() messages. In addition it would be useful to add errno value to these messages (to debug issues such as #499). Therefore, the suggested changes to these two functions are (changes in bold):

Add in both functions:
    **time_t now;
    time(&now);**

Changes to the 4 fprintf():
    fprintf(test->outfile, "**%s** iperf3: %s **\(errno=%d - %s\)**\n", **ctime(&now),** str, **errno, strerror(errno)**);

Changes to the 2 cJSON_AddStringToObject():
	**sprintf(str, "%s ", ctime(&now));**
	va_start(argp, format);
	vsnprintf(**&str[strlen(str)]**, sizeof(str)**-strlen(str)**, format, argp);
	......

@davidBar-On
Copy link
Contributor

Resending - now bold is bold and not ** bold **.

Changes to iperf_printf()

Assuming that accuracy of seconds is sufficient (millisec accuracy is no needed) then the following changes to iperf_printf() can be done to add current time at the beginning of each line (proposed changes are in bold):

time_t now;
time(&now);

if (test->role == 'c') {
    fprintf(test->outfile, "%s ", ctime(&now));
    if (test->title)
    ....
}
else if (test->role == 's') {
    char linebuffer[1024];
    int i;
    i = sprintf(linebuffer, "%s ", ctime(&now));
    va_start(argp, format);
    r = vsnprintf(&linebuffer[i], sizeof(linebuffer)-i, format, argp);
    va_end(argp);
    ....

Changes to iperf_err() and iperf_errexit()

It would be useful to also add the time in iperf_err() and iperf_errexit() messages. In addition it would be useful to add errno value to these messages (to debug issues such as #499). Therefore, the suggested changes to these two functions are (changes in bold):

Add in both functions:

    time_t now;
    time(&now);

Changes to the 4 fprintf():

    fprintf(test->outfile, "%s iperf3: %s \(errno=%d - %s\)\n", ctime(&now), str, errno, strerror(errno));

Changes to the 2 cJSON_AddStringToObject():

	sprintf(str, "%s ", ctime(&now));
	va_start(argp, format);
	vsnprintf(&str[strlen(str)], sizeof(str)*-strlen(str), format, argp);
	......

@bmah888 bmah888 mentioned this issue Jul 13, 2020
bmah888 added a commit that referenced this issue Jul 15, 2020
@bmah888 bmah888 self-assigned this Jul 15, 2020
bmah888 added a commit that referenced this issue Jul 23, 2020
…#1028)

This flag takes an optional argument, which is a format specification to strftime(3)...this allows for custom timestamp formats.  Based on a suggested implementation by @davidBar-On.  Towards #909.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants