/* * Return a string suitable for use as a timestamp in the xplot output. * sdo fix: originally, we were just plotting to the accuracy of 1/10 ms * this was mostly to help keep the .xpl files from being too large. However, * on faster networks this just isn't enough, so we'll now use all 6 digits * of the microsecond counter. Note that there's no guarantee that the * timestamps are really all that accurate! */ static char * xp_timestamp( PLOTTER pl, struct timeval time) { static char bufs[4][20]; /* several of them for multiple calls in one printf */ static int bufix = 0; unsigned secs; unsigned usecs; unsigned decimal; char *pbuf; struct plotter_info *ppi; ppi = &pplotters[pl]; /* see if we're graphing from "0" OR if the axis type is switched */ if (graph_time_zero || ppi->axis_switched) { if (ZERO_TIME(&ppi->zerotime)) { /* set "zero point" */ ppi->zerotime = time; } /* (in)sanity check */ if (tv_lt(time,ppi->zerotime)) { fprintf(stderr,"Internal error in plotting (plot file '%s')...\n\ ZERO-based X-axis plotting requested and elements are not plotted in\n\ increasing time order. Try without the '-z' flag\n", ppi->filename); /* exit(-5); */ time.tv_sec = time.tv_usec = 0; } else { /* computer offset from first plotter point */ tv_sub(&time, ppi->zerotime); } } /* calculate time components */ secs = time.tv_sec; usecs = time.tv_usec; decimal = usecs; /* use one of 4 rotating static buffers (for multiple calls per printf) */ bufix = (bufix+1)%4; pbuf = bufs[bufix]; snprintf(pbuf,sizeof(bufs[bufix]),"%u.%06u",secs,decimal); return(pbuf); }
void extend_line( PLINE pline, timeval xval, int yval) { PLOTTER p; if (!pline) return; p = pline->plotter; #ifdef OLD /* attach a label to the first non-zero point */ if (!pline->labelled) { if (yval != 0) { plotter_temp_color(p, pline->color); plotter_text(p, xval, yval, "l", pline->label); pline->labelled = 1; } } #endif /* attach a label midway on the first line segment above 0 */ /* for whom the second point is NOT 0 */ if (!pline->labelled) { if ((yval != 0) && (!ZERO_TIME(&pline->last_time))) { timeval tv_elapsed; timeval tv_avg; int avg_yval; /* computer elapsed time for these 2 points */ tv_elapsed = xval; tv_sub(&tv_elapsed,pline->last_time); /* divide elapsed time by 2 */ tv_elapsed.tv_sec /= 2; tv_elapsed.tv_usec /= 2; /* add 1/2 of the elapsed time to the oldest point */ /* (giving us the average time) */ tv_avg = pline->last_time; tv_add(&tv_avg, tv_elapsed); /* average the Y values */ avg_yval = (1 + pline->last_y+yval)/2; /* (rounding UP, please) */ /* draw the label */ plotter_temp_color(p, pline->color); plotter_text(p, tv_avg, avg_yval, "l", pline->label); /* remember that it's been done */ pline->labelled = 1; } } /* draw a dot at the current point */ plotter_perm_color(p, pline->color); plotter_dot(p, xval, yval); /* if this isn't the FIRST point, connect with a line */ if (!ZERO_TIME(&pline->last_time)) { plotter_line(p, xval, yval, pline->last_time, pline->last_y); } /* remember this point for the next line segment */ pline->last_time = xval; pline->last_y = yval; }
static void AgeTraffic(void) { struct traffic_info *pti; struct conn_info *pci; static timeval last_time = {0,0}; float etime; int ups; /* units per second */ /* first time doesn't count */ if (ZERO_TIME(&last_time)) { last_time = current_time; return; } /* check elapsed time */ etime = elapsed(last_time, current_time); if (ldebug>1) printf("AgeTraffic called, elapsed time is %.3f seconds\n", etime/1000000); if (etime == 0.0) return; /* roll the open/active/long connections into the port records */ for (pci=connhead; pci; pci=pci->next) { if (pci->wasactive) { if (pci->pti1) ++pci->pti1->nactive; if (pci->pti2) ++pci->pti2->nactive; pci->wasactive = 0; ++ports[0]->nactive; } if (pci->isopen) { if (pci->pti1) ++pci->pti1->nopen; if (pci->pti2) ++pci->pti2->nopen; ++ports[0]->nopen; if (pci->islong) { if (pci->pti1) ++pci->pti1->nlong; if (pci->pti2) ++pci->pti2->nlong; ++ports[0]->nlong; } if (!pci->wasactive) { /* open and !active ==> IDLE */ if (pci->pti1) ++pci->pti1->nidle; if (pci->pti2) ++pci->pti2->nidle; ++ports[0]->nidle; } } } /* ============================================================ */ /* plot halfopen conns */ if (doplot_halfopen) { /* draw lines */ extend_line(line_num_halfopens,current_time, num_halfopens); } /* ============================================================ */ /* plot connection activity */ /* opens */ if (doplot_openclose) { /* draw lines */ extend_line(line_num_opens,current_time, num_opens); extend_line(line_num_closes,current_time, num_closes); extend_line(line_open_conns,current_time, open_conns); /* reset interval counters */ // Counting ttl_num_opens instantaneously as and when num_opens is incremented, // so that ttl_num_opens is printed properly in traffic_stats.dat even // when the -C(openclose) option is not given. // Hence commenting off the following line. - Mani, 4 Aug 2003. // ttl_num_opens += num_opens; ttl_num_closes += num_closes; num_opens = 0; num_closes = 0; } /* ============================================================ */ /* report of loss events */ if (doplot_loss) { /* convert to events/second */ /* sdo bugfix - Wed May 12, 1999 - round UP!! */ dupacks = (dupacks+age_interval-1)/age_interval; rexmits = (rexmits+age_interval-1)/age_interval; /* draw lines */ extend_line(line_dupacks,current_time, dupacks); extend_line(line_rexmits,current_time, rexmits); /* reset interval counters */ dupacks = 0; rexmits = 0; } /* ============================================================ */ /* report of RTT */ if (doplot_rtt && (rtt_samples > 0)) { int rtt_avg; /* convert to average rtt */ rtt_avg = (int)((rtt_ttl/(float)rtt_samples)); /* draw lines */ extend_line(line_rtt_avg, current_time, rtt_avg); if (rtt_min != -1) extend_line(line_rtt_min, current_time, rtt_min); if (rtt_max != -1) extend_line(line_rtt_max, current_time, rtt_max); /* reset interval counters */ rtt_ttl = 0; rtt_samples = 0; rtt_min = -1; rtt_max = -1; } /* ============================================================ */ /* report of total data */ if (doplot_data) { extend_line(line_data_all, current_time, data_nbytes_all); extend_line(line_data_nonrexmit, current_time, data_nbytes_nonrexmit); } /* ============================================================ */ /* print them out */ for (pti=traffichead; pti; pti=pti->next) { if (ldebug>1) printf(" Aging Port %u bytes: %lu packets: %lu\n", pti->port, pti->nbytes, pti->npackets); /* plot bytes */ if (doplot_bytes) { /* convert to units per second */ ups = (int)((float)pti->nbytes * 1000000.0 / etime); /* plot it */ extend_line(pti->line_nbytes,current_time, ups); } /* plot packets */ if (doplot_packets) { /* convert to units per second */ ups = (int)((float)pti->npackets * 1000000.0 / etime); /* plot it */ extend_line(pti->line_npackets,current_time, ups); } /* plot active connections */ if (doplot_active) { /* plot it */ extend_line(pti->line_nactive,current_time, pti->nactive); } /* plot idle connections */ if (doplot_idle) { /* plot it */ extend_line(pti->line_nidle,current_time, pti->nidle); } /* plot open connections */ if (doplot_open) { /* plot it */ extend_line(pti->line_nopen,current_time, pti->nopen); } /* plot long-duration */ if (doplot_long) { extend_line(pti->line_nlong,current_time, pti->nlong); } /* plot pureacks */ if (doplot_pureacks) { /* convert to units per second */ ups = (int)((float)pti->npureacks * 1000000.0 / etime); extend_line(pti->line_pureacks, current_time, ups); } } /* zero them out */ for (pti=traffichead; pti; pti=pti->next) { pti->ttlbytes += pti->nbytes; pti->ttlpackets += pti->npackets; pti->ttlpureacks += pti->npureacks; pti->nbytes = 0; pti->nlong = 0; pti->npackets = 0; pti->nactive = 0; pti->nidle = 0; pti->nopen = 0; pti->npureacks = 0; } last_time = current_time; }
void PrintTrace( tcp_pair *ptp) { double etime; u_long etime_secs; u_long etime_usecs; double etime_data1; double etime_data2; tcb *pab = &ptp->a2b; tcb *pba = &ptp->b2a; char *host1 = pab->host_letter; char *host2 = pba->host_letter; char bufl[40],bufr[40]; /* counters to use for seq. space wrap around calculations */ u_llong stream_length_pab=0, stream_length_pba=0; u_long pab_last, pba_last; /* Reset the counter for each connection */ sv_print_count = 1; /* The first field (conn_#) gets printed in trace.c */ /* calculate elapsed time */ etime = elapsed(ptp->first_time,ptp->last_time); etime_secs = etime / 1000000.0; etime_usecs = 1000000 * (etime/1000000.0 - (double)etime_secs); /* Check if comma-separated-values or tab-separated-values * has been requested. */ if(csv || tsv || (sv != NULL)) { fprintf(stdout,"%s%s%s%s%s%s%s%s", ptp->a_hostname, sp, ptp->b_hostname, sp, ptp->a_portname, sp, ptp->b_portname, sp); sv_print_count += 4; /* Print the start and end times. In other words, * print the time of the first and the last packet */ fprintf(stdout,"%ld.%ld %s %ld.%ld %s", (long)ptp->first_time.tv_sec, (long)ptp->first_time.tv_usec, sp, (long)ptp->last_time.tv_sec, (long)ptp->last_time.tv_usec, sp); sv_print_count += 2; } else { fprintf(stdout,"\thost %-4s %s\n", (snprintf(bufl,sizeof(bufl),"%s:", host1),bufl), ptp->a_endpoint); fprintf(stdout,"\thost %-4s %s\n", (snprintf(bufl,sizeof(bufl),"%s:", host2),bufl), ptp->b_endpoint); fprintf(stdout,"\tcomplete conn: %s", ConnReset(ptp)?"RESET":( ConnComplete(ptp)?"yes":"no")); if (ConnComplete(ptp)) fprintf(stdout,"\n"); else fprintf(stdout,"\t(SYNs: %u) (FINs: %u)\n", SynCount(ptp), FinCount(ptp)); fprintf(stdout,"\tfirst packet: %s\n", ts2ascii(&ptp->first_time)); fprintf(stdout,"\tlast packet: %s\n", ts2ascii(&ptp->last_time)); fprintf(stdout,"\telapsed time: %s\n", elapsed2str(etime)); fprintf(stdout,"\ttotal packets: %" FS_ULL "\n", ptp->packets); fprintf(stdout,"\tfilename: %s\n", ptp->filename); fprintf(stdout," %s->%s: %s->%s:\n", host1,host2,host2,host1); } StatLineI("total packets","", pab->packets, pba->packets); if (pab->reset_count || pba->reset_count || csv || tsv || (sv != NULL)) StatLineI("resets sent","", pab->reset_count, pba->reset_count); StatLineI("ack pkts sent","", pab->ack_pkts, pba->ack_pkts); StatLineI("pure acks sent","", pab->pureack_pkts, pba->pureack_pkts); StatLineI("sack pkts sent","", pab->num_sacks, pba->num_sacks); StatLineI("dsack pkts sent","", pab->num_dsacks, pba->num_dsacks); StatLineI("max sack blks/ack","", pab->max_sack_blocks, pba->max_sack_blocks); StatLineI("unique bytes sent","", pab->unique_bytes, pba->unique_bytes); StatLineI("actual data pkts","", pab->data_pkts, pba->data_pkts); StatLineI("actual data bytes","", pab->data_bytes, pba->data_bytes); StatLineI("rexmt data pkts","", pab->rexmit_pkts, pba->rexmit_pkts); StatLineI("rexmt data bytes","", pab->rexmit_bytes, pba->rexmit_bytes); StatLineI("zwnd probe pkts","", pab->num_zwnd_probes, pba->num_zwnd_probes); StatLineI("zwnd probe bytes","", pab->zwnd_probe_bytes, pba->zwnd_probe_bytes); StatLineI("outoforder pkts","", pab->out_order_pkts, pba->out_order_pkts); StatLineI("pushed data pkts","", pab->data_pkts_push, pba->data_pkts_push); StatLineP("SYN/FIN pkts sent","","%s", (snprintf(bufl,sizeof(bufl),"%d/%d", pab->syn_count, pab->fin_count),bufl), (snprintf(bufr,sizeof(bufr),"%d/%d", pba->syn_count, pba->fin_count),bufr)); if (pab->f1323_ws || pba->f1323_ws || pab->f1323_ts || pba->f1323_ts || csv || tsv || (sv != NULL)) { StatLineP("req 1323 ws/ts","","%s", (snprintf(bufl,sizeof(bufl),"%c/%c", pab->f1323_ws?'Y':'N',pab->f1323_ts?'Y':'N'),bufl), (snprintf(bufr,sizeof(bufr),"%c/%c", pba->f1323_ws?'Y':'N',pba->f1323_ts?'Y':'N'),bufr)); } if (pab->f1323_ws || pba->f1323_ws || csv || tsv || (sv != NULL)) { StatLineI("adv wind scale","", (u_long)pab->window_scale, (u_long)pba->window_scale); } if (pab->fsack_req || pba->fsack_req || csv || tsv || (sv != NULL)) { StatLineP("req sack","","%s", pab->fsack_req?"Y":"N", pba->fsack_req?"Y":"N"); StatLineI("sacks sent","", pab->sacks_sent, pba->sacks_sent); } StatLineI("urgent data pkts", "pkts", pab->urg_data_pkts, pba->urg_data_pkts); StatLineI("urgent data bytes", "bytes", pab->urg_data_bytes, pba->urg_data_bytes); StatLineI("mss requested","bytes", pab->mss, pba->mss); StatLineI("max segm size","bytes", pab->max_seg_size, pba->max_seg_size); StatLineI("min segm size","bytes", pab->min_seg_size, pba->min_seg_size); StatLineI("avg segm size","bytes", (int)((double)pab->data_bytes / ((double)pab->data_pkts+.001)), (int)((double)pba->data_bytes / ((double)pba->data_pkts+.001))); StatLineI("max win adv","bytes", pab->win_max, pba->win_max); StatLineI("min win adv","bytes", pab->win_min, pba->win_min); StatLineI("zero win adv","times", pab->win_zero_ct, pba->win_zero_ct); // Average window advertisement is calculated only for window scaled pkts // if we have seen this connection using window scaling. // Otherwise, it is just the regular way of dividing the sum of // all window advertisements by the total number of packets. if (pab->window_stats_updated_for_scaling && pba->window_stats_updated_for_scaling) StatLineI("avg win adv","bytes", pab->win_scaled_pkts==0?0: (pab->win_tot/pab->win_scaled_pkts), pba->win_scaled_pkts==0?0: (pba->win_tot/pba->win_scaled_pkts)); else StatLineI("avg win adv","bytes", pab->packets==0?0:pab->win_tot/pab->packets, pba->packets==0?0:pba->win_tot/pba->packets); if (print_owin) { StatLineI("max owin","bytes", pab->owin_max, pba->owin_max); StatLineI("min non-zero owin","bytes", pab->owin_min, pba->owin_min); StatLineI("avg owin","bytes", pab->owin_count==0?0:pab->owin_tot/pab->owin_count, pba->owin_count==0?0:pba->owin_tot/pba->owin_count); if (etime == 0.0) { StatLineP("wavg owin", "", "%s", "NA", "NA"); } else { StatLineI("wavg owin","bytes", (u_llong)(pab->owin_wavg/((double)etime/1000000)), (u_llong)(pba->owin_wavg/((double)etime/1000000))); } } StatLineI("initial window","bytes", pab->initialwin_bytes, pba->initialwin_bytes); StatLineI("initial window","pkts", pab->initialwin_segs, pba->initialwin_segs); /* compare to theoretical length of the stream (not just what we saw) using the SYN and FIN * Seq. Space wrap around calculations: * Calculate stream length using last_seq_num seen, first_seq_num * seen and wrap_count. * first_seq_num = syn * If reset_set, last_seq_num = latest_seq * else last_seq_num = fin */ pab_last = (pab->reset_count>0)?pab->latest_seq:pab->fin; pba_last = (pba->reset_count>0)?pba->latest_seq:pba->fin; /* calculating stream length for direction pab */ if ((pab->syn_count > 0) && (pab->fin_count > 0)) { if (pab->seq_wrap_count > 0) { if (pab_last > pab->syn) { stream_length_pab = pab_last + (MAX_32 * pab->seq_wrap_count) - pab->syn - 1; } else { stream_length_pab = pab_last + (MAX_32 * (pab->seq_wrap_count+1)) - pab->syn - 1; } } else { if (pab_last > pab->syn) { stream_length_pab = pab_last - pab->syn - 1; } else { stream_length_pab = MAX_32 + pab_last - pab->syn - 1; } } } /* calculating stream length for direction pba */ if ((pba->syn_count > 0) && (pba->fin_count > 0)) { if (pba->seq_wrap_count > 0) { if (pba_last > pba->syn) { stream_length_pba = pba_last + (MAX_32 * pba->seq_wrap_count) - pba->syn - 1; } else { stream_length_pba = pba_last + (MAX_32 * (pba->seq_wrap_count+1)) - pba->syn - 1; } } else { if (pba_last > pba->syn) { stream_length_pba = pba_last - pba->syn - 1; } else { stream_length_pba = MAX_32 + pba_last - pba->syn - 1; } } } /* print out values */ if ((pab->fin_count > 0) && (pab->syn_count > 0)) { char *format = "%8" FS_ULL; StatLineFieldL("ttl stream length", "bytes", format, stream_length_pab, 0); } else { StatLineField("ttl stream length", "", "%s", (u_long)"NA", 0); } if ((pba->fin_count > 0) && (pba->syn_count > 0)) { char *format = "%8" FS_ULL; StatLineFieldL("ttl stream length", "bytes", format, stream_length_pba, 1); } else { StatLineField("ttl stream length", "", "%s", (u_long)"NA", 1); } if ((pab->fin_count > 0) && (pab->syn_count > 0)) { char *format = "%8" FS_ULL; StatLineFieldL("missed data", "bytes", format, (stream_length_pab - pab->unique_bytes), 0); } else { StatLineField("missed data", "", "%s", (u_long)"NA", 0); } if ((pba->fin_count > 0) && (pba->syn_count > 0)) { char *format = "%8" FS_ULL; StatLineFieldL("missed data", "bytes", format, (stream_length_pba - pba->unique_bytes), 1); } else { StatLineField("missed data", "", "%s", (u_long)"NA", 1); } /* tell how much data was NOT captured in the files */ StatLineI("truncated data","bytes", pab->trunc_bytes, pba->trunc_bytes); StatLineI("truncated packets","pkts", pab->trunc_segs, pba->trunc_segs); /* stats on just the data */ etime_data1 = elapsed(pab->first_data_time, pab->last_data_time); /* in usecs */ etime_data2 = elapsed(pba->first_data_time, pba->last_data_time); /* in usecs */ /* fix from Rob Austein */ StatLineF("data xmit time","secs","%7.3f", etime_data1 / 1000000.0, etime_data2 / 1000000.0); StatLineP("idletime max","ms","%s", ZERO_TIME(&pab->last_time)?"NA": (snprintf(bufl,sizeof(bufl),"%8.1f",(double)pab->idle_max/1000.0),bufl), ZERO_TIME(&pba->last_time)?"NA": (snprintf(bufr,sizeof(bufr),"%8.1f",(double)pba->idle_max/1000.0),bufr)); if ((pab->num_hardware_dups != 0) || (pba->num_hardware_dups != 0) || csv || tsv || (sv != NULL)) { StatLineI("hardware dups","segs", pab->num_hardware_dups, pba->num_hardware_dups); if(!(csv || tsv || (sv != NULL))) fprintf(stdout, " ** WARNING: presence of hardware duplicates makes these figures suspect!\n"); } /* do the throughput calcs */ etime /= 1000000.0; /* convert to seconds */ if (etime == 0.0) StatLineP("throughput","","%s","NA","NA"); else StatLineF("throughput","Bps","%8.0f", (double) (pab->unique_bytes) / etime, (double) (pba->unique_bytes) / etime); if (print_rtt) { if(!(csv || tsv || (sv != NULL))) fprintf(stdout,"\n"); StatLineI("RTT samples","", pab->rtt_count, pba->rtt_count); StatLineF("RTT min","ms","%8.1f", (double)pab->rtt_min/1000.0, (double)pba->rtt_min/1000.0); StatLineF("RTT max","ms","%8.1f", (double)pab->rtt_max/1000.0, (double)pba->rtt_max/1000.0); StatLineF("RTT avg","ms","%8.1f", Average(pab->rtt_sum, pab->rtt_count) / 1000.0, Average(pba->rtt_sum, pba->rtt_count) / 1000.0); StatLineF("RTT stdev","ms","%8.1f", Stdev(pab->rtt_sum, pab->rtt_sum2, pab->rtt_count) / 1000.0, Stdev(pba->rtt_sum, pba->rtt_sum2, pba->rtt_count) / 1000.0); if(!(csv || tsv || (sv != NULL))) fprintf(stdout,"\n"); StatLineF("RTT from 3WHS","ms","%8.1f", (double)pab->rtt_3WHS/1000.0, (double)pba->rtt_3WHS/1000.0); if(!(csv || tsv || (sv != NULL))) fprintf(stdout,"\n"); StatLineI("RTT full_sz smpls","", pab->rtt_full_count, pba->rtt_full_count); StatLineF("RTT full_sz min","ms","%8.1f", (double)pab->rtt_full_min/1000.0, (double)pba->rtt_full_min/1000.0); StatLineF("RTT full_sz max","ms","%8.1f", (double)pab->rtt_full_max/1000.0, (double)pba->rtt_full_max/1000.0); StatLineF("RTT full_sz avg","ms","%8.1f", Average(pab->rtt_full_sum, pab->rtt_full_count) / 1000.0, Average(pba->rtt_full_sum, pba->rtt_full_count) / 1000.0); StatLineF("RTT full_sz stdev","ms","%8.1f", Stdev(pab->rtt_full_sum, pab->rtt_full_sum2, pab->rtt_full_count) / 1000.0, Stdev(pba->rtt_full_sum, pba->rtt_full_sum2, pba->rtt_full_count) / 1000.0); if(!(csv || tsv || (sv != NULL))) fprintf(stdout,"\n"); StatLineI("post-loss acks","", pab->rtt_nosample, pba->rtt_nosample); if (pab->rtt_amback || pba->rtt_amback || csv || tsv || (sv != NULL)) { if(!(csv || tsv || (sv != NULL))) fprintf(stdout, "\ \t For the following 5 RTT statistics, only ACKs for\n\ \t multiply-transmitted segments (ambiguous ACKs) were\n\ \t considered. Times are taken from the last instance\n\ \t of a segment.\n\ "); StatLineI("ambiguous acks","", pab->rtt_amback, pba->rtt_amback); StatLineF("RTT min (last)","ms","%8.1f", (double)pab->rtt_min_last/1000.0, (double)pba->rtt_min_last/1000.0); StatLineF("RTT max (last)","ms","%8.1f", (double)pab->rtt_max_last/1000.0, (double)pba->rtt_max_last/1000.0); StatLineF("RTT avg (last)","ms","%8.1f", Average(pab->rtt_sum_last, pab->rtt_count_last) / 1000.0, Average(pba->rtt_sum_last, pba->rtt_count_last) / 1000.0); StatLineF("RTT sdv (last)","ms","%8.1f", Stdev(pab->rtt_sum_last, pab->rtt_sum2_last, pab->rtt_count_last) / 1000.0, Stdev(pba->rtt_sum_last, pba->rtt_sum2_last, pba->rtt_count_last) / 1000.0); } StatLineI("segs cum acked","", pab->rtt_cumack, pba->rtt_cumack); StatLineI("duplicate acks","", pab->rtt_dupack, pba->rtt_dupack); StatLineI("triple dupacks","", pab->rtt_triple_dupack, pba->rtt_triple_dupack); if (debug) StatLineI("unknown acks:","", pab->rtt_unkack, pba->rtt_unkack); StatLineI("max # retrans","", pab->retr_max, pba->retr_max); StatLineF("min retr time","ms","%8.1f", (double)((double)pab->retr_min_tm/1000.0), (double)((double)pba->retr_min_tm/1000.0)); StatLineF("max retr time","ms","%8.1f", (double)((double)pab->retr_max_tm/1000.0), (double)((double)pba->retr_max_tm/1000.0)); StatLineF("avg retr time","ms","%8.1f", Average(pab->retr_tm_sum, pab->retr_tm_count) / 1000.0, Average(pba->retr_tm_sum, pba->retr_tm_count) / 1000.0); StatLineF("sdv retr time","ms","%8.1f", Stdev(pab->retr_tm_sum, pab->retr_tm_sum2, pab->retr_tm_count) / 1000.0, Stdev(pba->retr_tm_sum, pba->retr_tm_sum2, pba->retr_tm_count) / 1000.0); } if(csv || tsv || (sv != NULL)) { printf("\n"); /* Error checking: print an error message if the count of printed fields * doesn't correspond to the actual fields expected. */ if(sv_print_count != sv_expected_count) { fprintf(stderr, "output.c: Count of printed fields does not correspond to count of header fields for long output with comma/tab/<SP>-separated values.\n"); fprintf(stderr,"sv_print_count=%u, sv_expected_count=%u\n", sv_print_count, sv_expected_count); exit(-1); } } }
void DoThru( tcb *ptcb, int nbytes) { double etime; double thruput; char *myname, *hisname; /* init, if not already done */ if (ZERO_TIME(&ptcb->thru_firsttime)) { char title[210]; ptcb->thru_firsttime = current_time; ptcb->thru_lasttime = current_time; ptcb->thru_pkts = 1; ptcb->thru_bytes = nbytes; /* bug fix from Michele Clark - UNC */ if (&ptcb->ptp->a2b == ptcb) { myname = ptcb->ptp->a_endpoint; hisname = ptcb->ptp->b_endpoint; } else { myname = ptcb->ptp->b_endpoint; hisname = ptcb->ptp->a_endpoint; } /* create the plotter file */ snprintf(title,sizeof(title),"%s_==>_%s (throughput)", myname, hisname); ptcb->thru_plotter = new_plotter(ptcb,NULL,title, "time","thruput (bytes/sec)", THROUGHPUT_FILE_EXTENSION); if (graph_time_zero) { /* set graph zero points */ plotter_nothing(ptcb->thru_plotter, current_time); } /* create lines for average and instantaneous values */ ptcb->thru_avg_line = new_line(ptcb->thru_plotter, "avg. tput", "blue"); ptcb->thru_inst_line = new_line(ptcb->thru_plotter, "inst. tput", "red"); return; } /* if no data, then nothing to do */ if (nbytes == 0) return; /* see if we should output the stats yet */ if (ptcb->thru_pkts+1 >= thru_interval) { /* compute stats for this interval */ etime = elapsed(ptcb->thru_firsttime,current_time); if (etime == 0.0) etime = 1000; /* ick, what if "no time" has passed?? */ thruput = (double) ptcb->thru_bytes / ((double) etime / 1000000.0); /* instantaneous plot */ extend_line(ptcb->thru_inst_line, current_time, (int) thruput); /* compute stats for connection lifetime */ etime = elapsed(ptcb->ptp->first_time,current_time); if (etime == 0.0) etime = 1000; /* ick, what if "no time" has passed?? */ thruput = (double) ptcb->data_bytes / ((double) etime / 1000000.0); /* long-term average */ extend_line(ptcb->thru_avg_line, current_time, (int) thruput); /* reset stats for this interval */ ptcb->thru_firsttime = current_time; ptcb->thru_pkts = 0; ptcb->thru_bytes = 0; } /* immediate value in yellow ticks */ if (plot_tput_instant) { etime = elapsed(ptcb->thru_lasttime,current_time); if (etime == 0.0) etime = 1000; /* ick, what if "no time" has passed?? */ thruput = (double) nbytes / ((double) etime / 1000000.0); plotter_temp_color(ptcb->thru_plotter,"yellow"); plotter_dot(ptcb->thru_plotter, current_time, (int) thruput); } /* add in the latest packet */ ptcb->thru_lasttime = current_time; ++ptcb->thru_pkts; ptcb->thru_bytes += nbytes; }
udp_pair * udpdotrace( struct ip *pip, struct udphdr *pudp, void *plast) { udp_pair *pup_save; ucb *thisdir; ucb *otherdir; udp_pair tp_in; int dir; u_short uh_sport; /* source port */ u_short uh_dport; /* destination port */ u_short uh_ulen; /* data length */ /* make sure we have enough of the packet */ if ((char *)pudp + sizeof(struct udphdr)-1 > (char *)plast) { if (warn_printtrunc) fprintf(stderr, "UDP packet %lu truncated too short to trace, ignored\n", pnum); ++ctrunc; return(NULL); } /* convert interesting fields to local byte order */ uh_sport = ntohs(pudp->uh_sport); uh_dport = ntohs(pudp->uh_dport); uh_ulen = ntohs(pudp->uh_ulen); /* make sure this is one of the connections we want */ pup_save = FindUTP(pip,pudp,&dir); ++packet_count; if (pup_save == NULL) { return(NULL); } ++udp_trace_count; /* do time stats */ if (ZERO_TIME(&pup_save->first_time)) { pup_save->first_time = current_time; } pup_save->last_time = current_time; // Lets not waste any more CPU cycles if we are ignoring this connection. if (pup_save->ignore_pair) return (pup_save); /* save to a file if requested */ if (output_filename) { PcapSavePacket(output_filename,pip,plast); } /* now, print it if requested */ if (printem && !printallofem) { printf("Packet %lu\n", pnum); printpacket(0, /* original length not available */ (char *)plast - (char *)pip + 1, NULL,0, /* physical stuff not known here */ pip,plast,NULL); } /* grab the address from this packet */ CopyAddr(&tp_in.addr_pair, pip, uh_sport, uh_dport); /* figure out which direction this packet is going */ if (dir == A2B) { thisdir = &pup_save->a2b; otherdir = &pup_save->b2a; } else { thisdir = &pup_save->b2a; otherdir = &pup_save->a2b; } /* do data stats */ thisdir->packets += 1; thisdir->data_bytes += uh_ulen; /* total packets stats */ ++pup_save->packets; return(pup_save); }