Changeset ccb2507


Ignore:
Timestamp:
11/10/18 22:32:09 (2 years ago)
Author:
Jacob van Walraven <jacobvw@…>
Branches:
develop
Children:
6c8579e
Parents:
dc62550 (diff), 4d5e6b3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/jacobvw/libtrace

File:
1 edited

Legend:

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

    racffeb8 r4d5e6b3  
    1010/* Structure to hold the counters each thread has its own one of these */
    1111struct addr_local {
     12        /* Holds the counts of each number occurance per octet, These are cleared after every output. */
    1213        uint64_t src[4][256];
    1314        uint64_t dst[4][256];
     15        /* Maintains a running average over. Only used within the tally */
     16        uint64_t src_lastoutput[4][256];
     17        uint64_t dst_lastoutput[4][256];
     18        /* Holds the timestamp */
    1419        uint64_t lastkey;
     20        /* Is the count of the number of packets processed, This is cleared after every output. */
    1521        uint64_t packets;
     22        uint64_t output_count;
    1623};
    1724
     
    174181                 * Right shifting these converts them to seconds, tickrate is in seconds */
    175182                if((timestamp >> 32) >= (local->lastkey >> 32) + tickrate) {
    176                         per_tick(trace, thread,global, local, timestamp);
     183                        per_tick(trace, thread, global, local, timestamp);
    177184                        local->lastkey = timestamp;
    178185                }
     
    219226                        tally->src[i][j] = 0;
    220227                        tally->dst[i][j] = 0;
     228                        tally->src_lastoutput[i][j] = 0;
     229                        tally->dst_lastoutput[i][j] = 0;
    221230                }
    222231        }
    223232        tally->lastkey = 0;
    224233        tally->packets = 0;
     234        tally->output_count = 0;
    225235
    226236        return tally;
     
    228238
    229239static void plot_results(struct addr_local *tally, uint64_t tick) {
    230 
    231         /* Get the current time */
    232         time_t current_time = time(NULL);
    233240
    234241        char outputfile[255];
     
    240247        FILE *tmp = fopen(outputfile, "w");
    241248        int i, j;
    242         fprintf(tmp, "#num\toctet1\t\toctet2\t\toctet3\t\toctet4\n");
    243         fprintf(tmp, "#\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\n");
     249        fprintf(tmp, "#Hits\t\t\t\t\t\t\t\t\tPercentage Change\n");
     250        fprintf(tmp, "#num\toctet1\t\toctet2\t\toctet3\t\toctet4\t\toctet1\t\toctet2\t\toctet3\t\toctet4\n");
     251        fprintf(tmp, "#\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\tsrc\tdst\n");
    244252        for(i=0;i<256;i++) {
    245253                fprintf(tmp, "%d", i);
     
    247255                        fprintf(tmp, "\t%d\t%d", tally->src[j][i], tally->dst[j][i]);
    248256                }
     257
     258                /* Calculates the percentage change from the last output */
     259                for(j=0;j<4;j++) {
     260                        float src_inc = 0;
     261                        float dst_inc = 0;
     262                        if(tally->src[j][i] != 0) {
     263                                src_inc = (((float)tally->src[j][i] - (float)tally->src_lastoutput[j][i]) / (float)tally->src[j][i]) * 100;
     264                        }
     265                        if(tally->dst[j][i] != 0) {
     266                                dst_inc = (((float)tally->dst[j][i] - (float)tally->dst_lastoutput[j][i]) / (float)tally->dst[j][i]) * 100;
     267                        }
     268                        fprintf(tmp, "\t%.0f\t%.0f", src_inc, dst_inc);
     269                }
     270
    249271                fprintf(tmp, "\n");
    250272        }
    251273        fclose(tmp);
    252         printf("wrote out to file %s\n", outputfile);
     274        printf("Ouput data file %s and plot %s\n", outputfile, outputplot);
    253275
    254276        /* Open pipe to gnuplot */
     
    260282        fprintf(gnuplot, "set xlabel 'Prefix'\n");
    261283        fprintf(gnuplot, "set ylabel 'Hits'\n");
     284        fprintf(gnuplot, "set y2label 'Percentage Change'\n");
    262285        fprintf(gnuplot, "set xtics 0,10,255\n");
    263         //fprintf(gnuplot, "set datafile commentschars '#!%'");
     286        fprintf(gnuplot, "set y2range[-100:100]\n");
     287        //fprintf(gnuplot, "set ytics nomirror\n");
     288        //fprintf(gnuplot, "set y2tics\n");
     289        //fprintf(gnuplot, "set tics out\n");
    264290        fprintf(gnuplot, "set output '%s'\n", outputplot);
    265         fprintf(gnuplot, "plot '%s' using 1:2 title 'Source address' with boxes, '%s' using 1:3 title 'Destination address' with boxes\n", outputfile, outputfile);
     291        fprintf(gnuplot, "plot '%s' using 1:2 title 'Source octet 1' axes x1y1 with boxes,", outputfile);
     292        fprintf(gnuplot, "'%s' using 1:3 title 'Destination octet 1' axes x1y1 with boxes,", outputfile);
     293        //fprintf(gnuplot, "'%s' using 1:4 title 'Source octet 2' axes x1y1 with boxes,", outputfile);
     294        //fprintf(gnuplot, "'%s' using 1:5 title 'Destination octet 2' axes x1y1 with boxes,", outputfile);
     295        //fprintf(gnuplot, "'%s' using 1:6 title 'Source octet 3' axes x1y1 with boxes,", outputfile);
     296        //fprintf(gnuplot, "'%s' using 1:7 title 'Destination octet 3' axes x1y1 with boxes,", outputfile);
     297        //fprintf(gnuplot, "'%s' using 1:8 title 'Source octet 4' axes x1y1 with boxes,", outputfile);
     298        //fprintf(gnuplot, "'%s' using 1:9 title 'Destination octet 4' axes x1y1 with boxes,", outputfile);
     299        fprintf(gnuplot, "'%s' using 1:10 title 'Octet 1 source change' axes x1y2 with lines,", outputfile);
     300        fprintf(gnuplot, "'%s' using 1:11 title 'Octet 1 destination change' axes x1y2 with lines\n", outputfile);
     301        //fprintf(gnuplot, "'%s' using 1:12 title 'Octet 2 source change' axes x1y2 with lines,", outputfile);
     302        //fprintf(gnuplot, "'%s' using 1:13 title 'Octet 2 destination change' axes x1y2 with lines,", outputfile);
     303        //fprintf(gnuplot, "'%s' using 1:14 title 'Octet 3 source change' axes x1y2 with lines,", outputfile);
     304        //fprintf(gnuplot, "'%s' using 1:15 title 'Octet 3 destination change' axes x1y2 with lines,", outputfile);
     305        //fprintf(gnuplot, "'%s' using 1:16 title 'Octet 4 source change' axes x1y2 with lines,", outputfile);
     306        //fprintf(gnuplot, "'%s' using 1:17 title 'Octet 4 destination change' axes x1y2 with lines\n", outputfile);
    266307        fprintf(gnuplot, "replot");
    267308        pclose(gnuplot);
     
    308349                tally->lastkey = key;
    309350
    310                 /* Plot the result with the key in epoch seconds*/
     351                /* Need to initialise lastoutput values on first pass */
     352                if(tally->output_count == 0) {
     353                        for(i=0;i<4;i++) {
     354                                for(j=0;j<256;j++) {
     355                                        tally->src_lastoutput[i][j] = tally->src[i][j];
     356                                        tally->dst_lastoutput[i][j] = tally->dst[i][j];
     357                                }
     358                        }
     359                }
     360
     361                /* Plot the result with the key in epoch seconds*/
    311362                plot_results(tally, key >> 32);
    312363
    313                 /* clear the tally */
     364                /* increment the output counter */
     365                tally->output_count++;
     366
     367                /* clear the tally but copy old values over first*/
    314368                for(i=0;i<4;i++) {
    315369                        for(j=0;j<256;j++) {
     370                                tally->src_lastoutput[i][j] = tally->src[i][j];
     371                                tally->dst_lastoutput[i][j] = tally->dst[i][j];
    316372                                tally->src[i][j] = 0;
    317373                                tally->dst[i][j] = 0;
Note: See TracChangeset for help on using the changeset viewer.