source: examples/tracemark/tracemark.c @ 010fafb

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 010fafb was c9caf07, checked in by Perry Lorier <perry@…>, 16 years ago

A benchmark program for testing trace processing speed

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2004 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$
28 *
29 */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <assert.h>
34#include <string.h>
35#include <sys/time.h>
36#include <sys/types.h>
37#include <time.h>
38
39#include <netinet/in.h>
40#include <netinet/in_systm.h>
41#include <netinet/tcp.h>
42#include <netinet/ip.h>
43#include <netinet/ip_icmp.h>
44#include <arpa/inet.h>
45#include <sys/socket.h>
46#include <getopt.h>
47#include <inttypes.h>
48
49#include "libtrace.h"
50
51struct libtrace_t *trace;
52
53
54uint64_t tot=0;
55/* Process a trace, counting packets that match filter(s) */
56void run_trace(char *uri) 
57{
58        struct libtrace_packet_t packet;
59        uint64_t count = 0;
60        uint64_t bytes = 0;
61        uint64_t nontcp_count = 0;
62        uint64_t nontcp_bytes = 0;
63
64
65
66        trace = trace_create(uri);
67
68        for (;;) {
69                int psize;
70                if ((psize = trace_read_packet(trace, &packet)) <1) {
71                        break;
72                }
73
74                if (trace_get_tcp(&packet)) {
75                        ++nontcp_count;
76                        nontcp_bytes+=trace_get_wire_length(&packet);
77                }
78
79                ++count;
80                bytes+=trace_get_wire_length(&packet);
81                ++tot;
82        }
83
84
85        trace_destroy(trace);
86}
87
88int main(int argc, char *argv[]) {
89
90        int i;
91        struct timeval start,end;
92        struct timeval interval;
93
94        gettimeofday(&start,NULL);
95        for(i=optind;i<argc;++i) {
96                run_trace(argv[i]);
97        }
98        gettimeofday(&end,NULL);
99        interval.tv_sec = end.tv_sec - start.tv_sec;                             
100        interval.tv_usec = end.tv_usec - start.tv_usec;     
101        if (interval.tv_usec < 0) {                         
102                --interval.tv_sec;                         
103                interval.tv_usec += 1000000;     
104        }                                                 
105
106        printf("Tracemarks: %.02f\n",((double)tot)/(interval.tv_sec+interval.tv_usec/100000));
107        return 0;
108}
Note: See TracBrowser for help on using the repository browser.