source: test/test-format-parallel-reporter.c @ 62b3c4e

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

Update the reporter method to match with the per_pkt method.

We now treat a result as a type of message.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40#include <stdio.h>
41#include <stdlib.h>
42#include <assert.h>
43#include <string.h>
44#include <sys/types.h>
45#include <time.h>
46#include <string.h>
47#include <signal.h>
48#include <unistd.h>
49
50#include "dagformat.h"
51#include "libtrace.h"
52#include "data-struct/vector.h"
53#include "combiners.h"
54
55void iferr(libtrace_t *trace,const char *msg)
56{
57        libtrace_err_t err = trace_get_err(trace);
58        if (err.err_num==0)
59                return;
60        printf("Error: %s: %s\n", msg, err.problem);
61        exit(1);
62}
63
64const char *lookup_uri(const char *type) {
65        if (strchr(type,':'))
66                return type;
67        if (!strcmp(type,"erf"))
68                return "erf:traces/100_packets.erf";
69        if (!strcmp(type,"rawerf"))
70                return "rawerf:traces/100_packets.erf";
71        if (!strcmp(type,"pcap"))
72                return "pcap:traces/100_packets.pcap";
73        if (!strcmp(type,"wtf"))
74                return "wtf:traces/wed.wtf";
75        if (!strcmp(type,"rtclient"))
76                return "rtclient:chasm";
77        if (!strcmp(type,"pcapfile"))
78                return "pcapfile:traces/100_packets.pcap";
79        if (!strcmp(type,"pcapfilens"))
80                return "pcapfile:traces/100_packetsns.pcap";
81        if (!strcmp(type, "duck"))
82                return "duck:traces/100_packets.duck";
83        if (!strcmp(type, "legacyatm"))
84                return "legacyatm:traces/legacyatm.gz";
85        if (!strcmp(type, "legacypos"))
86                return "legacypos:traces/legacypos.gz";
87        if (!strcmp(type, "legacyeth"))
88                return "legacyeth:traces/legacyeth.gz";
89        if (!strcmp(type, "tsh"))
90                return "tsh:traces/10_packets.tsh.gz";
91        return type;
92}
93
94int globalcount = 0;
95
96static void reporter(libtrace_t *libtrace UNUSED, int mesg,
97                     libtrace_generic_t data,
98                     libtrace_thread_t *sender UNUSED) {
99        static uint64_t last = -1;
100        static int pktcount = 0;
101        libtrace_packet_t *packet;
102        switch (mesg) {
103        case MESSAGE_RESULT:
104                packet = libtrace_result_get_value(data.res).pkt;
105                assert(libtrace_result_get_key(data.res) == trace_packet_get_order(packet));
106                if(last == (uint64_t)-1) {
107                        last = libtrace_result_get_key(data.res);
108                } else {
109                assert (last < libtrace_result_get_key(data.res));
110                last = libtrace_result_get_key(data.res);
111                }
112                pktcount++;
113                trace_free_result_packet(libtrace, packet);
114                break;
115        case MESSAGE_STOPPING:
116                globalcount = pktcount;
117                break;
118        }
119}
120
121static void* per_packet(libtrace_t *trace, libtrace_thread_t *t,
122                        int mesg, libtrace_generic_t data,
123                        libtrace_thread_t *sender UNUSED) {
124        UNUSED static __thread int x = 0;
125
126        if (mesg == MESSAGE_PACKET) {
127                int a,*b,c=0;
128                // Do some work to even out the load on cores
129                b = &c;
130                for (a = 0; a < 10000000; a++) {
131                        c += a**b;
132                }
133                x = c;
134                trace_publish_result(trace, t, trace_packet_get_order(data.pkt), (libtrace_generic_t){.pkt=data.pkt}, RESULT_PACKET);
135        }
136        return NULL;
137}
138
139int main(int argc, char *argv[]) {
140        int error = 0;
141        int expected = 100;
142        const char *tracename;
143        libtrace_t *trace;
144
145        if (argc<2) {
146                fprintf(stderr,"usage: %s type\n",argv[0]);
147                return 1;
148        }
149
150        tracename = lookup_uri(argv[1]);
151
152        trace = trace_create(tracename);
153        iferr(trace,tracename);
154
155        if (strcmp(argv[1],"rtclient")==0) expected=101;
156
157        trace_set_combiner(trace, &combiner_ordered, (libtrace_generic_t){0});
158
159        trace_pstart(trace, NULL, per_packet, reporter);
160        iferr(trace,tracename);
161
162        /* Make sure traces survive a pause */
163        trace_ppause(trace);
164        iferr(trace,tracename);
165        trace_pstart(trace, NULL, NULL, NULL);
166        iferr(trace,tracename);
167
168        /* Wait for all threads to stop */
169        trace_join(trace);
170
171        if (error == 0) {
172                if (globalcount == expected) {
173                        printf("success: %d packets read\n",expected);
174                } else {
175                        printf("failure: %d packets expected, %d seen\n",expected,globalcount);
176                        error = 1;
177                }
178        } else {
179                iferr(trace,tracename);
180        }
181        trace_destroy(trace);
182        return error;
183}
Note: See TracBrowser for help on using the repository browser.