Changeset 96ec511
- Timestamp:
- 11/15/18 15:27:00 (2 years ago)
- Branches:
- develop
- Children:
- eac29c7
- Parents:
- 49a047f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/tutorial/ipdist-parallel.c
r49a047f r96ec511 29 29 float src[4][256]; 30 30 float dst[4][256]; 31 //double mean_src[4]; 32 //double mean_dst[4]; 33 //double stdev_src[4]; 34 //double stdev_dst[4]; 35 //double variance_src[4]; 36 //double variance_dst[4]; 37 //double variation_src[4]; 38 //double variation_dst[4]; 31 double mode_src[4]; 32 double mode_dst[4]; 33 double mean_src[4]; 34 double mean_dst[4]; 35 double stddev_src[4]; 36 double stddev_dst[4]; 37 double variance_src[4]; 38 double variance_dst[4]; 39 double skewness_src[4]; 40 double skewness_dst[4]; 39 41 struct addr_rank *rank_src[4]; 40 42 struct addr_rank *rank_dst[4]; … … 140 142 } 141 143 142 143 144 /* This will all result in overflows, needs to be a rolling average?? stdev etc */ 145 /* Calculate mean */146 // for(i=0;i<4;i++) { 147 // uint64_t count_src= 0;148 // uint64_t count_dst= 0;149 // uint64_t tmp_src = 0; 150 // uint64_t tmp_dst = 0; 151 // for(j=0;j<256;j++) {152 // tmp_src += (j * tally->src[i][j]);153 // count_src += tally->src[i][j]; 154 // tmp_dst += (j * tally->dst[i][j]);155 // count_dst += tally->dst[i][j];156 // } 157 // 158 // tally->stats->mean_src[i] = tmp_src / count_src; 159 // tally->stats->mean_dst[i] = tmp_dst / count_dst;160 // } 161 // printf("mean: %f\n", tally->stats->mean_src[0]);162 // 163 // 164 // /* Calculate variance, standard deviation and variation*/ 165 // for(i=0;i<4;i++) { 166 // uint64_t count_src= 0;167 // uint64_t count_dst = 0; 168 // uint64_t tmp_src = 0; 169 // uint64_t tmp_dst = 0; 170 // for(j=0;j<256;j++) { 171 // tmp_src += (j * pow((tally->src[i][j] - tally->stats->mean_src[i]), 2)); 172 // count_src += tally->src[i][j];173 // tmp_dst += (j * pow((tally->dst[i][j] - tally->stats->mean_dst[i]), 2));174 // count_dst += tally->dst[i][j];175 //}176 // //printf("total: %u count: %u dd: %f\n", tmp_src, count_src, tmp_src/count_src); 177 // tally->stats->variance_src[i] = (double)tmp_src / (double)count_src;178 // tally->stats->variance_dst[i] = (double)tmp_dst / (double)count_dst;179 // tally->stats->stdev_src[i] = sqrt(tally->stats->variance_src[i]);180 // tally->stats->stdev_dst[i] = sqrt(tally->stats->variance_dst[i]); 181 // 182 // /* Calculate coefficient of variation */ 183 // tally->stats->variation_src[i] = tally->stats->stdev_src[i] / tally->stats->mean_src[i]; 184 // tally->stats->variation_dst[i] = tally->stats->stdev_dst[i] / tally->stats->mean_dst[i];185 // } 186 // 187 // 188 // printf("stdev: %f variance: %f variation: %f\n", tally->stats->stdev_src[0], tally->stats->variance_src[0], tally->stats->variation_src[0]);144 /* Calculate mean, variance and standard deviation */ 145 for(k=0;k<4;k++) { 146 147 double ex = 0; 148 double ex2 = 0; 149 double n = 0; 150 double m = 0; 151 for(i=0;i<256;i++) { 152 for(j=0;j<tally->src[k][i];j++) { 153 if(n == 0) { 154 m = i; 155 } 156 n += 1; 157 ex += (i - m); 158 ex2 += ((i - m) * (i - m)); 159 } 160 } 161 tally->stats->mean_src[k] = (k + (ex / n)); 162 tally->stats->variance_src[k] = ((ex2 - (ex*ex)/n) / n); 163 tally->stats->stddev_src[k] = sqrt(tally->stats->variance_src[k]); 164 165 ex = 0; 166 ex2 = 0; 167 n = 0; 168 m = 0; 169 for(i=0;i<256;i++) { 170 for(j=0;j<tally->dst[k][i];j++) { 171 if(n == 0) { 172 m = i; 173 } 174 n += 1; 175 ex += (i - m); 176 ex2 += ((i - m) * (i - m)); 177 } 178 } 179 tally->stats->mean_dst[k] = (k + (ex / n)); 180 tally->stats->variance_dst[k] = ((ex2 - (ex*ex)/n) / n); 181 tally->stats->stddev_dst[k] = sqrt(tally->stats->variance_dst[k]); 182 183 tally->stats->mode_src[k] = peak(&tally->stats->rank_src[k]); 184 tally->stats->mode_dst[k] = peak(&tally->stats->rank_src[k]); 185 /* Calculate skewness using pearsons mode method. This is accurate with large amounts of data */ 186 tally->stats->skewness_src[k] = (tally->stats->mean_src[k] - tally->stats->mode_src[k]) / tally->stats->stddev_src[k]; 187 tally->stats->skewness_dst[k] = (tally->stats->mean_dst[k] - tally->stats->mode_dst[k]) / tally->stats->stddev_dst[k]; 188 } 189 190 printf("skewnesss: %f\n", tally->stats->skewness_dst[1]); 189 191 190 192 } … … 386 388 } 387 389 /* Stats related varibles */ 388 //tally->stats->mean_src[i] = 0; 389 //tally->stats->mean_dst[i] = 0; 390 //tally->stats->stdev_src[i] = 0; 391 //tally->stats->stdev_dst[i] = 0; 392 //tally->stats->variance_src[i] = 0; 393 //tally->stats->variance_dst[i] = 0; 394 //tally->stats->variation_src[i] = 0; 395 //tally->stats->variation_dst[i] = 0; 390 tally->stats->mode_src[i] = 0; 391 tally->stats->mode_dst[i] = 0; 392 tally->stats->mean_src[i] = 0; 393 tally->stats->mean_dst[i] = 0; 394 tally->stats->stddev_src[i] = 0; 395 tally->stats->stddev_dst[i] = 0; 396 tally->stats->variance_src[i] = 0; 397 tally->stats->variance_dst[i] = 0; 398 tally->stats->skewness_src[i] = 0; 399 tally->stats->skewness_dst[i] = 0; 396 400 } 397 401 tally->lastkey = 0; … … 442 446 fprintf(tmp, "\n"); 443 447 } 448 fclose(tmp); 449 450 char outputfile_stats[255]; 451 snprintf(outputfile_stats, sizeof(outputfile_stats), "%sipdist-%u.stats", stats_outputdir, tick); 452 tmp = fopen(outputfile_stats, "w"); 453 /* append stats data to end of file */ 454 fprintf(tmp, "#\tmean\tstddev\tvariance\tmode\tskewness\n"); 455 for(i=0;i<4;i++) { 456 fprintf(tmp, "src%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%f\n", i+1, tally->stats->mean_src[i], tally->stats->stddev_src[i], tally->stats->variance_src[i], tally->stats->mode_src[i], tally->stats->skewness_src[i]); 457 fprintf(tmp, "dst%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%f\n", i+1, tally->stats->mean_dst[i], tally->stats->stddev_dst[i], tally->stats->variance_dst[i], tally->stats->mode_dst[i], tally->stats->skewness_dst[i]); 458 fprintf(tmp, "\n\n"); 459 } 444 460 fclose(tmp); 445 461 … … 484 500 FILE *gnuplot = popen("gnuplot -persistent", "w"); 485 501 /* send all commands to gnuplot */ 486 fprintf(gnuplot, "set term pngcairo dashedenhanced size 1280,960\n");502 fprintf(gnuplot, "set term pngcairo enhanced size 1280,960\n"); 487 503 fprintf(gnuplot, "set output '%s'\n", outputplot); 488 504 fprintf(gnuplot, "set multiplot layout 2,1\n"); … … 492 508 fprintf(gnuplot, "set ylabel 'Hits'\n"); 493 509 fprintf(gnuplot, "set xtics 0,10,255\n"); 494 fprintf(gnuplot, "plot '%s' using %d:%d title 'Source octet %d' smooth unique with boxes,", outputfile, (i*4)+3,(i*4)+4, i+1); 495 fprintf(gnuplot, "'%s' using %d:%d title 'Destination octet %d' smooth unique with boxes\n", outputfile, (i*4)+5, (i*4)+6, i+1); 510 /* Setup labels that hold mean, standard deviation and variance */ 511 fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 2 name 'SOURCEMEAN' nooutput\n", outputfile_stats, i); 512 //fprintf(gnuplot, "set label 1 gprintf(\"Source Mean %u\", SOURCEMEAN_min) at graph 0.02, 0.95\n"); 513 fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 2 name 'DESTMEAN' nooutput\n", outputfile_stats, i); 514 //fprintf(gnuplot, "set label 2 gprintf(\"Destination Mean: %f\", DESTMEAN_min) at graph 0.02, 0.90\n"); 515 //fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 3 name 'SOURCESTDDEV' nooutput\n", outputfile_stats, i); 516 //fprintf(gnuplot, "set label 3 sprintf('Source Standard Deviation: %f', SOURCESTDDEV_min) at graph 0.24, 0.95\n"); 517 //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 3 name 'DESTSTDDEV' nooutput\n", outputfile_stats, i); 518 //fprintf(gnuplot, "set label 4 sprintf('Destination Standard Deviation: %f', DESTSTDDEV_min) at graph 0.24, 0.90\n"); 519 //fprintf(gnuplot, "stats '%s' index %d every ::0::0 using 4 name 'SOURCEVAR' nooutput\n", outputfile_stats, i); 520 //fprintf(gnuplot, "set label 5 sprintf('Source Variance: %f', SOURCEVAR_min) at graph 0.55, 0.95\n"); 521 //fprintf(gnuplot, "stats '%s' index %d every ::1::1 using 4 name 'DESTVAR' nooutput\n", outputfile_stats, i); 522 //fprintf(gnuplot, "set label 6 sprintf('Destination Variance: %f', DESTVAR_min) at graph 0.55, 0.90\n"); 523 /* Plot the first graph of the multiplot */ 524 fprintf(gnuplot, "set arrow from SOURCEMEAN_min, graph 0 to SOURCEMEAN_min, graph 1 nohead lt 1\n"); 525 fprintf(gnuplot, "set arrow from DESTMEAN_min, graph 0 to DESTMEAN_min, graph 1 nohead lt 2\n"); 526 fprintf(gnuplot, "plot '%s' using %d:%d index 0 title 'Source octet %d' smooth unique with boxes,", outputfile, (i*4)+3,(i*4)+4, i+1); 527 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); 528 fprintf(gnuplot, "1/0 t 'Source mean' lt 1,"); 529 fprintf(gnuplot, "1/0 t 'Destination mean' lt 2\n"); 530 /* Unset labels for next plot */ 531 fprintf(gnuplot, "unset arrow\n"); 532 fprintf(gnuplot, "unset label 1\nunset label 2\nunset label 3\nunset label 4\nunset label 5\nunset label 6\n"); 496 533 fprintf(gnuplot, "set title 'Zipf Distribution'\n"); 497 534 fprintf(gnuplot, "set xlabel 'Rank'\n"); … … 499 536 fprintf(gnuplot, "set xrange[1:255]\n"); 500 537 fprintf(gnuplot, "set logscale xy 10\n"); 501 fprintf(gnuplot, "plot '%s' using 2:%d title 'Source octet %d',", outputfile, (i*4)+4, i+1); 502 fprintf(gnuplot, "'%s' using 2:%d title 'Destination octet %d'\n", outputfile, (i*4)+6, i+1); 538 /* Plot the second graph of the multiplot */ 539 fprintf(gnuplot, "plot '%s' using 2:%d index 0 title 'Source octet %d',", outputfile, (i*4)+4, i+1); 540 fprintf(gnuplot, "'%s' using 2:%d index 0 title 'Destination octet %d'\n", outputfile, (i*4)+6, i+1); 503 541 fprintf(gnuplot, "replot"); 504 542 pclose(gnuplot); … … 594 632 tally->dst[i][j] = 0; 595 633 } 596 /* Clear all stats related data */597 //tally->stats->mean_src[i] = 0;598 //tally->stats->mean_dst[i] = 0;599 //tally->stats->stdev_src[i] = 0;600 //tally->stats->stdev_dst[i] = 0;601 //tally->stats->variance_src[i] = 0;602 //tally->stats->variance_dst[i] = 0;603 //tally->stats->variation_src[i] = 0;604 //tally->stats->variation_dst[i] = 0;605 606 634 } 607 635 /* free the priority queue */
Note: See TracChangeset
for help on using the changeset viewer.