Debian Codegraph @

examples/barectf-tracepoint/barectf-tracepoint.c

raw
1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2016 Philippe Proulx <[email protected]>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <time.h>
29
30 #if defined(WITH_LTTNG_UST)
31 #include "barectf-tracepoint-lttng-ust.h"
32 #elif defined(WITH_QEMU_ARM_UART)
33 #include "barectf-tracepoint-qemu-arm-uart.h"
34 #else
35 #include "barectf-tracepoint-linux-fs.h"
36 #endif
37
38 enum state_t {
39 NEW,
40 TERMINATED,
41 READY,
42 RUNNING,
43 WAITING,
44 };
45
46 static void trace_stuff(int argc, char *argv[])
47 {
48 int i;
49 const char *str;
50
51 /* record 40000 events */
52 for (i = 0; i < 5000; ++i) {
53 str = argv[i % argc];
54 tracepoint(barectf_tp, simple_uint32, i * 1500);
55 tracepoint(barectf_tp, simple_int16, -i * 2);
56 tracepoint(barectf_tp, simple_float, (float) i / 1.23);
57 tracepoint(barectf_tp, simple_string, str);
58 tracepoint(barectf_tp, simple_enum, RUNNING);
59 tracepoint(barectf_tp, a_few_fields, -1, 301, -3.14159,
60 str, NEW);
61 tracepoint(barectf_tp, bit_packed_integers, 1, -1, 3,
62 -2, 2, 7, 23, -55, 232);
63 tracepoint(barectf_tp, simple_enum, TERMINATED);
64 }
65 }
66
67 #define NUM_STRINGS 5
68
69 static char *strings[] = {
70 "orange",
71 "mandarine",
72 "lemon",
73 "lime",
74 "grapefruit",
75 };
76
77 int main(int argc, char *argv[])
78 {
79 init_tracing();
80
81 if (argc <= 1) {
82 /* use static strings if there's nothing interesting in argv */
83 argc = NUM_STRINGS;
84 argv = strings;
85 }
86
87 trace_stuff(argc, argv);
88 fini_tracing();
89
90 return 0;
91 }