source: test/test-format-parallel.c @ 6a6e6a8

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

More documentation, including some renaming and modifications to behaviour

  • Removes accessor functions for libtrace_result_t, instead directly access the structure
  • Documentation for most functions
  • Split tick into interval and count messages for the two modes of operation
  • Normalise interval and packet order to use the erf timestamp format
  • Rename trace_send_message_to_XXX to trace trace_message_XXX
  • Property mode set to 100644
File size: 6.5 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_parallel.h"
52#include "data-struct/vector.h"
53
54void iferr(libtrace_t *trace,const char *msg)
55{
56        libtrace_err_t err = trace_get_err(trace);
57        if (err.err_num==0)
58                return;
59        printf("Error: %s: %s\n", msg, err.problem);
60        exit(1);
61}
62
63const char *lookup_uri(const char *type) {
64        if (strchr(type,':'))
65                return type;
66        if (!strcmp(type,"erf"))
67                return "erf:traces/100_packets.erf";
68        if (!strcmp(type,"rawerf"))
69                return "rawerf:traces/100_packets.erf";
70        if (!strcmp(type,"pcap"))
71                return "pcap:traces/100_packets.pcap";
72        if (!strcmp(type,"wtf"))
73                return "wtf:traces/wed.wtf";
74        if (!strcmp(type,"rtclient"))
75                return "rtclient:chasm";
76        if (!strcmp(type,"pcapfile"))
77                return "pcapfile:traces/100_packets.pcap";
78        if (!strcmp(type,"pcapfilens"))
79                return "pcapfile:traces/100_packetsns.pcap";
80        if (!strcmp(type, "duck"))
81                return "duck:traces/100_packets.duck";
82        if (!strcmp(type, "legacyatm"))
83                return "legacyatm:traces/legacyatm.gz";
84        if (!strcmp(type, "legacypos"))
85                return "legacypos:traces/legacypos.gz";
86        if (!strcmp(type, "legacyeth"))
87                return "legacyeth:traces/legacyeth.gz";
88        if (!strcmp(type, "tsh"))
89                return "tsh:traces/10_packets.tsh.gz";
90        return type;
91}
92
93struct TLS {
94        bool seen_start_message;
95        bool seen_stop_message;
96        bool seen_resuming_message;
97        bool seen_pausing_message;
98        int count;
99};
100
101static int totalpkts = 0;
102static void report_result(libtrace_t *trace UNUSED, int mesg,
103                          libtrace_generic_t data,
104                          libtrace_thread_t *sender UNUSED) {
105        static int totalthreads = 0;
106        switch (mesg) {
107        case MESSAGE_RESULT:
108                assert(data.res->key == 0);
109                printf("%d,", data.res->value.sint);
110                totalthreads++;
111                totalpkts += data.res->value.sint;
112                break;
113        case MESSAGE_STARTING:
114                printf("\tLooks like %d threads are being used!\n\tcounts(", libtrace_get_perpkt_count(trace));
115                break;
116        case MESSAGE_STOPPING:
117                printf(")\n");
118                assert(totalthreads == libtrace_get_perpkt_count(trace));
119                break;
120        }
121}
122
123int x;
124static void* per_packet(libtrace_t *trace, libtrace_thread_t *t,
125                        int mesg, libtrace_generic_t data,
126                        libtrace_thread_t *sender UNUSED) {
127        struct TLS *tls;
128        void* ret;
129        int a,*b,c=0;
130        // Test internal TLS against __thread
131        static __thread bool seen_start_message = false;
132        static __thread bool seen_stop_message = false;
133        static __thread bool seen_resuming_message = false;
134        static __thread bool seen_pausing_message = false;
135        static __thread int count = 0;
136        tls = trace_get_tls(t);
137
138        switch (mesg) {
139        case MESSAGE_PACKET:
140                assert(tls != NULL);
141                assert(!seen_stop_message);
142                count++;
143                tls->count++;
144                if (count>100) {
145                        fprintf(stderr, "Too many packets someone should stop me!!\n");
146                        kill(getpid(), SIGTERM);
147                }
148                // Do some work to even out the load on cores
149                b = &c;
150                for (a = 0; a < 10000000; a++) {
151                        c += a**b;
152                }
153                x = c;
154                return data.pkt;
155        case MESSAGE_STARTING:
156                assert(!seen_start_message || seen_resuming_message);
157                assert(tls == NULL);
158                tls = calloc(sizeof(struct TLS), 1);
159                ret = trace_set_tls(t, tls);
160                assert(ret == NULL);
161                seen_start_message = true;
162                tls->seen_start_message = true;
163                break;
164        case MESSAGE_STOPPING:
165                assert(seen_start_message);
166                assert(tls != NULL);
167                assert(tls->seen_start_message);
168                assert(tls->count == count);
169                seen_stop_message = true;
170                tls->seen_stop_message = true;
171                free(tls);
172                trace_set_tls(t, NULL);
173
174                // All threads publish to verify the thread count
175                trace_publish_result(trace, t, (uint64_t) 0, (libtrace_generic_t){.sint = count}, RESULT_USER);
176                trace_post_reporter(trace);
177                break;
178        case MESSAGE_TICK_INTERVAL:
179        case MESSAGE_TICK_COUNT:
180                assert(seen_start_message);
181                fprintf(stderr, "Not expecting a tick packet\n");
182                kill(getpid(), SIGTERM);
183                break;
184        case MESSAGE_PAUSING:
185                assert(seen_start_message);
186                seen_pausing_message = true;
187                tls->seen_pausing_message = true;
188                break;
189        case MESSAGE_RESUMING:
190                assert(tls->seen_pausing_message  || tls->seen_start_message );
191                seen_resuming_message = true;
192                tls->seen_resuming_message = true;
193                break;
194        }
195        return NULL;
196}
197
198int main(int argc, char *argv[]) {
199        int error = 0;
200        int expected = 100;
201        const char *tracename;
202        libtrace_t *trace;
203
204        if (argc<2) {
205                fprintf(stderr,"usage: %s type\n",argv[0]);
206                return 1;
207        }
208
209        tracename = lookup_uri(argv[1]);
210
211        trace = trace_create(tracename);
212        iferr(trace,tracename);
213
214        if (strcmp(argv[1],"rtclient")==0) expected=101;
215
216        trace_pstart(trace, NULL, per_packet, report_result);
217        iferr(trace,tracename);
218
219        /* Make sure traces survive a pause */
220        trace_ppause(trace);
221        iferr(trace,tracename);
222        trace_pstart(trace, NULL, NULL, NULL);
223        iferr(trace,tracename);
224
225        /* Wait for all threads to stop */
226        trace_join(trace);
227
228        /* Now check we have all received all the packets */
229        if (error == 0) {
230                if (totalpkts == expected) {
231                        printf("success: %d packets read\n",expected);
232                } else {
233                        printf("failure: %d packets expected, %d seen\n",expected,totalpkts);
234                        error = 1;
235                }
236        } else {
237                iferr(trace,tracename);
238        }
239
240    trace_destroy(trace);
241    return error;
242}
Note: See TracBrowser for help on using the repository browser.