Squashed commit of the following:

commit 23ef0d047fb5396df671be9245f7872153fc299c
Author: Bruce A. Mah <bmah@es.net>
Date:   Mon Apr 7 13:35:29 2014 -0700

    Add a few API calls to the client-side example program so we can
    exercise recently-added JSON-related functionality.

commit 5f8301e8d0380133d533da9b2e39ca4ac522e1c3
Author: Bruce A. Mah <bmah@es.net>
Date:   Mon Apr 7 13:16:39 2014 -0700

    Revert part of earlier change.

    We still want to save the JSON for libiperf consumers that might want it,
    but preserve the prior behavior of writing that JSON to stdout.  This
    maintains (roughly) the behavior of older libiperf, in which libiperf
    consumers (such as the iperf3 executable) do not need to explicitly print
    the JSON if that's all they're doing with it.

commit 173dcdb05867af00103205bfe39d1b71e18689e9
Author: Bruce A. Mah <bmah@es.net>
Date:   Tue Mar 25 13:55:45 2014 -0700

    Update manpage for newly-added library calls.

    Bump document date while here.

    Part of Issue #147.

commit 51a275de9463febc440d41cee9d971fcd381e01c
Author: Bruce A. Mah <bmah@es.net>
Date:   Tue Mar 25 13:30:09 2014 -0700

    Allow consumers of libiperf3 to get the JSON output for a just-completed test.

    This changes the behavior of iperf_json_finish() so that it no longer
    outputs JSON output, but saves the rendered output in a NUL-terminated
    string buffer.  After calling iperf_run_server() or iperf_run_client(),
    the client application should check iperf_get_test_json_output() to see
    if it returns a non-NULL pointer.  If so, there is JSON data available
    for it to print or otherwise consume.  The buffer is automatically
    deallocated when the containing iperf_test structure is deallocated
    with iperf_free_test().

    Also adds a new API call iperf_get_test_outfile() to find the output
    FILE* structure.

    Modifies the iperf3 application to use the new API.  Users of iperf3
    will not notice any functional change.

    No effect in "normal" output mode (non-JSON).
This commit is contained in:
Bruce A. Mah 2014-04-07 14:12:47 -07:00
parent 8c369d40f4
commit 2939863b1a
No known key found for this signature in database
GPG Key ID: 4984910A8CAAEE8A
6 changed files with 38 additions and 10 deletions

View File

@ -47,12 +47,18 @@ main( int argc, char** argv )
iperf_set_test_duration( test, 5 );
iperf_set_test_reporter_interval( test, 1 );
iperf_set_test_stats_interval( test, 1 );
/* iperf_set_test_json_output( test, 1 ); */
if ( iperf_run_client( test ) < 0 ) {
fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
exit( EXIT_FAILURE );
}
if (iperf_get_test_json_output_string(test)) {
fprintf(iperf_get_test_outfile(test), "%zd bytes of JSON emitted\n",
strlen(iperf_get_test_json_output_string(test)));
}
iperf_free_test( test );
exit( EXIT_SUCCESS );
}

View File

@ -193,6 +193,7 @@ struct iperf_test
int multisend;
int may_use_sigalrm;
char *json_output_string; /* rendered JSON output if json_output is set */
/* Select related parameters */
int max_fd;
fd_set read_set; /* set of read sockets */

View File

@ -145,6 +145,12 @@ iperf_get_test_blksize(struct iperf_test *ipt)
return ipt->settings->blksize;
}
FILE *
iperf_get_test_outfile (struct iperf_test *ipt)
{
return ipt->outfile;
}
int
iperf_get_test_socket_bufsize(struct iperf_test *ipt)
{
@ -193,6 +199,12 @@ iperf_get_test_json_output(struct iperf_test *ipt)
return ipt->json_output;
}
char *
iperf_get_test_json_output_string(struct iperf_test *ipt)
{
return ipt->json_output_string;
}
int
iperf_get_test_zerocopy(struct iperf_test *ipt)
{
@ -1681,6 +1693,11 @@ iperf_free_test(struct iperf_test *test)
free(prot);
}
if (test->json_output_string) {
free(test->json_output_string);
test->json_output_string = NULL;
}
/* XXX: Why are we setting these values to NULL? */
// test->streams = NULL;
test->stats_callback = NULL;
@ -2535,14 +2552,11 @@ iperf_json_start(struct iperf_test *test)
int
iperf_json_finish(struct iperf_test *test)
{
char *str;
str = cJSON_Print(test->json_top);
if (str == NULL)
test->json_output_string = cJSON_Print(test->json_top);
if (test->json_output_string == NULL)
return -1;
fprintf(test->outfile, "%s\n", str);
fprintf(test->outfile, "%s\n", test->json_output_string);
iflush(test);
free(str);
cJSON_Delete(test->json_top);
test->json_top = test->json_start = test->json_intervals = test->json_end = NULL;
return 0;

View File

@ -57,6 +57,7 @@ int iperf_get_test_duration( struct iperf_test* ipt );
char iperf_get_test_role( struct iperf_test* ipt );
int iperf_get_test_reverse( struct iperf_test* ipt );
int iperf_get_test_blksize( struct iperf_test* ipt );
FILE* iperf_get_test_outfile( struct iperf_test* ipt );
uint64_t iperf_get_test_rate( struct iperf_test* ipt );
int iperf_get_test_burst( struct iperf_test* ipt );
int iperf_get_test_socket_bufsize( struct iperf_test* ipt );
@ -67,6 +68,7 @@ int iperf_get_test_server_port( struct iperf_test* ipt );
char* iperf_get_test_server_hostname( struct iperf_test* ipt );
int iperf_get_test_protocol_id( struct iperf_test* ipt );
int iperf_get_test_json_output( struct iperf_test* ipt );
char* iperf_get_test_json_output_string ( struct iperf_test* ipt );
int iperf_get_test_zerocopy( struct iperf_test* ipt );
int iperf_get_test_may_use_sigalrm( struct iperf_test* ipt );

View File

@ -1,4 +1,4 @@
.TH LIBIPERF 3 "February 2014" ESnet "User Manuals"
.TH LIBIPERF 3 "March 2014" ESnet "User Manuals"
.SH NAME
libiperf \- API for iperf3 network throughput tester
@ -39,6 +39,11 @@ Running a test:
int iperf_run_server(struct iperf_test *);
void iperf_test_reset(struct iperf_test *);
.fi
Output:
.nf
FILE *iperf_get_test_outfile(struct iperf_test *);
char* iperf_get_test_json_output_string(struct iperf_test *);
.fi
Error reporting:
.nf
void iperf_err(struct iperf_test *t, const char *format, ...);

View File

@ -117,7 +117,7 @@ run(struct iperf_test *test)
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
}
for (;;) {
if (iperf_run_server(test) < 0) {
if (iperf_run_server(test) < 0) {
iperf_err(test, "error - %s", iperf_strerror(i_errno));
fprintf(stderr, "\n");
++consecutive_errors;
@ -131,8 +131,8 @@ run(struct iperf_test *test)
}
iperf_delete_pidfile(test);
break;
case 'c':
if (iperf_run_client(test) < 0)
case 'c':
if (iperf_run_client(test) < 0)
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
break;
default: