Skip to content

Parallel Libtrace HOWTO: Start Reporter Callback

Shane Alcock edited this page Sep 21, 2015 · 4 revisions

The definition of a start callback for a reporter thread is no different to the start callback for a processing thread (in fact, this is true for all callbacks -- as far as libtrace is concerned, a start callback is a start callback regardless of what thread it is being applied to).

In our case, we need our start callback to create and initialise some space to store our tallies of packets and bytes that are being published by each processing thread. I've also added a field for storing the key of the last result we have seen; this is something that we are going to need later on.

/* Structure for storing our tallies. */
struct udptally {
    uint64_t lastkey;
    uint64_t packets;
    uint64_t payload;
}

/* Starting callback for the reporter thread */
static void *start_reporter(libtrace_t *trace, libtrace_thread_t *thread,
        void *global) {

    /* This is really no different to the processing start callback, 
     * just using a different structure.
     */
    struct udpresult *tally;

    tally =  (struct udpresult *)malloc(sizeof(struct udpresult));
    tally->packets = 0;
    tally->payload = 0;
    tally->lastkey = 0;

    return tally;
}

Now that we've got somewhere to store our tallies, we can write a callback to handle published results.

Clone this wiki locally