void traffic_done(void) { struct traffic_info *pti; struct conn_info *pci; double etime = elapsed(first_packet,last_packet); int etime_secs = etime / 1000000.0; MFILE *pmf; int i; /* roll the active connections into the port records */ for (pci=connhead; pci; pci=pci->next) { if (pci->pti1) ++pci->pti1->ttlactive; if (pci->pti2) ++pci->pti2->ttlactive; ++ports[0]->ttlactive; } AgeTraffic(); pmf = Mfopen(PORT_FILENAME,"w"); printf("Dumping port statistics into file %s\n", PORT_FILENAME); /* dump out the data */ Mfprintf(pmf,"Overall totals by port\n"); for (i=0; i < NUM_PORTS; ++i) { pti = ports[i]; if ((pti != EXCLUDE_PORT) && (pti != INCLUDE_PORT)) { if (i == 0) Mfprintf(pmf,"TOTAL "); else Mfprintf(pmf,"Port %5u ", pti->port); Mfprintf(pmf,"\ bytes: %12lu pkts: %10lu conns: %8lu tput: %8lu B/s\n", pti->ttlbytes, pti->ttlpackets, pti->ttlactive, pti->ttlbytes / etime_secs); } } Mfclose(pmf); /* dump specific stats */ pmf = Mfopen(STATS_FILENAME,"w"); printf("Dumping overall statistics into file %s\n", STATS_FILENAME); pti = ports[0]; Mfprintf(pmf, "\n\nOverall Statistics over %d seconds (%s):\n", etime_secs, elapsed2str(etime)); /* ttl bytes */ Mfprintf(pmf, "%" FS_ULL " ttl bytes sent, %.3f bytes/second\n", data_nbytes_all, (float)data_nbytes_all / ((float)etime_secs)); /* ttl bytes (nonrexmit)*/ Mfprintf(pmf, "%" FS_ULL " ttl non-rexmit bytes sent, %.3f bytes/second\n", data_nbytes_nonrexmit, (float)data_nbytes_nonrexmit / ((float)etime_secs)); /* ttl bytes (nonrexmit)*/ Mfprintf(pmf, "%" FS_ULL " ttl rexmit bytes sent, %.3f bytes/second\n", data_nbytes_all - data_nbytes_nonrexmit, (float)(data_nbytes_all - data_nbytes_nonrexmit) / ((float)etime_secs)); /* ttl packets */ Mfprintf(pmf, "%u packets sent, %.3f packets/second\n", pti->ttlpackets, (float)pti->ttlpackets / ((float)etime_secs)); /* connections opened */ Mfprintf(pmf, "%u connections opened, %.3f conns/second\n", ttl_num_opens, (float)ttl_num_opens / ((float)etime_secs)); /* dupacks */ Mfprintf(pmf, "%u dupacks sent, %.3f dupacks/second\n", ttl_dupacks, (float)ttl_dupacks / ((float)etime_secs)); /* rexmits */ Mfprintf(pmf, "%u rexmits sent, %.3f rexmits/second\n", ttl_rexmits, (float)ttl_rexmits / ((float)etime_secs)); /* RTT */ Mfprintf(pmf, "average RTT: %.3f msecs\n", ttl_rtt_ttl / (float)ttl_rtt_samples); Mfclose(pmf); printf("Plotting performed at %.3f second intervals\n", age_interval); }
void plotter_done(void) { PLOTTER pl; MFILE *f; char *fname; static struct dstring *xplot_cmd_buff=NULL; if(plotter_ix>0) { if(xplot_all_files) { xplot_cmd_buff=DSNew(); DSAppendString(xplot_cmd_buff,"xplot"); DSAppendString(xplot_cmd_buff," "); if(xplot_args!=NULL) { DSAppendString(xplot_cmd_buff,xplot_args); DSAppendString(xplot_cmd_buff," "); } } } for (pl = 0; pl <= plotter_ix; ++pl) { struct plotter_info *ppi = &pplotters[pl]; if ((f = ppi->fplot) == NULL) continue; /* Write the plotter header if not already written */ if(!ppi->header_done) WritePlotHeader(pl); if (!ignore_non_comp || ((ppi->p2plast != NULL) && (ConnComplete(ppi->p2plast->ptp)))) { Mfprintf(f,"go\n"); Mfclose(f); } else { fname = ppi->p2plast->tsg_plotfile; if (debug) fprintf(stderr,"Removing incomplete plot file '%s'\n", fname); Mfclose(f); if (unlink(fname) != 0) perror(fname); } if(xplot_all_files){ if(output_file_dir!=NULL) { DSAppendString(xplot_cmd_buff,output_file_dir); DSAppendString(xplot_cmd_buff,"/"); } DSAppendString(xplot_cmd_buff,ppi->filename); DSAppendString(xplot_cmd_buff," "); } } if(plotter_ix>0) { if(xplot_all_files) { fprintf(stdout,"%s\n",DSVal(xplot_cmd_buff)); system(DSVal(xplot_cmd_buff)); DSDestroy(&xplot_cmd_buff); } } }
static void DoHist( struct samples *psamp) { int i; struct hist3d hist3d; MFILE *f; u_long sum; int slice; int base_z; int slice_size; if (psamp->num_samples == 0) return; printf("Samples: %lu\n", psamp->num_samples); printf("Min: %u\n", psamp->min); printf("Max: %u\n", psamp->max); /* init */ hist3d.rtt.num_buckets = 0; memset(&hist3d.rtt,'\00',sizeof(struct hist)); MakeBuckets(&hist3d.rtt, psamp->num_samples); for (i=0; i < NUM_SLICES; ++i) { memset(&hist3d.rtt_diff_slices[i],'\00',sizeof(struct hist)); MakeBuckets(&hist3d.rtt_diff_slices[i], psamp->num_samples); } /* calculate the global histogram */ for (i=0; i < psamp->num_samples; ++i) { u_short rtt = psamp->samples[i]; ++hist3d.rtt.buckets[rtt]; ++hist3d.rtt.num_samples; } /* find the slices, same amount of data in each slice */ sum = 0; slice = 0; base_z = 0; slice_size = psamp->num_samples / NUM_SLICES; for (i=0; i < psamp->num_samples; ++i) { u_short count = hist3d.rtt.buckets[i]; sum += count; if (sum > slice_size) { hist3d.rtt_diff_slices[slice].z = base_z; ++slice; sum = 0; base_z = i+1; } } for (; slice < NUM_SLICES; ++slice) hist3d.rtt_diff_slices[slice].z = ULONG_MAX; /* add the slice data */ for (i=1; i < psamp->num_samples; ++i) { u_short rtt = psamp->samples[i]; u_short prev_rtt = psamp->samples[i-1]; /* see which slice holds the prev_rtt */ for (slice = NUM_SLICES-1; slice >= 0; --slice) { if (prev_rtt > hist3d.rtt_diff_slices[slice].z) break; } ++hist3d.rtt_diff_slices[slice].buckets[rtt]; ++hist3d.rtt_diff_slices[slice].num_samples; } if ((f = Mfopen("rtt.dat","w")) == NULL) { perror("rtt.dat"); exit (1); } printf("Total Histogram\n"); hist3d.rtt.z = -1; PlotHist(f,&hist3d.rtt); Mfclose(f); if ((f = Mfopen("rtt3d.dat","w")) == NULL) { perror("rtt.dat"); exit (1); } for (i=0; i < NUM_SLICES; ++i) { struct hist *phist = &hist3d.rtt_diff_slices[i]; printf("Slice %d Histogram - base: %lu ms\n", i, phist->z); PlotHist(f,phist); } /* plot the "connections" */ #ifdef BROKEN for (i=0; i < psamp->max; i+=10) { for (slice=0; slice < NUM_SLICES; ++slice) { struct hist *phist = &hist3d.rtt_diff_slices[slice]; u_long count = phist->buckets[i]; float percent = (float)count / phist->num_samples; if (phist->num_samples == 0) continue; fprintf(f,"%4d %lu %.2f\n", i, phist->z, 100 * percent); } fprintf(f,"\n"); } #endif /* BROKEN */ Mfclose(f); }