Tracepoint and TRACEPOINT_EVENT API cleanup
[ust.git] / tests / register_test / register_test.c
CommitLineData
81614639
MD
1/*
2 * Copyright (C) 2010 Nils Carlson
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
a5f09c2c
NC
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <stdio.h>
21#include <unistd.h>
22#include <sys/mman.h>
23#include <stdarg.h>
24#include <sys/types.h>
25#include <sys/stat.h>
a5f09c2c
NC
26#include <fcntl.h>
27#include <signal.h>
28#include <pthread.h>
29
30#include <ust/marker.h>
31#include "usterr.h"
a5f09c2c 32
81614639
MD
33#define TRACEPOINT_CREATE_PROBES
34#include "tp.h"
a5f09c2c
NC
35
36struct hello_trace_struct {
37 char *message;
38};
39
40struct hello_trace_struct hello_struct = {
41 .message = "ehlo\n",
42};
43
44void tptest_probe(void *data, int anint)
45{
46 struct hello_trace_struct *hello;
47 char message[30];
81614639 48 hello = (struct hello_trace_struct *)data;
a5f09c2c
NC
49 //printf("this is the message: %s\n", hello->message);
50 snprintf(message, 30, "this is the %s\n", hello->message);
51}
52
53
54#define HELLO_LENGTH 100
55
81614639 56static void *register_thread_main(void *data)
a5f09c2c 57{
e2b46575 58 int i, j = 0;
a5f09c2c
NC
59 struct hello_trace_struct hello[HELLO_LENGTH];
60
81614639
MD
61 for (i = 0; i < HELLO_LENGTH; i++) {
62 hello[i].message = malloc(6 * sizeof(char));
63 hello[i].message[0] = 'a' + (i % 25);
a5f09c2c
NC
64 memcpy(&hello[i].message[1], "ello", 5);
65 }
66
81614639
MD
67 for (i = 0; i < 1000; i++) {
68 while (!__register_tracepoint(hello_tptest, tptest_probe,
69 &hello[j % HELLO_LENGTH])) {
a5f09c2c
NC
70 usleep(10);
71 j++;
72 }
73 printf("Registered all\n");
81614639
MD
74 while (!__unregister_tracepoint(hello_tptest, tptest_probe,
75 &hello[j % HELLO_LENGTH])) {
a5f09c2c
NC
76 usleep(10);
77 j++;
78 }
79 printf("Unregistered all\n");
80 }
fbae86d6 81 return NULL;
a5f09c2c
NC
82}
83
84
fbae86d6 85int main(int argc, char **argv)
a5f09c2c
NC
86{
87 pthread_t register_thread;
88 int i;
89
90 pthread_create(&register_thread, NULL, register_thread_main, NULL);
81614639 91 for(i = 0; i < 1000000; i++) {
cc7b66ba 92 tracepoint(hello_tptest, i);
a5f09c2c
NC
93 }
94
95 return 0;
96}
This page took 0.031317 seconds and 4 git commands to generate.