source: examples/parallel/trivial_skeleton.c @ 8decff7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 8decff7 was 5478d3d, checked in by Shane Alcock <salcock@…>, 6 years ago

Fix all outstanding warnings

Implemented trace_get_statistics for formats that were missing it, so
we no longer need to use the deprecated trace_get_dropped_packets anywhere
within libtrace.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/* Trivial parallel libtrace skeleton program
2 *
3 * This libtrace skeleton has the bare minimum required to write a useful
4 * libtrace program, including error handling.
5 *
6 *
7 */
8/* Note we include libtrace_parallel.h rather then libtrace.h */
9#include "libtrace_parallel.h"
10#include <stdio.h>
11#include <assert.h>
12
13
14/* Every time a packet becomes ready this function will be called. This
15 * function is run in parallel, so multiple packets can be processed at once.
16 *
17 * Parameters:
18 *   trace -- the input source that the packet was read from
19 *   t -- a pointer to the current processing thread
20 *   global -- a pointer to the global variable passed in to trace_start
21 *   tls -- a pointer to the thread local storage for this thread
22 *   packet -- the packet itself
23 */
24static libtrace_packet_t *process_packet(libtrace_t *trace UNUSED,
25                libtrace_thread_t *t UNUSED,
26                void *global UNUSED, void *tls UNUSED,
27                libtrace_packet_t *packet) {
28
29        /* Note that in this example, global and tls will both be NULL.
30         * global is NULL because we passed NULL as the second argument
31         * for trace_pstart. tls is NULL because we did not set a
32         * starting callback for our per packet threads.
33         */
34
35
36        assert(packet);
37
38        /* Your code goes here */
39
40        /* If we've finished with the packet, we should return it to
41         * libtrace so that it can be reused. */
42        return packet;
43}
44
45int main(int argc, char *argv[])
46{
47        libtrace_t *trace;
48        libtrace_callback_set_t *pktcbs;
49
50        if (argc<2) {
51                fprintf(stderr,"usage: %s libtraceuri\n",argv[0]);
52                return 1;
53        }
54
55        trace = trace_create(argv[1]);
56
57        if (trace_is_err(trace)) {
58                trace_perror(trace,"Opening trace file");
59                return 1;
60        }
61
62        /* Create a callback set for our per packet threads */
63        pktcbs = trace_create_callback_set();
64
65        /* Set the packet callback to be our packet processing function */
66        trace_set_packet_cb(pktcbs, process_packet);
67
68        /* We use a new version of trace_start(), trace_pstart()
69         * The reporter function argument is optional and can be NULL.
70         * We've also set the second argument to NULL because we have no
71         * global data that we want to be available to all threads. */
72        if (trace_pstart(trace, NULL, pktcbs, NULL)) {
73                trace_perror(trace,"Starting trace");
74                trace_destroy(trace);
75                return 1;
76        }
77
78        /* Wait for the trace to finish */
79        trace_join(trace);
80
81        if (trace_is_err(trace)) {
82                trace_perror(trace,"Reading packets");
83                trace_destroy(trace);
84                return 1;
85        }
86
87        trace_destroy(trace);
88        trace_destroy_callback_set(pktcbs);
89
90        return 0;
91}
Note: See TracBrowser for help on using the repository browser.