Changeset 5ab626a


Ignore:
Timestamp:
02/18/15 17:41:48 (6 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
e4f27d1
Parents:
8bcc925
Message:

Deprecate trace_get_filtered/accepted/recevied/dropped() in favour of a single function

Adds the single trace_get_statistics function. This allows the structure to be filled
at a point in time, rather than making multiple calls to the library during which state
might have changed.

This has been designed such that the structure can be added to in the future without
breaking old code.

The old internal get_captured_packets was removed from the formats as it was never used.
Eventually we should completely remove get_filtered and received from the formats and replace
them with get_statistics.

In additon some extra fields have added, such as error and captured and the pre-existing
fields are better defined.

The linux formats have been updated to use this new API, which combined with reading
/proc/net/dev returns a full set of statistics.

Files:
22 edited

Legend:

Unmodified
Added
Removed
  • lib/format_atmhdr.c

    rb13b939 r5ab626a  
    227227        NULL,                           /* get_filtered_packets */
    228228        NULL,                           /* get_dropped_packets */
    229         NULL,                           /* get_captured_packets */
     229        NULL,                           /* get_statistics */
    230230        NULL,                           /* get_fd */
    231231        trace_event_trace,              /* trace_event */
  • lib/format_bpf.c

    r9e429e8 r5ab626a  
    610610        NULL,                   /* get_filtered_packets */
    611611        bpf_get_dropped_packets,/* get_dropped_packets */
    612         NULL,                   /* get_captured_packets */
     612        NULL,                   /* get_statistics */
    613613        bpf_get_fd,             /* get_fd */
    614614        trace_event_device,     /* trace_event */
     
    657657        bpf_get_framing_length, /* get_framing_length */
    658658        NULL,                   /* set_capture_length */
    659         NULL,/* get_received_packets */
     659        NULL,                   /* get_received_packets */
    660660        NULL,                   /* get_filtered_packets */
    661         NULL,/* get_dropped_packets */
    662         NULL,                   /* get_captured_packets */
     661        NULL,                   /* get_dropped_packets */
     662        NULL,                   /* get_statistics */
    663663        NULL,                   /* get_fd */
    664664        NULL,                   /* trace_event */
  • lib/format_dag24.c

    r9e429e8 r5ab626a  
    554554        NULL,                           /* get_filtered_packets */
    555555        dag_get_dropped_packets,        /* get_dropped_packets */
    556         NULL,                           /* get_captured_packets */
     556        NULL,                           /* get_statistics */
    557557        NULL,                           /* get_fd */
    558558        trace_event_dag,                /* trace_event */
  • lib/format_dag25.c

    rde74f88 r5ab626a  
    15951595        NULL,                           /* get_filtered_packets */
    15961596        dag_get_dropped_packets,        /* get_dropped_packets */
    1597         NULL,                           /* get_captured_packets */
     1597        NULL,                           /* get_statistics */
    15981598        NULL,                           /* get_fd */
    15991599        trace_event_dag,                /* trace_event */
     
    16071607        dag_pconfig_input,
    16081608        dag_pregister_thread,
    1609         NULL
     1609        NULL,
     1610        NULL                            /* get thread stats */
    16101611};
    16111612
  • lib/format_dpdk.c

    r4631115 r5ab626a  
    21662166    /* Get the drop counter */
    21672167    return (uint64_t) stats.ierrors;
    2168 }
    2169 
    2170 static uint64_t dpdk_get_captured_packets (libtrace_t *trace) {
    2171     struct rte_eth_stats stats = {0};
    2172 
    2173     if (trace->format_data == NULL || FORMAT(trace)->port == 0xFF)
    2174         return UINT64_MAX;
    2175     /* Grab the current stats */
    2176     rte_eth_stats_get(FORMAT(trace)->port, &stats);
    2177 
    2178     /* Get the drop counter */
    2179     return (uint64_t) stats.ipackets;
    21802168}
    21812169
     
    23152303        dpdk_get_filtered_packets,/* get_filtered_packets */
    23162304        dpdk_get_dropped_packets,/* get_dropped_packets */
    2317     dpdk_get_captured_packets,/* get_captured_packets */
     2305        NULL,                   /* get_statistics */
    23182306        NULL,                       /* get_fd */
    23192307        dpdk_trace_event,               /* trace_event */
    2320     dpdk_help,              /* help */
    2321     NULL,                   /* next pointer */
    2322     {true, 8},              /* Live, NICs typically have 8 threads */
    2323     dpdk_pstart_input, /* pstart_input */
     2308        dpdk_help,              /* help */
     2309        NULL,                   /* next pointer */
     2310        {true, 8},              /* Live, NICs typically have 8 threads */
     2311        dpdk_pstart_input, /* pstart_input */
    23242312        dpdk_pread_packets, /* pread_packets */
    23252313        dpdk_pause_input, /* ppause */
    23262314        dpdk_fin_input, /* p_fin */
    23272315        dpdk_pconfig_input, /* pconfig_input */
    2328     dpdk_pregister_thread, /* pregister_thread */
    2329     dpdk_punregister_thread /* unpregister_thread */
     2316        dpdk_pregister_thread, /* pregister_thread */
     2317        dpdk_punregister_thread, /* punregister_thread */
     2318        NULL                            /* get thread stats */
    23302319};
    23312320
  • lib/format_duck.c

    r4631115 r5ab626a  
    362362        NULL,                           /* get_filtered_packets */
    363363        NULL,                           /* get_dropped_packets */
    364         NULL,                           /* get_captured_packets */
     364        NULL,                           /* get_statistics */
    365365        NULL,                           /* get_fd */
    366366        NULL,                           /* trace_event */
  • lib/format_erf.c

    r97d170d r5ab626a  
    833833        NULL,                           /* get_filtered_packets */
    834834        erf_get_dropped_packets,        /* get_dropped_packets */
    835         NULL,                           /* get_captured_packets */
     835        NULL,                           /* get_statistics */
    836836        NULL,                           /* get_fd */
    837837        erf_event,                      /* trace_event */
     
    877877        NULL,                           /* get_filtered_packets */
    878878        erf_get_dropped_packets,        /* get_dropped_packets */
    879         NULL,                           /* get_captured_packets */
     879        NULL,                           /* get_statistics */
    880880        NULL,                           /* get_fd */
    881881        erf_event,                      /* trace_event */
  • lib/format_legacy.c

    rb13b939 r5ab626a  
    548548        NULL,                           /* get_filtered_packets */
    549549        NULL,                           /* get_dropped_packets */
    550         NULL,                           /* get_captured_packets */
     550        NULL,                           /* get_statistics */
    551551        NULL,                           /* get_fd */
    552552        trace_event_trace,              /* trace_event */
     
    592592        NULL,                           /* get_filtered_packets */
    593593        NULL,                           /* get_dropped_packets */
    594         NULL,                           /* get_captured_packets */
     594        NULL,                           /* get_statistics */
    595595        NULL,                           /* get_fd */
    596596        trace_event_trace,              /* trace_event */
     
    636636        NULL,                           /* get_filtered_packets */
    637637        NULL,                           /* get_dropped_packets */
    638         NULL,                           /* get_captured_packets */
     638        NULL,                           /* get_statistics */
    639639        NULL,                           /* get_fd */
    640640        trace_event_trace,              /* trace_event */
     
    680680        NULL,                           /* get_filtered_packets */
    681681        NULL,                           /* get_dropped_packets */
    682         NULL,                           /* get_captured_packets */
     682        NULL,                           /* get_statistics */
    683683        NULL,                           /* get_fd */
    684684        trace_event_trace,              /* trace_event */
  • lib/format_linux_common.c

    red6304c5 r5ab626a  
    186186        FORMAT_DATA->filter = NULL;
    187187        FORMAT_DATA->stats_valid = 0;
     188        FORMAT_DATA->stats.tp_drops = 0;
     189        FORMAT_DATA->stats.tp_packets = 0;
    188190        FORMAT_DATA->max_order = MAX_ORDER;
    189191        FORMAT_DATA->fanout_flags = PACKET_FANOUT_LB;
     
    253255                             tmp_stats.if_name,
    254256                             &tmp_stats.rx_bytes,
    255                              &tmp_stats.rx_bytes,
     257                             &tmp_stats.rx_packets,
    256258                             &tmp_stats.rx_errors,
    257259                             &tmp_stats.rx_drops,
     
    402404                               sizeof(filter->filter)) == -1) {
    403405                        perror("setsockopt(SO_ATTACH_FILTER)");
    404                 } else {
    405                         /* The socket accepted the filter, so we need to
    406                          * consume any buffered packets that were received
    407                          * between opening the socket and applying the filter.
    408                          */
    409                         void *buf = malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
    410                         while(recv(stream->fd,
    411                                    buf,
    412                                    (size_t)LIBTRACE_PACKET_BUFSIZE,
    413                                    MSG_DONTWAIT) != -1) { }
    414                         free(buf);
    415                 }
    416         }
    417 
    418         FORMAT_DATA->stats_valid = 0;
     406                }
     407        }
     408
     409        /* Consume any buffered packets that were received before the socket
     410         * was properly setup, including those which missed the filter and
     411         * bind()ing to an interface.
     412         *
     413         * If packet rate is high this could therotically hang forever. 4K
     414         * should be a large enough limit.
     415         */
     416        int count = 0;
     417        void *buf = malloc((size_t)LIBTRACE_PACKET_BUFSIZE);
     418        while(count < 4096 &&
     419                recv(stream->fd,
     420                   buf,
     421                   (size_t)LIBTRACE_PACKET_BUFSIZE,
     422                   MSG_DONTWAIT) != -1) { count++; }
     423        free(buf);
     424        fprintf(stderr, "set offset %d", count);
     425
     426        /* Mark that the stats are valid and apply an offset */
     427        FORMAT_DATA->stats_valid = 1;
     428        /* Offset by number we ate for each stream */
     429        FORMAT_DATA->stats.tp_packets -= count;
     430
     431
    419432        if (linuxcommon_get_dev_statisitics(libtrace, &FORMAT_DATA->dev_stats) != 0) {
    420433                /* Mark this as bad */
     
    561574}
    562575
    563 /* Number of packets that passed filtering */
    564 uint64_t linuxcommon_get_captured_packets(libtrace_t *libtrace) {
     576#define DEV_DIFF(x) (dev_stats.x - FORMAT_DATA->dev_stats.x)
     577/* Note these statistics come from two different sources, the socket itself and
     578 * the linux device. As such this means it is highly likely that their is some
     579 * margin of error in the returned statisitics, we perform basic sanitising so
     580 * that these are not too noticable.
     581 */
     582void linuxcommon_get_statistics(libtrace_t *libtrace, libtrace_stat_t *stat) {
     583        struct linux_dev_stats dev_stats;
    565584        if (libtrace->format_data == NULL)
    566                 return UINT64_MAX;
     585                return;
     586        /* Do we need to consider the case after the trace is closed? */
    567587        if (FORMAT_DATA_FIRST->fd == -1) {
    568588                /* This is probably a 'dead' trace so obviously we can't query
    569589                 * the socket for capture counts, can we? */
    570                 return UINT64_MAX;
     590                return;
     591        }
     592
     593        dev_stats.if_name[0] = 0; /* This will be set if we retrive valid stats */
     594        /* Do we have starting stats to compare to? */
     595        if (FORMAT_DATA->dev_stats.if_name[0] != 0) {
     596                linuxcommon_get_dev_statisitics(libtrace, &dev_stats);
    571597        }
    572598        linuxcommon_update_socket_statistics(libtrace);
    573         if (FORMAT_DATA->stats_valid)
    574                 return FORMAT_DATA->stats.tp_packets;
    575         else
    576                 return UINT64_MAX;
    577 }
    578 
    579 /* Number of packets that got past filtering and were then dropped because
    580  * of lack of space.
    581  *
    582  * We could also try read from /sys/class/net/ethX/statistics/ to get
    583  * real drop counters and stuff.
    584  */
    585 uint64_t linuxcommon_get_dropped_packets(libtrace_t *libtrace) {
    586         struct linux_dev_stats dev_stats;
    587         uint64_t adjustment = 0;
    588         if (libtrace->format_data == NULL)
    589                 return UINT64_MAX;
    590         if (FORMAT_DATA_FIRST->fd == -1) {
    591                 /* This is probably a 'dead' trace so obviously we can't query
    592                  * the socket for drop counts, can we? */
    593                 return UINT64_MAX;
    594         }
    595         // Do we have starting stats to compare to?
    596         if (FORMAT_DATA->dev_stats.if_name[0] != 0) {
    597                 if (linuxcommon_get_dev_statisitics(libtrace, &dev_stats) == 0) {
    598                         adjustment = dev_stats.rx_drops - FORMAT_DATA->dev_stats.rx_drops;
    599                 }
    600         }
    601         linuxcommon_update_socket_statistics(libtrace);
    602         if (FORMAT_DATA->stats_valid)
    603                 return FORMAT_DATA->stats.tp_drops + adjustment;
    604         else
    605                 return UINT64_MAX;
    606 }
    607 
    608 /* Linux doesn't keep track how many packets were seen before filtering
    609  * so we can't tell how many packets were filtered.  Bugger.  So annoying.
    610  *
    611  * Since we tell libtrace that we do support filtering, if we don't declare
    612  * this here as failing, libtrace will happily report for us that it didn't
    613  * filter any packets, so don't lie -- return that we don't know.
    614  */
    615 uint64_t linuxcommon_get_filtered_packets(libtrace_t *trace UNUSED) {
    616         return UINT64_MAX;
     599
     600        /* filtered count == dev received - socket received */
     601        if (FORMAT_DATA->filter == NULL) {
     602                stat->filtered_valid = 1;
     603                stat->filtered = 0;
     604        } else if (FORMAT_DATA->stats_valid && dev_stats.if_name[0]) {
     605                stat->filtered_valid = 1;
     606                stat->filtered = DEV_DIFF(rx_packets) -
     607                                 FORMAT_DATA->stats.tp_packets;
     608                if (stat->filtered > UINT64_MAX - 100000) {
     609                        stat->filtered = 0;
     610                }
     611        }
     612
     613        /* dropped count == socket dropped + dev dropped */
     614        if (FORMAT_DATA->stats_valid) {
     615                stat->dropped_valid = 1;
     616                stat->dropped = FORMAT_DATA->stats.tp_drops;
     617                if (dev_stats.if_name[0]) {
     618                        stat->dropped += DEV_DIFF(rx_drops);
     619                }
     620        }
     621
     622        /* received count - All good packets even those dropped or filtered */
     623        if (dev_stats.if_name[0]) {
     624                stat->received_valid = 1;
     625                stat->received = DEV_DIFF(rx_packets) + DEV_DIFF(rx_drops);
     626        }
     627
     628        /* captured count - received and but not dropped */
     629        if (dev_stats.if_name[0] && FORMAT_DATA->stats_valid) {
     630                stat->captured_valid = 1;
     631                stat->captured = DEV_DIFF(rx_packets) - FORMAT_DATA->stats.tp_drops;
     632        }
     633
     634        /* errors */
     635        if (dev_stats.if_name[0]) {
     636                stat->errors_valid = 1;
     637                stat->errors = DEV_DIFF(rx_errors);
     638        }
     639
    617640}
    618641
     
    671694
    672695/* No NETPACKET - So this format is not live */
    673 uint64_t linuxcommon_get_filtered_packets(libtrace_t *trace UNUSED) {
    674         return UINT64_MAX;
    675 }
    676 
    677 uint64_t linuxcommon_get_captured_packets(libtrace_t *trace UNUSED) {
    678         return UINT64_MAX;
    679 }
    680 
    681 uint64_t linuxcommon_get_dropped_packets(libtrace_t *trace UNUSED) {
    682         return UINT64_MAX;
     696void linuxcommon_get_statistics(libtrace_t *libtrace UNUSED,
     697                                libtrace_stat_t *stat UNUSED) {
     698        return;
    683699}
    684700
  • lib/format_linux_common.h

    red6304c5 r5ab626a  
    325325#endif /* HAVE_NETPACKET_PACKET_H */
    326326
    327 uint64_t linuxcommon_get_captured_packets(libtrace_t *libtrace);
    328 uint64_t linuxcommon_get_filtered_packets(libtrace_t *libtrace);
    329 uint64_t linuxcommon_get_dropped_packets(libtrace_t *libtrace);
     327void linuxcommon_get_statistics(libtrace_t *libtrace, libtrace_stat_t *stat);
    330328inline libtrace_direction_t linuxcommon_get_direction(uint8_t pkttype);
    331329inline libtrace_direction_t linuxcommon_set_direction(struct sockaddr_ll * skadr,
  • lib/format_linux_int.c

    r6cf3ca0 r5ab626a  
    508508        linuxnative_set_capture_length, /* set_capture_length */
    509509        NULL,                           /* get_received_packets */
    510         linuxcommon_get_filtered_packets,/* get_filtered_packets */
    511         linuxcommon_get_dropped_packets,/* get_dropped_packets */
    512         linuxcommon_get_captured_packets,/* get_captured_packets */
     510        NULL,                           /* get_filtered_packets */
     511        NULL,                           /* get_dropped_packets */
     512        linuxcommon_get_statistics,     /* get_statistics */
    513513        linuxcommon_get_fd,             /* get_fd */
    514514        trace_event_device,             /* trace_event */
    515515        linuxnative_help,               /* help */
    516         NULL,                                   /* next pointer */
    517         {true, -1},              /* Live, no thread limit */
    518         linuxnative_pstart_input,                       /* pstart_input */
    519         linuxnative_pread_packets,                      /* pread_packets */
    520         linuxcommon_pause_input,                        /* ppause */
    521         linuxcommon_fin_input,                          /* p_fin */
    522         linuxcommon_pconfig_input,                      /* pconfig input */
    523         linuxcommon_pregister_thread,
    524         NULL
     516        NULL,                           /* next pointer */
     517        {true, -1},                     /* Live, no thread limit */
     518        linuxnative_pstart_input,       /* pstart_input */
     519        linuxnative_pread_packets,      /* pread_packets */
     520        linuxcommon_pause_input,        /* ppause */
     521        linuxcommon_fin_input,          /* p_fin */
     522        linuxcommon_pconfig_input,      /* pconfig input */
     523        linuxcommon_pregister_thread,   /* register thread */
     524        NULL,                           /* unregister thread */
     525        NULL                            /* get thread stats */
    525526};
    526527#else
     
    564565        linuxnative_set_capture_length, /* set_capture_length */
    565566        NULL,                           /* get_received_packets */
    566         linuxnative_get_filtered_packets,/* get_filtered_packets */
    567         linuxnative_get_dropped_packets,/* get_dropped_packets */
    568         linuxnative_get_captured_packets,/* get_captured_packets */
     567        NULL,                           /* get_filtered_packets */
     568        NULL,                           /* get_dropped_packets */
     569        linuxcommon_get_statistics,     /* get_statistics */
    569570        linuxnative_get_fd,             /* get_fd */
    570571        trace_event_device,             /* trace_event */
  • lib/format_linux_ring.c

    r3e89670 r5ab626a  
    745745        linuxring_set_capture_length,   /* set_capture_length */
    746746        NULL,                           /* get_received_packets */
    747         linuxcommon_get_filtered_packets,/* get_filtered_packets */
    748         linuxcommon_get_dropped_packets,/* get_dropped_packets */
    749         linuxcommon_get_captured_packets,/* get_captured_packets */
     747        NULL,                           /* get_filtered_packets */
     748        NULL,                           /* get_dropped_packets */
     749        linuxcommon_get_statistics,     /* get_statistics */
    750750        linuxcommon_get_fd,             /* get_fd */
    751751        linuxring_event,                /* trace_event */
     
    757757        linuxcommon_pause_input,        /* ppause */
    758758        linuxcommon_fin_input,          /* p_fin */
    759         linuxcommon_pconfig_input,      /* pconfig input */
    760         linuxcommon_pregister_thread,
    761         NULL
     759        linuxcommon_pconfig_input,      /* pconfig input */
     760        linuxcommon_pregister_thread,   /* register thread */
     761        NULL,                           /* unregister thread */
     762        NULL                            /* get thread stats */
    762763};
    763764#else
     
    805806        NULL,                           /* get_filtered_packets */
    806807        NULL,                           /* get_dropped_packets */
    807         NULL,                           /* get_captured_packets */
     808        linuxcommon_get_statistics,     /* get_statistics */
    808809        NULL,                           /* get_fd */
    809810        NULL,                           /* trace_event */
  • lib/format_pcap.c

    r9e429e8 r5ab626a  
    830830        NULL,                           /* get_filtered_packets */
    831831        NULL,                           /* get_dropped_packets */
    832         NULL,                           /* get_captured_packets */
     832        NULL,                           /* get_statistics */
    833833        NULL,                           /* get_fd */
    834834        trace_event_trace,              /* trace_event */
     
    874874        NULL,                           /* get_filtered_packets */
    875875        pcap_get_dropped_packets,       /* get_dropped_packets */
    876         NULL,                           /* get_captured_packets */
     876        NULL,                           /* get_statistics */
    877877        pcap_get_fd,                    /* get_fd */
    878878        trace_event_device,             /* trace_event */
  • lib/format_pcapfile.c

    r97d170d r5ab626a  
    782782        NULL,                           /* get_filtered_packets */
    783783        NULL,                           /* get_dropped_packets */
    784         NULL,                           /* get_captured_packets */
     784        NULL,                           /* get_statistics */
    785785        NULL,                           /* get_fd */
    786786        pcapfile_event,         /* trace_event */
  • lib/format_rt.c

    r4631115 r5ab626a  
    859859        NULL,                           /* get_filtered_packets */
    860860        NULL,                           /* get_dropped_packets */
    861         NULL,                           /* get_captured_packets */
     861        NULL,                           /* get_statistics */
    862862        rt_get_fd,                      /* get_fd */
    863863        trace_event_rt,             /* trace_event */
  • lib/format_tsh.c

    r97d170d r5ab626a  
    270270        NULL,                           /* get_filtered_packets */
    271271        NULL,                           /* get_dropped_packets */
    272         NULL,                           /* get_captured_packets */
     272        NULL,                           /* get_statistics */
    273273        NULL,                           /* get_fd */
    274274        trace_event_trace,              /* trace_event */
     
    319319        NULL,                           /* get_filtered_packets */
    320320        NULL,                           /* get_dropped_packets */
    321         NULL,                           /* get_captured_packets */
     321        NULL,                           /* get_statistics */
    322322        NULL,                           /* get_fd */
    323323        trace_event_trace,              /* trace_event */
  • lib/libtrace.h.in

    r4631115 r5ab626a  
    6363
    6464#include <sys/types.h>
     65#include <stddef.h>
     66#include <stdio.h>
     67/* Compile time assertion. Sourced from:
     68 * http://www.pixelbeat.org/programming/gcc/static_assert.html */
     69#define ct_assert(e) extern char (*ct_assert(void)) [sizeof(char[1 - 2*!(e)])]
     70
    6571#ifndef WIN32
    6672#include <sys/time.h>
     
    13081314} trace_option_output_t;
    13091315
     1316/* To add a new stat field update this list, and the relevent places in
     1317 * libtrace_stat_t structure.
     1318 */
     1319/** An X Macro set for libtrace stat fields */
     1320#define LIBTRACE_STAT_FIELDS \
     1321        X(accepted) \
     1322        X(filtered) \
     1323        X(received) \
     1324        X(dropped) \
     1325        X(captured) \
     1326        X(errors)
     1327
     1328/**
     1329 * Statistic counters are cumulative from the time the trace is started.
     1330 * Trace pause will reset the counters, to zero.
     1331 * Always check \a{field}_valid is set before attempting to read the stored value.
     1332 *
     1333 * @note Always allocate this structure using trace_create_statistics().
     1334 *       This allows us to extend the structure in the future.
     1335 */
     1336typedef struct libtrace_stat_t {
     1337        // Align to 64 bits, because the compiler is likely to do this anyway.
     1338#if __BYTE_ORDER == __LITTLE_ENDIAN
     1339#define X(name) LT_BITFIELD64 name ##_valid : 1;
     1340        LIBTRACE_STAT_FIELDS
     1341#undef X
     1342        /* We use the remaining space as magic to ensure the structure
     1343         * was alloc'd by us. We can easily decrease the no. bits without
     1344         * problems as long as we update any asserts as needed */
     1345        LT_BITFIELD64 reserved1: 26; /**< Bits reserved for future fields */
     1346        LT_BITFIELD64 reserved2: 24; /**< Bits reserved for future fields */
     1347        LT_BITFIELD64 magic: 8; /**< A number stored against the format to
     1348                                  ensure the struct was allocated correctly */
     1349#else
     1350        LT_BITFIELD64 magic: 8;
     1351        LT_BITFIELD64 reserved2: 24;
     1352        LT_BITFIELD64 reserved1: 26;
     1353        LT_BITFIELD64 dropped_valid: 1;
     1354        LT_BITFIELD64 received_valid: 1;
     1355        LT_BITFIELD64 filtered_valid: 1;
     1356        LT_BITFIELD64 accepted_valid: 1;
     1357#endif
     1358        /* These must all be uint64_t's, match this order with the X macro */
     1359        uint64_t accepted;
     1360        /**< The number of packets that have been read from the input trace
     1361         * using trace_read_packet(). In the parallel framework this may include
     1362         * some packets waiting in a batch yet to be seen by the user's
     1363         * application.
     1364         *
     1365         * This does not include filtered packets because these do not make it
     1366         * to trace_read_packet().
     1367         *
     1368         * @note This field replaces trace_get_accepted_packets()
     1369         */
     1370        uint64_t filtered;
     1371        /**< The number of packets that were captured, but discarded for not
     1372         * matching a provided filter.
     1373         *
     1374         * @note This field replaces trace_get_filtered_packets()
     1375         */
     1376        uint64_t received;
     1377        /**< The total number of good packets which have been recevied. Including
     1378         * those which are dropped and filtered. This does not include errors.
     1379         *
     1380         * @note This may include a small number of buffered packets
     1381         *       not yet included in accepted.
     1382         *
     1383         * @note This field replaces trace_get_received_packets()
     1384         */
     1385        uint64_t dropped;
     1386        /**< The number of packets that have been dropped on an input trace
     1387         * due to lack of buffer space on the capturing device. This does not
     1388         * included errored packets which are dropped directly by the card.
     1389         *
     1390         * @note This field replaces trace_get_dropped_packets()
     1391         */
     1392        uint64_t captured;
     1393        /**< The number of received packets that have not been dropped. This
     1394         * includes filtered packets.
     1395         *
     1396         * This is equivalent to received-dropped.
     1397         *
     1398         * @note This may include a small number of buffered packets
     1399         *       not yet included in accepted.
     1400         */
     1401        uint64_t errors;
     1402        /**< The number of packets that have been discarded by the network card
     1403         * because they are invalid. That includes FCS mismatches, incorrect
     1404         * packet lengths etc.
     1405         */
     1406} libtrace_stat_t;
     1407
     1408ct_assert(offsetof(libtrace_stat_t, accepted) == 8);
     1409
    13101410/** Sets an output config option
    13111411 *
     
    13991499 *
    14001500 * If the number is not known, this function will return UINT64_MAX
    1401  */
    1402 DLLEXPORT
     1501 *
     1502 * @deprecated This function is deprecated: Use trace_get_statistics(), this
     1503 *             allows all statistic counters to be read in an atomic manner.
     1504 */
     1505DLLEXPORT DEPRECATED
    14031506uint64_t trace_get_received_packets(libtrace_t *trace);
    14041507
     
    14101513 *
    14111514 * If the number is not known, this function will return UINT64_MAX
    1412  */
    1413 DLLEXPORT
     1515 *
     1516 * @deprecated This function is deprecated: Use trace_get_statistics(), this
     1517 *             allows all statistic counters to be read in an atomic manner.
     1518 */
     1519DLLEXPORT DEPRECATED
    14141520uint64_t trace_get_filtered_packets(libtrace_t *trace);
    14151521
     
    14211527 *
    14221528 * If the number is not known, this function will return UINT64_MAX
    1423  */
    1424 DLLEXPORT
     1529 *
     1530 * @deprecated This function is deprecated: Use trace_get_statistics(), this
     1531 *             allows all statistic counters to be read in an atomic manner.
     1532 */
     1533DLLEXPORT DEPRECATED
    14251534uint64_t trace_get_dropped_packets(libtrace_t *trace);
    14261535
     
    14321541 *
    14331542 * If the number is not known, this function will return UINT64_MAX
     1543 *
     1544 * @deprecated This function is deprecated: Use trace_get_statistics(), this
     1545 *             allows all statistic counters to be read in an atomic manner.
     1546 */
     1547DLLEXPORT DEPRECATED
     1548uint64_t trace_get_accepted_packets(libtrace_t *trace);
     1549
     1550/**
     1551 * Returns statistic counters for a trace, for a parallel trace this is a
     1552 * combined total.
     1553 * Where possible these are retrived atomically, however this behaviour depends
     1554 * on the underlying trace format.
     1555 *
     1556 * @param trace The input trace to examine.
     1557 * @param stats Optional, Filled upon return with statistics about the trace,
     1558 *              check the flags included to see if a given statistic is valid.
     1559 *              If NULL a statistic structure owned by libtrace is returned, this
     1560 *              should not be free'd and will become invalid if the trace is
     1561 *              destroyed.
     1562 *
     1563 * @return A pointer to the statistics structure.
     1564 * @note Use trace_create_stat() to create the stats object, this way future
     1565 *       versions of libtrace can add to the structure without breaking existing
     1566 *       code.
    14341567 */
    14351568DLLEXPORT
    1436 uint64_t trace_get_accepted_packets(libtrace_t *trace);
     1569libtrace_stat_t *trace_get_statistics(libtrace_t *trace, libtrace_stat_t *stats);
     1570
     1571
     1572/**
     1573 * Returns statistic counters for a single thread of a trace.
     1574 * Where possible these are retrived atomically, however this behaviour depends
     1575 * on the underlying trace format.
     1576 *
     1577 * @param trace The input trace to examine.
     1578 * @param t An optional thread to received stats for or NULL to retrive stats
     1579 *          for the current thread
     1580 * @param stats Filled upon return with statistics about the trace, check the
     1581 *              flags included to see if a given statistic is valid.
     1582 *
     1583 * @note Use trace_create_stat() to create the stats object, this way future
     1584 *       versions of libtrace can add to the structure without breaking existing
     1585 *       code.
     1586 */
     1587DLLEXPORT
     1588void trace_get_thread_statistics(libtrace_t *trace, libtrace_thread_t *t,
     1589                                 libtrace_stat_t *stats);
     1590
     1591/**
     1592 * Creates and returns a zeroed libtrace_stat_t structure.
     1593 *
     1594 * This allows us to add extra fields increasing the size of the structure
     1595 * without breaking existing libtrace applications.
     1596 *
     1597 * This structure should be free'd using free().
     1598 *
     1599 * @return A valid pointer to a libtrace_stat_t struct otherwise NULL if
     1600 *         memory was not available.
     1601 */
     1602DLLEXPORT libtrace_stat_t* trace_create_statistics(void);
     1603
     1604/**
     1605 * Performs the operation c=a-b accounting for valid fields.
     1606 * c is allowed to be a or b.
     1607 *
     1608 * @param a The minuend
     1609 * @param b The subtrahend
     1610 * @param c The resulting difference
     1611 */
     1612DLLEXPORT
     1613void trace_subtract_statistics(const libtrace_stat_t *a,
     1614                               const libtrace_stat_t *b, libtrace_stat_t *c);
     1615
     1616/**
     1617 * Performs operation c=a+b accounting for valid fields.
     1618 * c is allowed to be a or b.
     1619 *
     1620 * @param a The first operand
     1621 * @param b The second operand
     1622 * @param c The result
     1623 */
     1624DLLEXPORT
     1625void trace_add_statistics(const libtrace_stat_t *a,
     1626                          const libtrace_stat_t *b, libtrace_stat_t *c);
     1627
     1628/**
     1629 * Prints all valid stats to a file stream, (which could be stdout/err).
     1630 * By default the format "name: value" is used.
     1631 *
     1632 * @param s The statistic structure to print
     1633 * @param f The output file stream
     1634 * @param format An optional format string such as the default ("%s: %"PRIu64"\n")
     1635 *               This is passed to fprintf and called with two arguments
     1636 *               first a char* (%s) and second a uint64_t (%PRIu64).
     1637 *
     1638 * @return -1 if an error occurs when writing to the file stream, check errno.
     1639 *         Otherwise 0.
     1640 */
     1641DLLEXPORT
     1642int trace_print_statistics(const libtrace_stat_t *s, FILE *f,
     1643                           const char *format);
    14371644
    14381645
     
    32663473        /* C99 Integer types */
    32673474        /* NOTE: Standard doesn't require 64-bit
    3268     * but x32 and x64 gcc does */
     3475        * but x32 and x64 gcc does */
    32693476        int64_t sint64;
    32703477        uint64_t uint64;
  • lib/libtrace_int.h

    r0b01fea r5ab626a  
    325325         * paused or stopped before this counter is taken
    326326         */
    327         uint64_t dropped_packets;
    328         uint64_t received_packets;
     327        libtrace_stat_t *stats;
    329328        struct user_configuration config;
    330329        libtrace_combine_t combiner;
    331330};
     331
     332#define LIBTRACE_STAT_MAGIC 0x41
    332333
    333334void trace_fin_packet(libtrace_packet_t *packet);
     
    457458
    458459        /** Given a filename, return if this is the most likely capture format
    459          * (used for devices). Used to "guess" the capture format when the
     460         * (used for devices). Used to "guess" the capture format when the
    460461         * URI is not fully specified.
    461462         *
    462463         * @param fname         The name of the device or file to examine
    463464         * @return 1 if the name matches the capture format, 0 otherwise
    464          */
     465         */
    465466        int (*probe_filename)(const char *fname);
    466467       
     
    834835         */
    835836        uint64_t (*get_dropped_packets)(libtrace_t *trace);
    836        
    837         /** Returns the number of packets captured and returned by an input
    838          * trace.
    839          *
    840          * @param trace         The input trace to get the capture count for
    841          * @return The number of packets returned to the libtrace user, or
    842          * UINT64_MAX if the number is unknown
    843          *
    844          * This is the number of packets that have been successfully returned
    845          * to the libtrace user via the read_packet() function.
    846          *
    847          */
    848         uint64_t (*get_captured_packets)(libtrace_t *trace);
     837
     838        /** Returns statistics about a trace. Flags are all set to 0 when
     839         * invoked.
     840         *
     841         * @param trace The libtrace object
     842         * @param stat A zeroed structure ready to be filled.
     843         */
     844        void (*get_statistics)(libtrace_t *trace, libtrace_stat_t *stat);
    849845       
    850846        /** Returns the file descriptor used by the input trace.
     
    958954         */
    959955        void (*punregister_thread)(libtrace_t *libtrace, libtrace_thread_t *t);
     956
     957        /**
     958         * Return statistics for a single thread.
     959         */
     960        void (*get_thread_statistics)(libtrace_t *libtrace,
     961                                      libtrace_thread_t *t,
     962                                      libtrace_stat_t *stat);
    960963};
    961964
    962965/** Macro to zero out a single thread format */
    963966#define NON_PARALLEL(live) \
    964 {live, 1},              /* trace info */ \
    965 NULL,                   /* pstart_input */ \
    966 NULL,                   /* pread_packet */ \
    967 NULL,                   /* ppause_input */ \
    968 NULL,                   /* pfin_input */ \
    969 NULL,                   /* pconfig_input */ \
    970 NULL,                   /* pregister_thread */ \
    971 NULL                    /* punregister_thread */
     967        {live, 1},              /* trace info */ \
     968        NULL,                   /* pstart_input */ \
     969        NULL,                   /* pread_packet */ \
     970        NULL,                   /* ppause_input */ \
     971        NULL,                   /* pfin_input */ \
     972        NULL,                   /* pconfig_input */ \
     973        NULL,                   /* pregister_thread */ \
     974        NULL,                   /* punregister_thread */ \
     975        NULL,                   /* get_thread_statistics */
    972976
    973977/** The list of registered capture formats */
  • lib/trace.c

    r4631115 r5ab626a  
    280280        libtrace->first_packets.count = 0;
    281281        libtrace->first_packets.packets = NULL;
    282         libtrace->dropped_packets = UINT64_MAX;
    283         libtrace->received_packets = UINT64_MAX;
     282        libtrace->stats = NULL;
    284283        libtrace->pread = NULL;
    285284        ZERO_USER_CONFIG(libtrace->config);
     
    397396        libtrace->perpkt_threads = NULL;
    398397        libtrace->tracetime = 0;
     398        libtrace->stats = NULL;
    399399        libtrace->pread = NULL;
    400400        ZERO_USER_CONFIG(libtrace->config);
     
    660660        if (libtrace->uridata)
    661661                free(libtrace->uridata);
     662
     663        if (libtrace->stats)
     664                free(libtrace->stats);
    662665       
    663666        /* Empty any packet memory */
     
    19511954                if ((ret = trace->format->get_received_packets(trace)) != UINT64_MAX)
    19521955                        return ret;
    1953         }
    1954         // Read this cached value taken before the trace was closed
    1955         return trace->received_packets;
     1956        } else if (trace->format->get_statistics) {
     1957                struct libtrace_stat_t stat;
     1958                stat.magic = LIBTRACE_STAT_MAGIC;
     1959                trace_get_statistics(trace, &stat);
     1960                if (stat.received_valid)
     1961                        return stat.received;
     1962        }
     1963
     1964        // Read the cached value taken before the trace was paused/closed
     1965        if(trace->stats && trace->stats->received_valid)
     1966                return trace->stats->received;
     1967        else
     1968                return UINT64_MAX;
    19561969}
    19571970
     
    19601973        assert(trace);
    19611974        int i = 0;
    1962         uint64_t ret = trace->filtered_packets;
     1975        uint64_t lib_filtered = trace->filtered_packets;
    19631976        for (i = 0; i < trace->perpkt_thread_count; i++) {
    1964                 ret += trace->perpkt_threads[i].filtered_packets;
     1977                lib_filtered += trace->perpkt_threads[i].filtered_packets;
    19651978        }
    19661979        if (trace->format->get_filtered_packets) {
    1967                 return trace->format->get_filtered_packets(trace)+
    1968                         ret;
    1969         }
    1970         return ret;
     1980                uint64_t trace_filtered = trace->format->get_filtered_packets(trace);
     1981                if (trace_filtered == UINT64_MAX)
     1982                        return UINT64_MAX;
     1983                else
     1984                        return trace_filtered + lib_filtered;
     1985        } else if (trace->format->get_statistics) {
     1986                struct libtrace_stat_t stat;
     1987                stat.magic = LIBTRACE_STAT_MAGIC;
     1988                trace_get_statistics(trace, &stat);
     1989                if (stat.filtered_valid)
     1990                        return lib_filtered + stat.filtered;
     1991                else
     1992                        return UINT64_MAX;
     1993        }
     1994
     1995        // Read the cached value taken before the trace was paused/closed
     1996        if(trace->stats && trace->stats->filtered_valid)
     1997                return trace->stats->filtered + lib_filtered;
     1998        else
     1999                return lib_filtered;
    19712000}
    19722001
     
    19792008                if ((ret = trace->format->get_dropped_packets(trace)) != UINT64_MAX)
    19802009                        return ret;
    1981         }
    1982         // Read this cached value taken before the trace was closed
    1983         return trace->dropped_packets;
     2010        } else if (trace->format->get_statistics) {
     2011                struct libtrace_stat_t stat;
     2012                stat.magic = LIBTRACE_STAT_MAGIC;
     2013                trace_get_statistics(trace, &stat);
     2014                if (stat.dropped_valid)
     2015                        return stat.dropped;
     2016        }
     2017
     2018        // Read the cached value taken before the trace was paused/closed
     2019        if(trace->stats && trace->stats->dropped_valid)
     2020                return trace->stats->dropped;
     2021        else
     2022                return UINT64_MAX;
    19842023}
    19852024
     
    19942033        return ret;
    19952034}
     2035
     2036libtrace_stat_t *trace_get_statistics(libtrace_t *trace, libtrace_stat_t *stat)
     2037{
     2038        uint64_t ret;
     2039        int i;
     2040        assert(trace);
     2041        if (stat == NULL) {
     2042                if (trace->stats == NULL)
     2043                        trace->stats = trace_create_statistics();
     2044                stat = trace->stats;
     2045        }
     2046        assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2047               "trace_create_statistics() to allocate statistics");
     2048        stat->reserved1 = 0;
     2049        stat->reserved2 = 0;
     2050#define X(x) stat->x ##_valid = 0;
     2051        LIBTRACE_STAT_FIELDS;
     2052#undef X
     2053        if (trace->state == STATE_PAUSED ||
     2054            trace->state == STATE_FINSHED ||
     2055            trace->state == STATE_JOINED) {
     2056                if (trace->stats && trace->stats != stat)
     2057                        *stat = *trace->stats;
     2058                return stat;
     2059        } else if (trace->format->get_statistics) {
     2060                trace->format->get_statistics(trace, stat);
     2061                ret = trace_get_accepted_packets(trace);
     2062                if (ret != UINT64_MAX) {
     2063                        stat->accepted_valid = 1;
     2064                        stat->accepted = ret;
     2065                }
     2066                /* Now add on any library filtered packets */
     2067                if (stat->filtered_valid) {
     2068                        stat->filtered += trace->filtered_packets;
     2069                        for (i = 0; i < trace->perpkt_thread_count; i++) {
     2070                                stat->filtered += trace->perpkt_threads[i].filtered_packets;
     2071                        }
     2072                }
     2073                return stat;
     2074        }
     2075        ret = trace_get_accepted_packets(trace);
     2076        if (ret != UINT64_MAX) {
     2077                stat->accepted_valid = 1;
     2078                stat->accepted = ret;
     2079        }
     2080        ret = trace_get_received_packets(trace);
     2081        if (ret != UINT64_MAX) {
     2082                stat->received_valid = 1;
     2083                stat->received = ret;
     2084        }
     2085        /* Fallback to the old way */
     2086        ret = trace_get_dropped_packets(trace);
     2087        if (ret != UINT64_MAX) {
     2088                stat->dropped_valid = 1;
     2089                stat->dropped = ret;
     2090        }
     2091        ret = trace_get_filtered_packets(trace);
     2092        if (ret != UINT64_MAX) {
     2093                stat->filtered_valid = 1;
     2094                stat->filtered = ret;
     2095        }
     2096        return stat;
     2097}
     2098
     2099void trace_get_thread_statistics(libtrace_t *trace, libtrace_thread_t *t,
     2100                                 libtrace_stat_t *stat)
     2101{
     2102        assert(trace && stat);
     2103        assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2104               "trace_create_statistics() to allocate statistics");
     2105        stat->reserved1 = 0;
     2106        stat->reserved2 = 0;
     2107#define X(x) stat->x ##_valid= 0;
     2108        LIBTRACE_STAT_FIELDS;
     2109#undef X
     2110        if (trace->format->get_thread_statistics) {
     2111                trace->format->get_thread_statistics(trace, t, stat);
     2112        }
     2113        if (t->accepted_packets != UINT64_MAX) {
     2114                stat->accepted_valid = 1;
     2115                stat->accepted = t->accepted_packets;
     2116        }
     2117        /* Now add on any library filtered packets */
     2118        if (stat->filtered_valid) {
     2119                stat->filtered += t->filtered_packets;
     2120        }
     2121        return;
     2122}
     2123
     2124libtrace_stat_t *trace_create_statistics(void) {
     2125        libtrace_stat_t *ret;
     2126        ret = malloc(sizeof(libtrace_stat_t));
     2127        if (ret) {
     2128                memset(ret, 0, sizeof(libtrace_stat_t));
     2129                ret->magic = LIBTRACE_STAT_MAGIC;
     2130        }
     2131        return ret;
     2132}
     2133
     2134void trace_subtract_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b,
     2135                         libtrace_stat_t *c) {
     2136        assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2137               "trace_create_statistics() to allocate statistics");
     2138        assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2139               "trace_create_statistics() to allocate statistics");
     2140        assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2141               "trace_create_statistics() to allocate statistics");
     2142
     2143#define X(x) \
     2144        if (a->x ##_valid && b->x ##_valid) { \
     2145                c->x ##_valid = 1; \
     2146                c->x = a->x - b->x; \
     2147        } else {\
     2148                c->x ##_valid = 0;\
     2149        }
     2150        LIBTRACE_STAT_FIELDS
     2151#undef X
     2152}
     2153
     2154void trace_add_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b,
     2155                         libtrace_stat_t *c) {
     2156        assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2157               "trace_create_statistics() to allocate statistics");
     2158        assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2159               "trace_create_statistics() to allocate statistics");
     2160        assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2161               "trace_create_statistics() to allocate statistics");
     2162
     2163#define X(x) \
     2164        if (a->x ##_valid&& b->x ##_valid) { \
     2165                c->x ##_valid = 1; \
     2166                c->x = a->x + b->x; \
     2167        } else {\
     2168                c->x ##_valid = 0;\
     2169        }
     2170        LIBTRACE_STAT_FIELDS
     2171#undef X
     2172}
     2173
     2174int trace_print_statistics(const libtrace_stat_t *s, FILE *f, const char *format) {
     2175        assert(s->magic == LIBTRACE_STAT_MAGIC && "Please use"
     2176               "trace_create_statistics() to allocate statistics");
     2177        if (format == NULL)
     2178                format = "%s: %"PRIu64"\n";
     2179#define xstr(s) str(s)
     2180#define str(s) #s
     2181#define X(x) \
     2182        if (s->x ##_valid) { \
     2183                if (fprintf(f, format, xstr(x), s->x) < 0) \
     2184                        return -1; \
     2185        }
     2186        LIBTRACE_STAT_FIELDS
     2187#undef X
     2188        return 0;
     2189}
     2190
    19962191
    19972192void trace_clear_cache(libtrace_packet_t *packet) {
  • lib/trace_parallel.c

    r8bcc925 r5ab626a  
    19061906
    19071907        /* Cache values before we pause */
    1908         libtrace->dropped_packets = trace_get_dropped_packets(libtrace);
    1909         libtrace->received_packets = trace_get_received_packets(libtrace);
    1910         uint64_t tmp_stats;
    1911         if (libtrace->format->get_filtered_packets) {
    1912                 if ((tmp_stats = libtrace->format->get_filtered_packets(libtrace)) != UINT64_MAX) {
    1913                         libtrace->filtered_packets += tmp_stats;
    1914                 }
    1915         }
     1908        if (libtrace->stats == NULL)
     1909                libtrace->stats = trace_create_statistics();
     1910        // Save the statistics against the trace
     1911        trace_get_statistics(libtrace, NULL);
    19161912        if (trace_supports_parallel(libtrace) && !trace_has_dedicated_hasher(libtrace) && libtrace->perpkt_thread_count > 1) {
    19171913                libtrace->started = false;
  • tools/tracestats/tracestats.c

    r3c54095 r5ab626a  
    8484        uint64_t count = 0;
    8585        uint64_t bytes = 0;
    86         uint64_t packets;
     86        libtrace_stat_t *stats;
    8787
    8888        fprintf(stderr,"%s:\n",uri);
     
    128128                ++count;
    129129                bytes+=wlen;
    130         }
     130        }
     131
     132        stats = trace_get_statistics(trace, NULL);
    131133
    132134        printf("%-30s\t%12s\t%12s\t%7s\n","filter","count","bytes","%");
     
    136138                filters[i].count=0;
    137139        }
    138         packets=trace_get_received_packets(trace);
    139         if (packets!=UINT64_MAX)
     140        if (stats->received_valid)
    140141                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    141                                 "Input packets", packets);
    142         packets=trace_get_filtered_packets(trace);
    143         if (packets!=UINT64_MAX)
     142                                "Input packets", stats->received);
     143        if (stats->filtered_valid)
    144144                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    145                                 "Filtered packets", packets);
    146         packets=trace_get_dropped_packets(trace);
    147         if (packets!=UINT64_MAX)
     145                                "Filtered packets", stats->filtered);
     146        if (stats->dropped_valid)
    148147                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    149                                 "Dropped packets",packets);
    150         packets=trace_get_accepted_packets(trace);
    151         if (packets!=UINT64_MAX)
     148                                "Dropped packets",stats->dropped);
     149        if (stats->accepted_valid)
    152150                fprintf(stderr,"%30s:\t%12" PRIu64 "\n",
    153                                 "Accepted Packets",packets);
     151                                "Accepted packets", stats->accepted);
     152        if (stats->errors_valid)
     153                fprintf(stderr,"%30s:\t%12" PRIu64 "\n",
     154                                "Erred packets", stats->errors);
    154155        printf("%30s:\t%12"PRIu64"\t%12" PRIu64 "\n","Total",count,bytes);
    155156        totcount+=count;
  • tools/tracestats/tracestats_parallel.c

    rd994324 r5ab626a  
    132132                        case MESSAGE_STOPPING:
    133133                                trace_publish_result(trace, t, 0, (libtrace_generic_types_t){.ptr = results}, RESULT_NORMAL); // Only ever using a single key 0
    134                                 fprintf(stderr, "Thread published resuslts WOWW\n");
     134                                //fprintf(stderr, "tracestats_parallel:\t Stopping thread - publishing results\n");
    135135                                break;
    136136                        case MESSAGE_STARTING:
     
    138138                                break;
    139139                        case MESSAGE_DO_PAUSE:
    140                                 fprintf(stderr, "GOT Asked to pause ahh\n");
     140                                assert(!"GOT Asked to pause!!!\n");
    141141                                break;
    142142                        case MESSAGE_PAUSING:
    143                                 fprintf(stderr, "Thread is pausing\n");
     143                                //fprintf(stderr, "tracestats_parallel:\t pausing thread\n");
    144144                                break;
    145145                        case MESSAGE_RESUMING:
    146                                 fprintf(stderr, "Thread has paused\n");
     146                                //fprintf(stderr, "tracestats_parallel:\t resuming thread\n");
    147147                                break;
    148148                }
     
    168168                free(res);
    169169        } else switch (mesg->code) {
     170                libtrace_stat_t *stats;
    170171                case MESSAGE_STOPPING:
     172                        stats = trace_get_statistics(trace, NULL);
    171173                        printf("%-30s\t%12s\t%12s\t%7s\n","filter","count","bytes","%");
    172174                        for(i=0;i<filter_count;++i) {
     
    175177                                filters[i].count=0;
    176178                        }
    177                         packets=trace_get_received_packets(trace);
    178                         if (packets!=UINT64_MAX)
     179                        if (stats->received_valid)
    179180                                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    180                                                 "Input packets", packets);
    181                         packets=trace_get_filtered_packets(trace);
    182                         if (packets!=UINT64_MAX)
     181                                                "Input packets", stats->received);
     182                        if (stats->filtered_valid)
    183183                                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    184                                                 "Filtered packets", packets);
    185                         packets=trace_get_dropped_packets(trace);
    186                         if (packets!=UINT64_MAX)
     184                                                "Filtered packets", stats->filtered);
     185                        if (stats->dropped_valid)
    187186                                fprintf(stderr,"%30s:\t%12" PRIu64"\n",
    188                                                 "Dropped packets",packets);
    189                         packets=trace_get_accepted_packets(trace);
    190                         if (packets!=UINT64_MAX)
     187                                                "Dropped packets",stats->dropped);
     188                        if (stats->accepted_valid)
    191189                                fprintf(stderr,"%30s:\t%12" PRIu64 "\n",
    192                                                 "Accepted Packets",packets);
     190                                                "Accepted packets", stats->accepted);
     191                        if (stats->errors_valid)
     192                                fprintf(stderr,"%30s:\t%12" PRIu64 "\n",
     193                                                "Erred packets", stats->errors);
    193194                        printf("%30s:\t%12"PRIu64"\t%12" PRIu64 "\n","Total",count,bytes);
    194195                        totcount+=count;
Note: See TracChangeset for help on using the changeset viewer.