Changeset 4dd7363 for examples


Ignore:
Timestamp:
10/13/05 14:09:18 (15 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d2cc963
Parents:
3aed3ed
Message:

Add tracestats and a simple wrapper to display some common statistics

Location:
examples/count
Files:
3 added
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • examples/count/Makefile

    r18478c1 r4dd7363  
    99LDLIBS = $(libdir) -ltrace
    1010
    11 BINS = count
     11BINS = tracestats
    1212.PHONY: all clean distclean install depend
    1313
  • examples/count/tracestats.c

    r18478c1 r4dd7363  
    3030
    3131//
    32 // This program takes a trace and outputs every packet that it sees to standard
    33 // out, decoding source/dest IP's, protocol type, and the timestamp of this
    34 // packet.
     32// This program takes a series of traces and bpf filters and outputs how many
     33// bytes/packets
    3534
    3635#include <stdio.h>
     
    6362} *filters = NULL;
    6463int filter_count=0;
    65 uint64_t count;
    66 uint64_t bytes;
     64uint64_t totcount;
     65uint64_t totbytes;
    6766
    6867/* Process a trace, counting packets that match filter(s) */
     
    7170        struct libtrace_packet_t packet;
    7271        int i;
     72        uint64_t count = 0;
     73        uint64_t bytes = 0;
    7374
    7475        fprintf(stderr,"%s:\n",uri);
     
    9495
    9596        for(i=0;i<filter_count;++i) {
    96                 printf("%s\t%8"PRIu64"\t%8"PRIu64"\t%5.02f\n",filters[i].expr,filters[i].count,filters[i].bytes,filters[i].count*100.0/count);
     97                printf("%30s:\t%12"PRIu64"\t%12"PRIu64"\t%7.03f\n",filters[i].expr,filters[i].count,filters[i].bytes,filters[i].count*100.0/count);
    9798                filters[i].bytes=0;
    9899                filters[i].count=0;
    99100        }
    100         printf("Total:\t%8"PRIu64"\t%8" PRIu64 "\n",count,bytes);
    101         count=0;
    102         bytes=0;
     101        printf("%30s:\t%12"PRIu64"\t%12" PRIu64 "\n","Total",count,bytes);
     102        totcount+=count;
     103        totbytes+=bytes;
    103104
    104105        trace_destroy(trace);
     
    143144        }
    144145
    145         printf("filter\tcount    \tbytes   \t%%\n");
     146        printf("%-30s\t%12s\t%12s\t%7s\n","filter","count","bytes","%");
    146147        for(i=optind;i<argc;++i) {
    147148                run_trace(argv[i]);
     149        }
     150        if (optind+1<argc) {
     151                printf("Grand total:\n");
     152                printf("%30s:\t%12"PRIu64"\t%12" PRIu64 "\n","Total",totcount,totbytes);
    148153        }
    149154
Note: See TracChangeset for help on using the changeset viewer.