Ignore:
Timestamp:
11/16/18 13:22:29 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
dbd745c
Parents:
1f79936
Message:

Added more skewness plots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/tutorial/ipdist-parallel.c

    r1f79936 r36fb135  
    2121        /* Is the count of the number of packets processed, This is cleared after every output. */
    2222        uint64_t packets;
     23        /* Total number an output has been generated */
    2324        uint64_t output_count;
    2425        /* Pointer to stats structure */
     
    2930        float src[4][256];
    3031        float dst[4][256];
     32        /* Stats calculated independently per output */
    3133        double mode_src[4];
    3234        double mode_dst[4];
     
    4143        double skewness_src[4];
    4244        double skewness_dst[4];
     45        /* Stats calculated over entire trace */
     46        double total_skewness_src[4];
     47        double total_skewness_dst[4];
     48
    4349        struct addr_rank *rank_src[4];
    4450        struct addr_rank *rank_dst[4];
     
    204210                tally->stats->skewness_src[k] = (tally->stats->mean_src[k] - tally->stats->median_src[k]) / tally->stats->stddev_src[k];
    205211                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];
    206216        }
    207217
     
    416426                tally->stats->skewness_src[i] = 0;
    417427                tally->stats->skewness_dst[i] = 0;
     428
     429                tally->stats->total_skewness_src[i] = 0;
     430                tally->stats->total_skewness_dst[i] = 0;
    418431        }
    419432        tally->lastkey = 0;
     
    477490        }
    478491        fclose(tmp);
     492
     493        char outputfile_stats_timeseries[255];
     494        snprintf(outputfile_stats_timeseries, sizeof(outputfile_stats_timeseries), "%sipdist-timeseries-skewness.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);
    479507
    480508        /* Puts data into timeseries files that gnuplot likes */
     
    532560                fprintf(gnuplot, "set output '%s'\n", outputplot);
    533561                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);
    535563                fprintf(gnuplot, "set xrange[0:255]\n");
     564                fprintf(gnuplot, "set y2range[-1:1]\n");
     565                fprintf(gnuplot, "set y2tics\n");
    536566                fprintf(gnuplot, "set xlabel 'Prefix'\n");
    537567                fprintf(gnuplot, "set ylabel 'Hits'\n");
     568                fprintf(gnuplot, "set y2label 'Skewness'\n");
    538569                fprintf(gnuplot, "set xtics 0,10,255\n");
    539570                /* Setup labels that hold mean, standard deviation and variance */
     
    550581                //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 4 name 'DESTVAR' nooutput\n", outputfile_stats, i);
    551582                //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);
    552585                /* Plot the first graph of the multiplot */
    553586                fprintf(gnuplot, "set arrow from SOURCEMEAN_min, graph 0 to SOURCEMEAN_min, graph 1 nohead lt 1\n");
     
    556589                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);
    557590                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");
    559594                /* Unset labels for next plot */
     595                fprintf(gnuplot, "unset y2tics\n");
     596                fprintf(gnuplot, "unset y2label\n");
    560597                fprintf(gnuplot, "unset arrow\n");
    561598                fprintf(gnuplot, "unset label 1\nunset label 2\nunset label 3\nunset label 4\nunset label 5\nunset label 6\n");
     
    585622                        fprintf(gnuplot, "set term pngcairo size 1280,960 \n");
    586623                        fprintf(gnuplot, "set output '%s'\n", outputplot2);
     624                        fprintf(gnuplot, "set multiplot layout 2,1\n");
    587625                        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);
    589627                        } 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);
    591629                        }
    592630                        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");
    593634                        //fprintf(gnuplot, "set key out vert\n");
    594635                        fprintf(gnuplot, "set key off\n");
     
    598639                        fprintf(gnuplot, "set autoscale xy\n");
    599640                        if(k) {
    600                                 //if(gnuplot_version < 5) {
    601                                         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);
    602                                 //} else {
    603                                 //      fprintf(gnuplot, "plot '%sipdist-timeseries-dst-octet%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 '%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);
    605642                        } else {
    606                                 //if(gnuplot_version < 5) {
    607                                         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);
    608                                 //} else {
    609                                 //      fprintf(gnuplot, "plot '%sipdist-timeseries-src-octet%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 '%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);
    611644                        }
    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 '%sipdist-timeseries-skewness.stats' using %d:xtic(1) with lines title columnheader(%d)\n", stats_outputdir, (i*2)+2+k);
     651                        fprintf(gnuplot, "unset multiplot");
    613652                        pclose(gnuplot);
    614653                }
Note: See TracChangeset for help on using the changeset viewer.