Changeset 91852de2


Ignore:
Timestamp:
11/19/18 14:47:05 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
0d451ef
Parents:
d9a4dc2
Message:

Move more plotting tasks to python script

Location:
examples/stats
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • examples/stats/ipdist-genplot.py

    rd9a4dc2 r91852de2  
    44import subprocess
    55import os
     6import re
    67
    78# Ensure a data directory was supplied
    89if len(sys.argv) != 2:
    9         print("Usage: python data-directory")
     10        print("Usage: python3 data-directory")
    1011        sys.exit()
    1112
    1213dir = sys.argv[1]
    1314dataFiles = []
    14 statsFiles = []
     15
     16# Stats
     17total_skew_src = [0, 0, 0, 0]
     18total_skew_dst = [0, 0, 0, 0]
    1519
    1620# Get all data/stats files contained within the directory
     
    1822        if file.endswith(".data"):
    1923                dataFiles.append(file)
    20         if file.endswith(".stats"):
    21                 statsFiles.append(file)
     24
     25# sort the datafiles list so they are read in the correct order
     26dataFiles.sort()
    2227
    2328# Every datafile should have a corresponding stats file
     
    3035        tick = tick[1]
    3136
     37        # Open the current stats file
     38        lines = []
     39        with open(dir + "/" + statsFile, "r") as tmp:
     40                lines = tmp.readlines()
     41        # increment the total skew counters
     42        for x in range(4):
     43                total_skew_src[x] += float(lines[(4*x)+1].split()[6])
     44                total_skew_dst[x] += float(lines[(4*x)+2].split()[6])
     45
     46        # Create/append to timeseries stats file
     47        # the file needs to be created on the first pass
     48        if i == 0:
     49                tmp = open(dir + "/ipdist-timeseries-skewness.stats", "w")
     50                tmp.write("timestamp\tsrc1\t\tdst1\t\tsrc2\t\tdst2\t\tsrc3\t\tdst3\t\tsrc4\t\tdst4\n")
     51        else:
     52                tmp = open(dir + "/ipdist-timeseries-skewness.stats", "a")
     53        tmp.write(tick)
     54        for x in range(4):
     55                tmp.write("\t" + str(total_skew_src[x]/(i+1)) + "\t" + str(total_skew_dst[x]/(i+1)))
     56        tmp.write("\n")
     57        tmp.close()
     58
     59
     60
     61        # open data file to read from and count all occurances
     62        with open(dir + "/" + dataFile, "r") as tmp:
     63                lines = tmp.readlines()
     64        tmp.close()
     65        # Count up all octet count in current data file
     66        count_src = [0] * 4
     67        count_dst = [0] * 4
     68        # initialize the array
     69        for x in range(4):
     70                count_src[x] = [0] * 256
     71                count_dst[x] = [0] * 256
     72        # count all occurances
     73        for x in range(256):
     74                for k in range(4):
     75                        count_src[k][int(lines[x+2].split()[(k*4)+2])] = int(lines[x+2].split()[(k*4)+3])
     76                        count_dst[k][int(lines[x+2].split()[(k*4)+4])] = int(lines[x+2].split()[(k*4)+5])
     77        # output the results to the timeseries file
     78        tmp_src = []
     79        tmp_dst = []
     80        if i == 0:
     81                for x in range(4):
     82                        tmp_src.append(open(dir + "/ipdist-src-octet" + str(x+1) + ".timeseries", "w"))
     83                        tmp_dst.append(open(dir + "/ipdist-dst-octet" + str(x+1) + ".timeseries", "w"))
     84                        tmp_src[x].write("timestamp")
     85                        tmp_dst[x].write("timestamp")
     86                        for k in range(256):
     87                                tmp_src[x].write("\t" + str(k))
     88                                tmp_dst[x].write("\t" + str(k))
     89        else:
     90                for x in range(4):
     91                        tmp_src.append(open(dir + "/ipdist-src-octet" + str(x+1) + ".timeseries", "a"))
     92                        tmp_dst.append(open(dir + "/ipdist-dst-octet" + str(x+1) + ".timeseries", "a"))
     93        # print data into file
     94        for x in range(4):
     95                tmp_src[x].write("\n" + tick)
     96                tmp_dst[x].write("\n" + tick)
     97                for k in range(256):
     98                        tmp_src[x].write("\t" + str(count_src[x][k]))
     99                        tmp_dst[x].write("\t" + str(count_dst[x][k]))
     100        # close all files
     101        for x in range(4):
     102                tmp_src[x].close()
     103                tmp_dst[x].close()
     104
     105
     106        # create interval plots
    32107        for x in range(4):
    33108                plot = subprocess.Popen(['gnuplot -persistent','-p'],
  • examples/stats/ipdist-parallel.c

    rd9a4dc2 r91852de2  
    4444        double skewness_src[4];
    4545        double skewness_dst[4];
    46         /* Stats calculated over entire trace */
    47         double total_skewness_src[4];
    48         double total_skewness_dst[4];
    49 
    5046        struct addr_rank *rank_src[4];
    5147        struct addr_rank *rank_dst[4];
     
    191187                tally->stats->skewness_src[k] = (tally->stats->mean_src[k] - tally->stats->median_src[k]) / tally->stats->stddev_src[k];
    192188                tally->stats->skewness_dst[k] = (tally->stats->mean_dst[k] - tally->stats->median_dst[k]) / tally->stats->stddev_dst[k];
    193 
    194                 /* Increment total skew */
    195                 tally->stats->total_skewness_src[k] += tally->stats->skewness_src[k];
    196                 tally->stats->total_skewness_dst[k] += tally->stats->skewness_dst[k];
    197189        }
    198190
     
    407399                tally->stats->skewness_src[i] = 0;
    408400                tally->stats->skewness_dst[i] = 0;
    409 
    410                 tally->stats->total_skewness_src[i] = 0;
    411                 tally->stats->total_skewness_dst[i] = 0;
    412401        }
    413402        tally->lastkey = 0;
     
    420409static void output_results(struct addr_local *tally, uint64_t tick) {
    421410
    422         int i, j, k;
     411        int i, j;
    423412
    424413        /* Calculations before reporting the results */
     
    471460        }
    472461        fclose(tmp);
    473 
    474         char outputfile_stats_timeseries[255];
    475         snprintf(outputfile_stats_timeseries, sizeof(outputfile_stats_timeseries), "%sipdist-timeseries-skewness.stats", stats_outputdir);
    476         if(tally->output_count == 0) {
    477                 tmp = fopen(outputfile_stats_timeseries, "w");
    478                 fprintf(tmp, "timestamp\tsrc1\t\tdst1\t\tsrc2\t\tdst2\t\tsrc3\t\tdst3\t\tsrc4\t\tdst4");
    479         } else {
    480                 tmp = fopen(outputfile_stats_timeseries, "a");
    481         }
    482         fprintf(tmp, "\n%lu\t", tick);
    483         for(k=0;k<4;k++) {
    484                 fprintf(tmp, "%f\t", tally->stats->total_skewness_src[k] / (tally->output_count+1));
    485                 fprintf(tmp, "%f\t", tally->stats->total_skewness_dst[k] / (tally->output_count+1));
    486         }
    487         fclose(tmp);
    488 
    489         /* Puts data into timeseries files that gnuplot likes */
    490         char outputfile2[255];
    491         for(k=0;k<2;k++) {
    492                 for(j=0;j<4;j++) {
    493                         /* If k is 0 we are doing src else dst */
    494                         if(k) {
    495                                 snprintf(outputfile2, sizeof(outputfile2), "%sipdist-dst-octet%d.timeseries", stats_outputdir, j+1);
    496                         } else {
    497                                 snprintf(outputfile2, sizeof(outputfile2), "%sipdist-src-octet%d.timeseries", stats_outputdir, j+1);
    498                         }
    499                         if(tally->output_count == 0) {
    500                                 tmp = fopen(outputfile2, "w");
    501                                 fprintf(tmp, "timestamp\t");
    502                                 for(i=0;i<256;i++) {
    503                                         fprintf(tmp, "%d\t", i);
    504                                 }
    505                                 fprintf(tmp, "\n");
    506                         } else {
    507                                 tmp = fopen(outputfile2, "a");
    508                         }
    509                         fprintf(tmp, "%lu\t", tick);
    510                         for(i=0;i<256;i++) {
    511                                 if(k) {
    512                                         fprintf(tmp, "%lu\t", tally->dst[j][i]);
    513                                 } else {
    514                                         fprintf(tmp, "%lu\t", tally->src[j][i]);
    515                                 }
    516                         }
    517                         fprintf(tmp, "\n");
    518                         fclose(tmp);
    519                 }
    520         }
    521462}
    522463
Note: See TracChangeset for help on using the changeset viewer.