Changeset 36fb135
 Timestamp:
 11/16/18 13:22:29 (2 years ago)
 Branches:
 develop
 Children:
 dbd745c
 Parents:
 1f79936
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

examples/tutorial/ipdistparallel.c
r1f79936 r36fb135 21 21 /* Is the count of the number of packets processed, This is cleared after every output. */ 22 22 uint64_t packets; 23 /* Total number an output has been generated */ 23 24 uint64_t output_count; 24 25 /* Pointer to stats structure */ … … 29 30 float src[4][256]; 30 31 float dst[4][256]; 32 /* Stats calculated independently per output */ 31 33 double mode_src[4]; 32 34 double mode_dst[4]; … … 41 43 double skewness_src[4]; 42 44 double skewness_dst[4]; 45 /* Stats calculated over entire trace */ 46 double total_skewness_src[4]; 47 double total_skewness_dst[4]; 48 43 49 struct addr_rank *rank_src[4]; 44 50 struct addr_rank *rank_dst[4]; … … 204 210 tally>stats>skewness_src[k] = (tally>stats>mean_src[k]  tally>stats>median_src[k]) / tally>stats>stddev_src[k]; 205 211 tally>stats>skewness_dst[k] = (tally>stats>mean_dst[k]  tally>stats>median_dst[k]) / tally>stats>stddev_dst[k]; 212 213 /* Increment total skew */ 214 tally>stats>total_skewness_src[k] += tally>stats>skewness_src[k]; 215 tally>stats>total_skewness_dst[k] += tally>stats>skewness_dst[k]; 206 216 } 207 217 … … 416 426 tally>stats>skewness_src[i] = 0; 417 427 tally>stats>skewness_dst[i] = 0; 428 429 tally>stats>total_skewness_src[i] = 0; 430 tally>stats>total_skewness_dst[i] = 0; 418 431 } 419 432 tally>lastkey = 0; … … 477 490 } 478 491 fclose(tmp); 492 493 char outputfile_stats_timeseries[255]; 494 snprintf(outputfile_stats_timeseries, sizeof(outputfile_stats_timeseries), "%sipdisttimeseriesskewness.stats", stats_outputdir); 495 if(tally>output_count == 0) { 496 tmp = fopen(outputfile_stats_timeseries, "w"); 497 fprintf(tmp, "timestamp\tsrc1\t\tdst1\t\tsrc2\t\tdst2\t\tsrc3\t\tdst3\t\tsrc4\t\tdst4"); 498 } else { 499 tmp = fopen(outputfile_stats_timeseries, "a"); 500 } 501 fprintf(tmp, "\n%lu\t", tick); 502 for(k=0;k<4;k++) { 503 fprintf(tmp, "%f\t", tally>stats>total_skewness_src[k] / (tally>output_count+1)); 504 fprintf(tmp, "%f\t", tally>stats>total_skewness_dst[k] / (tally>output_count+1)); 505 } 506 fclose(tmp); 479 507 480 508 /* Puts data into timeseries files that gnuplot likes */ … … 532 560 fprintf(gnuplot, "set output '%s'\n", outputplot); 533 561 fprintf(gnuplot, "set multiplot layout 2,1\n"); 534 fprintf(gnuplot, "set title 'IP Distribution '\n");562 fprintf(gnuplot, "set title 'IP Distribution  %lu'\n", tick); 535 563 fprintf(gnuplot, "set xrange[0:255]\n"); 564 fprintf(gnuplot, "set y2range[1:1]\n"); 565 fprintf(gnuplot, "set y2tics\n"); 536 566 fprintf(gnuplot, "set xlabel 'Prefix'\n"); 537 567 fprintf(gnuplot, "set ylabel 'Hits'\n"); 568 fprintf(gnuplot, "set y2label 'Skewness'\n"); 538 569 fprintf(gnuplot, "set xtics 0,10,255\n"); 539 570 /* Setup labels that hold mean, standard deviation and variance */ … … 550 581 //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 4 name 'DESTVAR' nooutput\n", outputfile_stats, i); 551 582 //fprintf(gnuplot, "set label 6 sprintf('Destination Variance: %f', DESTVAR_min) at graph 0.55, 0.90\n"); 583 fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 7 name 'SOURCESKEW' nooutput\n", outputfile_stats, i); 584 fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 7 name 'DESTSKEW' nooutput\n", outputfile_stats, i); 552 585 /* Plot the first graph of the multiplot */ 553 586 fprintf(gnuplot, "set arrow from SOURCEMEAN_min, graph 0 to SOURCEMEAN_min, graph 1 nohead lt 1\n"); … … 556 589 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); 557 590 fprintf(gnuplot, "1/0 t 'Source mean' lt 1,"); 558 fprintf(gnuplot, "1/0 t 'Destination mean' lt 2\n"); 591 fprintf(gnuplot, "1/0 t 'Destination mean' lt 2,"); 592 fprintf(gnuplot, "SOURCESKEW_min title 'Source Skewness' axes x1y2,"); 593 fprintf(gnuplot, "DESTSKEW_min title 'Destination Skewness' axes x1y2\n"); 559 594 /* Unset labels for next plot */ 595 fprintf(gnuplot, "unset y2tics\n"); 596 fprintf(gnuplot, "unset y2label\n"); 560 597 fprintf(gnuplot, "unset arrow\n"); 561 598 fprintf(gnuplot, "unset label 1\nunset label 2\nunset label 3\nunset label 4\nunset label 5\nunset label 6\n"); … … 585 622 fprintf(gnuplot, "set term pngcairo size 1280,960 \n"); 586 623 fprintf(gnuplot, "set output '%s'\n", outputplot2); 624 fprintf(gnuplot, "set multiplot layout 2,1\n"); 587 625 if(k) { 588 fprintf(gnuplot, "set title 'Timeseries Dst Octet %i  Cumulative'\n", i+1);626 fprintf(gnuplot, "set title 'Timeseries Dst Octet %i'\n", i+1); 589 627 } else { 590 fprintf(gnuplot, "set title 'Timeseries Src Octet %i  Cumulative'\n", i+1);628 fprintf(gnuplot, "set title 'Timeseries Src Octet %i'\n", i+1); 591 629 } 592 630 fprintf(gnuplot, "set xtics rotate\n"); 631 fprintf(gnuplot, "set y2tics\n"); 632 fprintf(gnuplot, "set xlabel 'Timestamp'\n"); 633 fprintf(gnuplot, "set ylabel 'Cumulative hits'\n"); 593 634 //fprintf(gnuplot, "set key out vert\n"); 594 635 fprintf(gnuplot, "set key off\n"); … … 598 639 fprintf(gnuplot, "set autoscale xy\n"); 599 640 if(k) { 600 //if(gnuplot_version < 5) { 601 fprintf(gnuplot, "plot '%sipdisttimeseriesdstoctet%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); 602 //} else { 603 // fprintf(gnuplot, "plot '%sipdisttimeseriesdstoctet%d.data' using 2:xtic(1) with lines title columnheader(2) at end smooth cumulative, for[i=3:257] '' using i with lines title columnheader(i) at end smooth cumulative\n", stats_outputdir, i+1); 604 //} 641 fprintf(gnuplot, "plot '%sipdisttimeseriesdstoctet%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); 605 642 } else { 606 //if(gnuplot_version < 5) { 607 fprintf(gnuplot, "plot '%sipdisttimeseriessrcoctet%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); 608 //} else { 609 // fprintf(gnuplot, "plot '%sipdisttimeseriessrcoctet%d.data' using 2:xtic(1) with lines title columnheader(2) at end smooth cumulative, for[i=3:257] '' using i with lines title columnheader(i) at end smooth cumulative\n", stats_outputdir, i+1); 610 //} 643 fprintf(gnuplot, "plot '%sipdisttimeseriessrcoctet%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); 611 644 } 612 fprintf(gnuplot, "replot"); 645 /* Draw the mean skewness line */ 646 fprintf(gnuplot, "set title 'Timeseries mean skewness\n"); 647 fprintf(gnuplot, "set yrange[1:1]\n"); 648 fprintf(gnuplot, "set xlabel 'Timestamp'\n"); 649 fprintf(gnuplot, "set ylabel 'Skewness'\n"); 650 fprintf(gnuplot, "plot '%sipdisttimeseriesskewness.stats' using %d:xtic(1) with lines title columnheader(%d)\n", stats_outputdir, (i*2)+2+k); 651 fprintf(gnuplot, "unset multiplot"); 613 652 pclose(gnuplot); 614 653 }
Note: See TracChangeset
for help on using the changeset viewer.