Tracepoints: add wrapper tracepoint() macro
[lttng-ust.git] / tests / tracepoint / tracepoint_test.c
CommitLineData
cd5de8df
DG
1/* Copyright (C) 2010 David Goulet <david.goulet@polymtl.ca>
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18/*
686debc3 19 * This test is aimed at testing tracepoint *with* ust_marker :
cd5de8df
DG
20 *
21 * 1) tracepoint named : "ust_event"
22 * -) Probe 1 registered and recording the value 13 (x5)
23 * -) Probe 2 registered and recording the value 42 (x5)
24 * -) Probe 3 registered and recording the payload of the struct message
25 * but using a *different* tracepoint (event_msg)
26 *
27 * 2) tracepoint named : "ust_event2"
28 * -) Probe 4 registered and recording the value 42 (x100)
29 */
30
31#include <stdio.h>
32#include <ust/marker.h>
33#include "tracepoint_test.h"
34
35DEFINE_TRACE(ust_event);
36DEFINE_TRACE(ust_event2);
37
38static struct message msg_probe3 = {
39 .payload = "probe3",
40};
41
42/*
43 * Probe 4 --> ust_event2
44 * Will record 100 times the value 42
45 */
46void tp_probe4(void *data, unsigned int p4)
47{
48 int i;
49 for (i = 0; i < 100; i++) {
686debc3 50 ust_marker_tp(event2, ust_event2, tp_probe4, "probe4 %u", p4);
cd5de8df
DG
51 }
52}
53
54/*
55 * Probe 3 --> ust_event *and* event_msg (from inside)
56 * Will record the payload of msg_prob3 struct
57 * from the data pointer of the probe
58 */
59void tp_probe3(void *data, unsigned int p3)
60{
61 struct message *msg;
62 msg = (struct message*) data;
686debc3 63 ust_marker_tp(event_msg, ust_event_msg,
cd5de8df
DG
64 tp_probe3, "probe %s", msg->payload);
65}
66
67/*
68 * Probe 2 --> ust_event
69 * Will record 5 times the number 13
70 */
71void tp_probe2(void *data, unsigned int p2)
72{
73 int i;
74 for (i = 0; i < 5; i++) {
686debc3 75 ust_marker_tp(event, ust_event, tp_probe2, "probe %u", 13);
cd5de8df
DG
76 }
77}
78
79/*
80 * Probe 1 --> ust_event
81 * Will record 5 times the unsigned int v = 42
82 */
83void tp_probe(void *data, unsigned int p1)
84{
85 int i;
86 for (i = 0; i < 5; i++) {
686debc3 87 ust_marker_tp(event, ust_event, tp_probe, "probe %u", p1);
cd5de8df
DG
88 }
89}
90
91static void __attribute__((constructor)) init()
92{
cc7b66ba
MD
93 register_tracepoint(ust_event, tp_probe, NULL);
94 register_tracepoint(ust_event, tp_probe2, NULL);
95 register_tracepoint(ust_event, tp_probe3, &msg_probe3);
96 register_tracepoint(ust_event2, tp_probe4, NULL);
cd5de8df
DG
97}
98
99int main(int argc, char **argv) {
100 unsigned int v = 42;
101 /* Tracepoint 1 : ust_event */
cc7b66ba 102 tracepoint(ust_event, v);
cd5de8df 103 /* Tracepoint 2 : ust_event2 */
cc7b66ba 104 tracepoint(ust_event2, v);
cd5de8df
DG
105
106 return 0;
107}
This page took 0.029559 seconds and 4 git commands to generate.