void JSON_stats( Transfer_Info *stats ) { max_size_t speed = (max_size_t)(((double)stats->TotalLen * 8.0) / (stats->endTime - stats->startTime)); char timestamp[128]; JSON_timestamp( timestamp, sizeof(timestamp) ); if ( stats->mUDP != (char)kMode_Server ) { // TCP Reporting printf( reportJSON_bw_format, timestamp, (stats->reserved_delay == NULL ? "{}" : stats->reserved_delay), stats->transferID, stats->startTime, stats->endTime, stats->TotalLen, speed); } else { // UDP Reporting printf( reportJSON_bw_jitter_loss_format, timestamp, (stats->reserved_delay == NULL ? "{}" : stats->reserved_delay), stats->transferID, stats->startTime, stats->endTime, stats->TotalLen, speed, stats->jitter*1000.0, stats->cntError, stats->cntDatagrams, (100.0 * stats->cntError) / stats->cntDatagrams, stats->cntOutofOrder ); } if ( stats->free == 1 && stats->reserved_delay != NULL ) { free( stats->reserved_delay ); } }
/* * Print stats in json format * {"end-time": val, "interval": val, "samples": [speed, speed, speed, ... ]} */ void JSON_stats( Transfer_Info *stats ) { max_size_t speed; int i; FILE * fp; char timestamp[16]; JSON_timestamp( timestamp, sizeof(timestamp) ); if (stats->outputfilename) { fp = fopen(stats->outputfilename, "w"); if (fp == NULL) { fp = stdout; } } else { fp = stdout; } fprintf (fp, reportJSON_format_opening); if (stats->sampleIndex) { i = 0; do { speed = stats->speedSamples[i]; fprintf (fp, reportJSON_sample_format, speed); if (++i < stats->sampleIndex) { fprintf (fp, ", "); } else { break; } } while (i < stats->sampleIndex); } else { speed = (max_size_t)(((double)stats->TotalLen * 8.0) / (stats->endTime - stats->startTime)); fprintf (fp, reportJSON_sample_format, speed); } fprintf (fp, reportJSON_format_closing, stats->startTime, stats->endTime - stats->startTime, timestamp); if (fp != stdout) { fclose(fp); } if ( stats->free == 1 && stats->reserved_delay != NULL ) { free( stats->reserved_delay ); } }