Changeset 91852de2
 Timestamp:
 11/19/18 14:47:05 (4 years ago)
 Branches:
 develop
 Children:
 0d451ef
 Parents:
 d9a4dc2
 Location:
 examples/stats
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

examples/stats/ipdistgenplot.py
rd9a4dc2 r91852de2 4 4 import subprocess 5 5 import os 6 import re 6 7 7 8 # Ensure a data directory was supplied 8 9 if len(sys.argv) != 2: 9 print("Usage: python datadirectory")10 print("Usage: python3 datadirectory") 10 11 sys.exit() 11 12 12 13 dir = sys.argv[1] 13 14 dataFiles = [] 14 statsFiles = [] 15 16 # Stats 17 total_skew_src = [0, 0, 0, 0] 18 total_skew_dst = [0, 0, 0, 0] 15 19 16 20 # Get all data/stats files contained within the directory … … 18 22 if file.endswith(".data"): 19 23 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 26 dataFiles.sort() 22 27 23 28 # Every datafile should have a corresponding stats file … … 30 35 tick = tick[1] 31 36 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 + "/ipdisttimeseriesskewness.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 + "/ipdisttimeseriesskewness.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 + "/ipdistsrcoctet" + str(x+1) + ".timeseries", "w")) 83 tmp_dst.append(open(dir + "/ipdistdstoctet" + 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 + "/ipdistsrcoctet" + str(x+1) + ".timeseries", "a")) 92 tmp_dst.append(open(dir + "/ipdistdstoctet" + 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 32 107 for x in range(4): 33 108 plot = subprocess.Popen(['gnuplot persistent','p'], 
examples/stats/ipdistparallel.c
rd9a4dc2 r91852de2 44 44 double skewness_src[4]; 45 45 double skewness_dst[4]; 46 /* Stats calculated over entire trace */47 double total_skewness_src[4];48 double total_skewness_dst[4];49 50 46 struct addr_rank *rank_src[4]; 51 47 struct addr_rank *rank_dst[4]; … … 191 187 tally>stats>skewness_src[k] = (tally>stats>mean_src[k]  tally>stats>median_src[k]) / tally>stats>stddev_src[k]; 192 188 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];197 189 } 198 190 … … 407 399 tally>stats>skewness_src[i] = 0; 408 400 tally>stats>skewness_dst[i] = 0; 409 410 tally>stats>total_skewness_src[i] = 0;411 tally>stats>total_skewness_dst[i] = 0;412 401 } 413 402 tally>lastkey = 0; … … 420 409 static void output_results(struct addr_local *tally, uint64_t tick) { 421 410 422 int i, j , k;411 int i, j; 423 412 424 413 /* Calculations before reporting the results */ … … 471 460 } 472 461 fclose(tmp); 473 474 char outputfile_stats_timeseries[255];475 snprintf(outputfile_stats_timeseries, sizeof(outputfile_stats_timeseries), "%sipdisttimeseriesskewness.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), "%sipdistdstoctet%d.timeseries", stats_outputdir, j+1);496 } else {497 snprintf(outputfile2, sizeof(outputfile2), "%sipdistsrcoctet%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 }521 462 } 522 463
Note: See TracChangeset
for help on using the changeset viewer.