source: lib/combiner_sorted.c @ 89e2ff7

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 89e2ff7 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27
28#include "libtrace.h"
29#include "libtrace_int.h"
30#include "data-struct/vector.h"
31#include <assert.h>
32#include <stdlib.h>
33
34static int init_combiner(libtrace_t *t, libtrace_combine_t *c) {
35        int i = 0;
36        assert(trace_get_perpkt_threads(t) > 0);
37        libtrace_vector_t *queues;
38        c->queues = calloc(sizeof(libtrace_vector_t), trace_get_perpkt_threads(t));
39        queues = c->queues;
40        for (i = 0; i < trace_get_perpkt_threads(t); ++i) {
41                libtrace_vector_init(&queues[i], sizeof(libtrace_result_t));
42        }
43        return 0;
44}
45
46static void publish(libtrace_t *trace UNUSED, int t_id, libtrace_combine_t *c, libtrace_result_t *res) {
47        libtrace_vector_t *vec = &((libtrace_vector_t*)c->queues)[t_id];
48        libtrace_vector_push_back(vec, res);
49}
50
51static void read(libtrace_t *trace UNUSED, libtrace_combine_t *c UNUSED){
52        return;
53}
54
55static int compare_result(const void* p1, const void* p2)
56{
57        const libtrace_result_t * r1 = p1;
58        const libtrace_result_t * r2 = p2;
59        if (r1->key < r2->key)
60                return -1;
61        if (r1->key == r2->key)
62                return 0;
63        else
64                return 1;
65}
66
67static void pause(libtrace_t *trace, libtrace_combine_t *c) {
68        libtrace_vector_t *queues = c->queues;
69        int i;
70        for (i = 0; i < trace_get_perpkt_threads(trace); ++i) {
71                libtrace_vector_apply_function(&queues[i], (vector_data_fn) libtrace_make_result_safe);
72        }
73}
74
75static void read_final(libtrace_t *trace, libtrace_combine_t *c) {
76        libtrace_vector_t *queues = c->queues;
77        int i;
78        size_t a;
79        // Combine all results into queue 1
80        for (i = 1; i < trace_get_perpkt_threads(trace); ++i)
81        {
82                libtrace_vector_append(&queues[0],&queues[i]);
83        }
84        // Sort them
85        libtrace_vector_qsort(&queues[0], compare_result);
86
87        for (a = 0; a < libtrace_vector_get_size(&queues[0]); ++a) {
88                libtrace_result_t r;
89                libtrace_generic_t gt = {.res = &r};
90                ASSERT_RET (libtrace_vector_get(&queues[0], a, (void *) &r), == 1);
91                if (r.type == RESULT_TICK_INTERVAL ||
92                                r.type == RESULT_TICK_COUNT) {
93                        /* Ticks are essentially useless for this combiner? */
94                        continue;
95                }
96                send_message(trace, &trace->reporter_thread, MESSAGE_RESULT,
97                                gt, NULL);
98        }
99        libtrace_vector_empty(&queues[0]);
100}
101
102static void destroy(libtrace_t *trace, libtrace_combine_t *c) {
103        int i;
104        libtrace_vector_t *queues = c->queues;
105
106        for (i = 0; i < trace_get_perpkt_threads(trace); i++) {
107                assert(libtrace_vector_get_size(&queues[i]) == 0);
108                libtrace_vector_destroy(&queues[i]);
109        }
110        free(queues);
111        queues = NULL;
112}
113
114DLLEXPORT const libtrace_combine_t combiner_sorted = {
115    init_combiner,      /* initialise */
116        destroy,                /* destroy */
117        publish,                /* publish */
118    read,                       /* read */
119    read_final,                 /* read_final */
120    pause,                      /* pause */
121    NULL,                       /* queues */
122    0,                          /* last_count_tick */
123    0,                          /* last_ts_tick */
124    {0}                         /* opts */
125};
Note: See TracBrowser for help on using the repository browser.