Changeset 904c639 for tools


Ignore:
Timestamp:
06/12/09 16:19:38 (12 years ago)
Author:
Shane Alcock <salcock@…>
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:
8365c66
Parents:
3fc7948
Message:
  • Added a --count option to tracereport that will stop processing after N packets
  • Ensure that when the "done" flag is set, we don't waste time opening and immediately closing any outstanding trace files
  • Removed old code for "count" parameter that had been commented out
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/tracereport/tracereport.c

    r4423dc7 r904c639  
    5151struct libtrace_t *trace;
    5252uint32_t reports_required = 0;
     53int packets_read = 0;
    5354
    5455static volatile int done=0;
     
    6364{
    6465        struct libtrace_packet_t *packet = trace_create_packet();
     66
     67        /* Already read the maximum number of packets - don't need to read
     68         * anything from this trace */
     69        if ((count >= 0 && packets_read >= count) || done)
     70                return;
    6571
    6672        trace = trace_create(uri);
     
    8086        }
    8187
    82         for (;;) {
     88        while (1) {
    8389                int psize;
    8490               
    85                 /* Not convinced we need this count business */
    86                 /*
    87                 if (count--<1)
     91                if (count >= 0 && packets_read >= count)
    8892                        break;
    89                 */
    9093                if (done)
    9194                        break;
     
    119122                if (reports_required & REPORT_TYPE_TCPSEG)
    120123                        tcpseg_per_packet(packet);
     124
     125                packets_read ++;
    121126        }
    122127        if (reports_required & REPORT_TYPE_DROPS)
     
    130135        "%s flags traceuri [traceuri...]\n"
    131136        "-f --filter=bpf        \tApply BPF filter. Can be specified multiple times\n"
     137        "-c --count=N           Stop after reading N packets\n"
    132138        "-e --error             Report packet errors (e.g. checksum failures, rxerrors)\n"
    133139        "-F --flow              Report flows\n"
     
    154160        char *filterstring=NULL;
    155161        struct sigaction sigact;
     162        int count = -1;
    156163
    157164        libtrace_filter_t *filter = NULL;/*trace_bpf_setfilter(filterstring); */
     
    160167                int option_index;
    161168                struct option long_options[] = {
     169                        { "count",              1, 0, 'c' },
    162170                        { "ecn",                0, 0, 'C' },
    163171                        { "direction",          0, 0, 'd' },
     
    178186                        { NULL,                 0, 0, 0 }
    179187                };
    180                 opt = getopt_long(argc, argv, "Df:HemFPpTtOondCsl:",
     188                opt = getopt_long(argc, argv, "Df:HemFPpTtOondCsc:",
    181189                                long_options, &option_index);
    182190                if (opt == -1)
     
    184192               
    185193                switch (opt) {
     194                        case 'c':
     195                                count = atoi(optarg);
     196                                break;
    186197                        case 'C':
    187198                                reports_required |= REPORT_TYPE_ECN;
     
    261272                 * genuine output at the moment */
    262273                fprintf(stderr, "Reading from trace: %s\n", argv[i]);
    263                 run_trace(argv[i],filter,(1<<30));
     274                run_trace(argv[i],filter, count);
    264275        }
    265276
Note: See TracChangeset for help on using the changeset viewer.