Changeset d9a4dc2
- Timestamp:
- 11/19/18 10:14:26 (2 years ago)
- Branches:
- develop
- Children:
- 91852de2
- Parents:
- dbd745c
- Location:
- examples/stats
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
examples/stats/ipdist-parallel.c
rdbd745c rd9a4dc2 418 418 } 419 419 420 static void plot_results(struct addr_local *tally, uint64_t tick) {420 static void output_results(struct addr_local *tally, uint64_t tick) { 421 421 422 422 int i, j, k; … … 493 493 /* If k is 0 we are doing src else dst */ 494 494 if(k) { 495 snprintf(outputfile2, sizeof(outputfile2), "%sipdist- timeseries-dst-octet%d.data", stats_outputdir, j+1);495 snprintf(outputfile2, sizeof(outputfile2), "%sipdist-dst-octet%d.timeseries", stats_outputdir, j+1); 496 496 } else { 497 snprintf(outputfile2, sizeof(outputfile2), "%sipdist- timeseries-src-octet%d.data", stats_outputdir, j+1);497 snprintf(outputfile2, sizeof(outputfile2), "%sipdist-src-octet%d.timeseries", stats_outputdir, j+1); 498 498 } 499 499 if(tally->output_count == 0) { … … 519 519 } 520 520 } 521 522 /* Plot the results */523 for(i=0;i<4;i++) {524 char outputplot[255];525 snprintf(outputplot, sizeof(outputplot), "%sipdist-%lu-octet%d.png", stats_outputdir, tick, i+1);526 /* Open pipe to gnuplot */527 FILE *gnuplot = popen("gnuplot -persistent", "w");528 /* send all commands to gnuplot */529 fprintf(gnuplot, "set term pngcairo enhanced size 1280,960\n");530 fprintf(gnuplot, "set output '%s'\n", outputplot);531 fprintf(gnuplot, "set multiplot layout 2,1\n");532 fprintf(gnuplot, "set title 'IP Distribution - %lu'\n", tick);533 fprintf(gnuplot, "set xrange[0:255]\n");534 fprintf(gnuplot, "set y2range[-1:1]\n");535 fprintf(gnuplot, "set y2tics\n");536 fprintf(gnuplot, "set xlabel 'Prefix'\n");537 fprintf(gnuplot, "set ylabel 'Hits'\n");538 fprintf(gnuplot, "set y2label 'Skewness'\n");539 fprintf(gnuplot, "set xtics 0,10,255\n");540 /* Setup labels that hold mean, standard deviation and variance */541 fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 2 name 'SOURCEMEAN' nooutput\n", outputfile_stats, i);542 //fprintf(gnuplot, "set label 1 gprintf(\"Source Mean %u\", SOURCEMEAN_min) at graph 0.02, 0.95\n");543 fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 2 name 'DESTMEAN' nooutput\n", outputfile_stats, i);544 //fprintf(gnuplot, "set label 2 gprintf(\"Destination Mean: %f\", DESTMEAN_min) at graph 0.02, 0.90\n");545 //fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 3 name 'SOURCESTDDEV' nooutput\n", outputfile_stats, i);546 //fprintf(gnuplot, "set label 3 sprintf('Source Standard Deviation: %f', SOURCESTDDEV_min) at graph 0.24, 0.95\n");547 //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 3 name 'DESTSTDDEV' nooutput\n", outputfile_stats, i);548 //fprintf(gnuplot, "set label 4 sprintf('Destination Standard Deviation: %f', DESTSTDDEV_min) at graph 0.24, 0.90\n");549 //fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 4 name 'SOURCEVAR' nooutput\n", outputfile_stats, i);550 //fprintf(gnuplot, "set label 5 sprintf('Source Variance: %f', SOURCEVAR_min) at graph 0.55, 0.95\n");551 //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 4 name 'DESTVAR' nooutput\n", outputfile_stats, i);552 //fprintf(gnuplot, "set label 6 sprintf('Destination Variance: %f', DESTVAR_min) at graph 0.55, 0.90\n");553 fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 7 name 'SOURCESKEW' nooutput\n", outputfile_stats, i);554 fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 7 name 'DESTSKEW' nooutput\n", outputfile_stats, i);555 /* Plot the first graph of the multiplot */556 fprintf(gnuplot, "set arrow from SOURCEMEAN_min, graph 0 to SOURCEMEAN_min, graph 1 nohead lt 1\n");557 fprintf(gnuplot, "set arrow from DESTMEAN_min, graph 0 to DESTMEAN_min, graph 1 nohead lt 2\n");558 fprintf(gnuplot, "plot '%s' using %d:%d index 0 title 'Source octet %d' smooth unique with boxes,", outputfile, (i*4)+3,(i*4)+4, i+1);559 fprintf(gnuplot, "'%s' using %d:%d index 0 title 'Destination octet %d' smooth unique with boxes,", outputfile, (i*4)+5, (i*4)+6, i+1);560 fprintf(gnuplot, "1/0 t 'Source mean' lt 1,");561 fprintf(gnuplot, "1/0 t 'Destination mean' lt 2,");562 fprintf(gnuplot, "SOURCESKEW_min title 'Source Skewness' axes x1y2,");563 fprintf(gnuplot, "DESTSKEW_min title 'Destination Skewness' axes x1y2\n");564 /* Unset labels for next plot */565 fprintf(gnuplot, "unset y2tics\n");566 fprintf(gnuplot, "unset y2label\n");567 fprintf(gnuplot, "unset arrow\n");568 fprintf(gnuplot, "unset label 1\nunset label 2\nunset label 3\nunset label 4\nunset label 5\nunset label 6\n");569 fprintf(gnuplot, "set title 'Zipf Distribution'\n");570 fprintf(gnuplot, "set xlabel 'Rank'\n");571 fprintf(gnuplot, "set ylabel 'Frequency'\n");572 fprintf(gnuplot, "set logscale xy 10\n");573 fprintf(gnuplot, "set xrange[1:255]\n");574 fprintf(gnuplot, "set xtics 0,10,255\n");575 /* Plot the second graph of the multiplot */576 fprintf(gnuplot, "plot '%s' using 2:%d index 0 title 'Source octet %d',", outputfile, (i*4)+4, i+1);577 fprintf(gnuplot, "'%s' using 2:%d index 0 title 'Destination octet %d'\n", outputfile, (i*4)+6, i+1);578 fprintf(gnuplot, "unset multiplot\n");579 pclose(gnuplot);580 }581 582 /* Plot time series */583 for(k=0;k<2;k++) {584 for(i=0;i<4;i++) {585 char outputplot2[255];586 if(k) {587 snprintf(outputplot2, sizeof(outputplot2), "%sipdist-timeseries-dst-octet%i.png", stats_outputdir, i+1);588 } else {589 snprintf(outputplot2, sizeof(outputplot2), "%sipdist-timeseries-src-octet%i.png", stats_outputdir, i+1);590 }591 FILE *gnuplot = popen("gnuplot -persistent", "w");592 fprintf(gnuplot, "set term pngcairo size 1280,960 \n");593 fprintf(gnuplot, "set output '%s'\n", outputplot2);594 fprintf(gnuplot, "set multiplot layout 2,1\n");595 if(k) {596 fprintf(gnuplot, "set title 'Timeseries Dst Octet %i'\n", i+1);597 } else {598 fprintf(gnuplot, "set title 'Timeseries Src Octet %i'\n", i+1);599 }600 fprintf(gnuplot, "set xtics rotate\n");601 fprintf(gnuplot, "set y2tics\n");602 fprintf(gnuplot, "set xlabel 'Timestamp'\n");603 fprintf(gnuplot, "set ylabel 'Cumulative hits'\n");604 //fprintf(gnuplot, "set key out vert\n");605 fprintf(gnuplot, "set key off\n");606 //fprintf(gnuplot, "set xdata time\n");607 //fprintf(gnuplot, "set timefmt '%%s'\n");608 //fprintf(gnuplot, "set format x '%%m/%%d/%%Y %%H:%%M:%%S'\n");609 fprintf(gnuplot, "set autoscale xy\n");610 if(k) {611 fprintf(gnuplot, "plot '%sipdist-timeseries-dst-octet%d.data' using 2:xtic(1) with lines title columnheader(2) smooth cumulative, for[i=3:257] '' using i with lines title columnheader(i) smooth cumulative\n", stats_outputdir, i+1);612 } else {613 fprintf(gnuplot, "plot '%sipdist-timeseries-src-octet%d.data' using 2:xtic(1) with lines title columnheader(2) smooth cumulative, for[i=3:257] '' using i with lines title columnheader(i) smooth cumulative\n", stats_outputdir, i+1);614 }615 /* Draw the mean skewness line */616 fprintf(gnuplot, "set title 'Timeseries mean skewness\n");617 fprintf(gnuplot, "set yrange[-1:1]\n");618 fprintf(gnuplot, "set xlabel 'Timestamp'\n");619 fprintf(gnuplot, "set ylabel 'Skewness'\n");620 fprintf(gnuplot, "plot '%sipdist-timeseries-skewness.stats' using %d:xtic(1) with lines title columnheader(%d)\n", stats_outputdir, (i*2)+2+k);621 fprintf(gnuplot, "unset multiplot");622 pclose(gnuplot);623 }624 }625 521 } 626 522 … … 665 561 tally->lastkey = key; 666 562 667 /* Plot the resultwith the key in epoch seconds*/668 plot_results(tally, key >> 32);563 /* Output the results with the key in epoch seconds*/ 564 output_results(tally, key >> 32); 669 565 670 566 /* increment the output counter */ … … 715 611 /* If there is any remaining data in the tally plot it */ 716 612 if(tally->packets > 0) { 717 /* Then plot the results */718 plot_results(tally, (tally->lastkey >> 32) + 1);613 /* Then output the results */ 614 output_results(tally, (tally->lastkey >> 32) + 1); 719 615 } 720 616 /* Cleanup tally results*/ … … 723 619 724 620 static void libtrace_cleanup(libtrace_t *trace, libtrace_callback_set_t *processing, 725 libtrace_callback_set_t *reporting ) {621 libtrace_callback_set_t *reporting, struct exclude_networks *exclude) { 726 622 /* Only destroy if the structure exists */ 727 623 if(trace) { … … 733 629 if(reporting) { 734 630 trace_destroy_callback_set(reporting); 631 } 632 if(exclude->count > 0) { 633 free(exclude->networks); 634 } 635 if(exclude) { 636 free(exclude); 735 637 } 736 638 } … … 885 787 if(trace_pstart(trace, exclude, processing, reporter)) { 886 788 trace_perror(trace, "Starting parallel trace"); 887 libtrace_cleanup(trace, processing, reporter );789 libtrace_cleanup(trace, processing, reporter, exclude); 888 790 return 1; 889 791 } … … 893 795 894 796 /* Clean up everything */ 895 free(exclude->networks); 896 free(exclude); 897 libtrace_cleanup(trace, processing, reporter); 797 libtrace_cleanup(trace, processing, reporter, exclude); 898 798 899 799 return 0;
Note: See TracChangeset
for help on using the changeset viewer.