Changeset ccb2507
- Timestamp:
- 11/10/18 22:32:09 (2 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/tutorial/ipdist-parallel.c
racffeb8 r4d5e6b3 10 10 /* Structure to hold the counters each thread has its own one of these */ 11 11 struct addr_local { 12 /* Holds the counts of each number occurance per octet, These are cleared after every output. */ 12 13 uint64_t src[4][256]; 13 14 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 */ 14 19 uint64_t lastkey; 20 /* Is the count of the number of packets processed, This is cleared after every output. */ 15 21 uint64_t packets; 22 uint64_t output_count; 16 23 }; 17 24 … … 174 181 * Right shifting these converts them to seconds, tickrate is in seconds */ 175 182 if((timestamp >> 32) >= (local->lastkey >> 32) + tickrate) { 176 per_tick(trace, thread, global, local, timestamp);183 per_tick(trace, thread, global, local, timestamp); 177 184 local->lastkey = timestamp; 178 185 } … … 219 226 tally->src[i][j] = 0; 220 227 tally->dst[i][j] = 0; 228 tally->src_lastoutput[i][j] = 0; 229 tally->dst_lastoutput[i][j] = 0; 221 230 } 222 231 } 223 232 tally->lastkey = 0; 224 233 tally->packets = 0; 234 tally->output_count = 0; 225 235 226 236 return tally; … … 228 238 229 239 static void plot_results(struct addr_local *tally, uint64_t tick) { 230 231 /* Get the current time */232 time_t current_time = time(NULL);233 240 234 241 char outputfile[255]; … … 240 247 FILE *tmp = fopen(outputfile, "w"); 241 248 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"); 244 252 for(i=0;i<256;i++) { 245 253 fprintf(tmp, "%d", i); … … 247 255 fprintf(tmp, "\t%d\t%d", tally->src[j][i], tally->dst[j][i]); 248 256 } 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 249 271 fprintf(tmp, "\n"); 250 272 } 251 273 fclose(tmp); 252 printf(" wrote out to file %s\n", outputfile);274 printf("Ouput data file %s and plot %s\n", outputfile, outputplot); 253 275 254 276 /* Open pipe to gnuplot */ … … 260 282 fprintf(gnuplot, "set xlabel 'Prefix'\n"); 261 283 fprintf(gnuplot, "set ylabel 'Hits'\n"); 284 fprintf(gnuplot, "set y2label 'Percentage Change'\n"); 262 285 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"); 264 290 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); 266 307 fprintf(gnuplot, "replot"); 267 308 pclose(gnuplot); … … 308 349 tally->lastkey = key; 309 350 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*/ 311 362 plot_results(tally, key >> 32); 312 363 313 /* clear the tally */ 364 /* increment the output counter */ 365 tally->output_count++; 366 367 /* clear the tally but copy old values over first*/ 314 368 for(i=0;i<4;i++) { 315 369 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]; 316 372 tally->src[i][j] = 0; 317 373 tally->dst[i][j] = 0;
Note: See TracChangeset
for help on using the changeset viewer.