Skip to content

Commit 85d0171

Browse files
committed
add ability to get full JSON result object with streams enabled
1 parent 84c49f2 commit 85d0171

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/iperf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ struct iperf_test
350350
int verbose; /* -V option - verbose mode */
351351
int json_output; /* -J option - JSON output */
352352
int json_stream; /* --json-stream */
353+
int json_stream_full_output; /* --json-stream-full-output */
353354
void (*json_callback) (struct iperf_test *, char *); /* allow user apps to receive the
354355
JSON strings,instead of writing them to the output file */
355356
int zerocopy; /* -Z option - use sendfile */

src/iperf_api.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,12 @@ iperf_set_test_json_stream(struct iperf_test *ipt, int json_stream)
697697
ipt->json_stream = json_stream;
698698
}
699699

700+
void
701+
iperf_set_test_json_stream_full_output( struct iperf_test* ipt, int json_stream_full_output )
702+
{
703+
ipt->json_stream_full_output = json_stream_full_output;
704+
}
705+
700706
void
701707
iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)(struct iperf_test *, char *))
702708
{
@@ -1089,6 +1095,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
10891095
{"verbose", no_argument, NULL, 'V'},
10901096
{"json", no_argument, NULL, 'J'},
10911097
{"json-stream", no_argument, NULL, OPT_JSON_STREAM},
1098+
{"json-stream-full-output", no_argument, NULL, OPT_JSON_STREAM_FULL_OUTPUT},
10921099
{"version", no_argument, NULL, 'v'},
10931100
{"server", no_argument, NULL, 's'},
10941101
{"client", required_argument, NULL, 'c'},
@@ -1255,6 +1262,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
12551262
test->json_output = 1;
12561263
test->json_stream = 1;
12571264
break;
1265+
case OPT_JSON_STREAM_FULL_OUTPUT:
1266+
test->json_stream_full_output = 1;
1267+
break;
12581268
case 'v':
12591269
printf("%s (cJSON %s)\n%s\n%s\n", version, cJSON_Version(), get_system_info(),
12601270
get_optional_features());
@@ -3724,7 +3734,7 @@ iperf_print_intermediate(struct iperf_test *test)
37243734
*
37253735
* This avoids unneeded memory build up for long sessions.
37263736
*/
3727-
discard_json = test->json_stream == 1 && !(test->role == 's' && test->get_server_output);
3737+
discard_json = !test->json_stream_full_output && test->json_stream == 1 && !(test->role == 's' && test->get_server_output);
37283738

37293739
if (test->json_output) {
37303740
json_interval = cJSON_CreateObject();
@@ -5116,6 +5126,8 @@ iperf_json_finish(struct iperf_test *test)
51165126
cJSON_AddStringToObject(test->json_top, "server_output_text", test->server_output_text);
51175127
}
51185128

5129+
int print_full_json = 1;
5130+
51195131
/* --json-stream, so we print various individual objects */
51205132
if (test->json_stream) {
51215133
cJSON *error = iperf_cJSON_GetObjectItemType(test->json_top, "error", cJSON_String);
@@ -5129,9 +5141,12 @@ iperf_json_finish(struct iperf_test *test)
51295141
JSONStream_Output(test, "server_output_text", cJSON_CreateString(test->server_output_text));
51305142
}
51315143
JSONStream_Output(test, "end", test->json_end);
5144+
5145+
if (!test->json_stream_full_output)
5146+
print_full_json = 0;
51325147
}
51335148
/* Original --json output, single monolithic object */
5134-
else {
5149+
if (print_full_json) {
51355150
/*
51365151
* Get ASCII rendering of JSON structure. Then make our
51375152
* own copy of it and return the storage that cJSON

src/iperf_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef atomic_uint_fast64_t atomic_iperf_size_t;
104104
#define OPT_USE_PKCS1_PADDING 30
105105
#define OPT_CNTL_KA 31
106106
#define OPT_SKIP_RX_COPY 32
107+
#define OPT_JSON_STREAM_FULL_OUTPUT 33
107108

108109
/* states */
109110
#define TEST_START 1
@@ -155,6 +156,7 @@ int iperf_get_test_protocol_id( struct iperf_test* ipt );
155156
int iperf_get_test_json_output( struct iperf_test* ipt );
156157
char* iperf_get_test_json_output_string ( struct iperf_test* ipt );
157158
int iperf_get_test_json_stream( struct iperf_test* ipt );
159+
int iperf_get_test_json_stream_full_output( struct iperf_test* ipt );
158160
int iperf_get_test_zerocopy( struct iperf_test* ipt );
159161
int iperf_get_test_get_server_output( struct iperf_test* ipt );
160162
char iperf_get_test_unit_format(struct iperf_test *ipt);
@@ -200,6 +202,7 @@ void iperf_set_test_template( struct iperf_test *ipt, const char *tmp_templat
200202
void iperf_set_test_reverse( struct iperf_test* ipt, int reverse );
201203
void iperf_set_test_json_output( struct iperf_test* ipt, int json_output );
202204
void iperf_set_test_json_stream( struct iperf_test* ipt, int json_stream );
205+
void iperf_set_test_json_stream_full_output( struct iperf_test* ipt, int json_stream_full_output );
203206
void iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)(struct iperf_test *, char *));
204207
int iperf_has_zerocopy( void );
205208
void iperf_set_test_zerocopy( struct iperf_test* ipt, int zerocopy );

src/iperf_locale.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
118118
" -V, --verbose more detailed output\n"
119119
" -J, --json output in JSON format\n"
120120
" --json-stream output in line-delimited JSON format\n"
121+
" --json-stream-full-output output in JSON format with JSON streams enabled\n"
121122
" --logfile f send output to a log file\n"
122123
" --forceflush force flushing output at every interval\n"
123124
" --timestamps<=format> emit a timestamp at the start of each output line\n"

0 commit comments

Comments
 (0)