source: lib/combiner_sorted.c @ d994324

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d994324 was d994324, checked in by Richard Sanger <rsangerarj@…>, 6 years ago

Remove anything to do with the combiner from set configuration and removes any options/storage related to these such as the next expected packet.

Instead this is done using trace_set_combiner now, and the for the built-in combiners.h header. This is a lot more flexible and allows the users to specify there own combiner, and any number of options for it.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include "libtrace.h"
2#include "libtrace_int.h"
3#include "data-struct/vector.h"
4#include <assert.h>
5#include <stdlib.h>
6
7static int init_combiner(libtrace_t *t, libtrace_combine_t *c) {
8        int i = 0;
9        assert(libtrace_get_perpkt_count(t) > 0);
10        libtrace_vector_t *queues;
11        c->queues = calloc(sizeof(libtrace_vector_t), libtrace_get_perpkt_count(t));
12        queues = c->queues;
13        for (i = 0; i < libtrace_get_perpkt_count(t); ++i) {
14                libtrace_vector_init(&queues[i], sizeof(libtrace_result_t));
15        }
16        return 0;
17}
18
19static void publish(libtrace_t *trace UNUSED, int t_id, libtrace_combine_t *c, libtrace_result_t *res) {
20        libtrace_vector_t *vec = &((libtrace_vector_t*)c->queues)[t_id];
21        libtrace_vector_push_back(vec, res);
22}
23
24static void read(libtrace_t *trace UNUSED, libtrace_combine_t *c UNUSED){
25        return;
26}
27
28static int compare_result(const void* p1, const void* p2)
29{
30        if (libtrace_result_get_key((libtrace_result_t *) p1) < libtrace_result_get_key((libtrace_result_t *) p2))
31                return -1;
32        if (libtrace_result_get_key((libtrace_result_t *) p1) == libtrace_result_get_key((libtrace_result_t *) p2))
33                return 0;
34        else
35                return 1;
36}
37
38static void pause(libtrace_t *trace, libtrace_combine_t *c) {
39        libtrace_vector_t *queues = c->queues;
40        int i;
41        for (i = 0; i < libtrace_get_perpkt_count(trace); ++i) {
42                libtrace_vector_apply_function(&queues[i], (vector_data_fn) libtrace_make_result_safe);
43        }
44}
45
46static void read_final(libtrace_t *trace, libtrace_combine_t *c) {
47        libtrace_vector_t *queues = c->queues;
48        int i;
49        size_t a;
50        // Combine all results into queue 1
51        for (i = 1; i < libtrace_get_perpkt_count(trace); ++i)
52        {
53                libtrace_vector_append(&queues[0],&queues[i]);
54        }
55        // Sort them
56        libtrace_vector_qsort(&queues[0], compare_result);
57
58        for (a = 0; a < libtrace_vector_get_size(&queues[0]); ++a) {
59                libtrace_result_t r;
60                ASSERT_RET (libtrace_vector_get(&queues[0], a,  (void *) &r), == 1);
61                trace->reporter(trace, &r, NULL);
62        }
63        libtrace_vector_empty(&queues[0]);
64}
65
66static void destroy(libtrace_t *trace, libtrace_combine_t *c) {
67        int i;
68        libtrace_vector_t *queues = c->queues;
69
70        for (i = 0; i < libtrace_get_perpkt_count(trace); i++) {
71                assert(libtrace_vector_get_size(&queues[i]) == 0);
72                libtrace_vector_destroy(&queues[i]);
73        }
74        free(queues);
75        queues = NULL;
76}
77
78DLLEXPORT const libtrace_combine_t combiner_sorted = {
79    init_combiner,      /* initialise */
80        destroy,                /* destroy */
81        publish,                /* publish */
82    read,                       /* read */
83    read_final,                 /* read_final */
84    pause,                      /* pause */
85    NULL,                       /* queues */
86    {0}                         /* opts */
87};
Note: See TracBrowser for help on using the repository browser.