Commit | Line | Data |
---|---|---|
a5f09c2c NC |
1 | /* Copyright (C) 2010 Nils Carlson |
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 | #include <stdio.h> | |
19 | #include <unistd.h> | |
20 | #include <sys/mman.h> | |
21 | #include <stdarg.h> | |
22 | #include <sys/types.h> | |
23 | #include <sys/stat.h> | |
24 | #include <sys/timerfd.h> | |
25 | #include <fcntl.h> | |
26 | #include <signal.h> | |
27 | #include <pthread.h> | |
28 | ||
29 | #include <ust/marker.h> | |
30 | #include "usterr.h" | |
31 | #include "tracer.h" | |
32 | #include "tp.h" | |
33 | ||
34 | DEFINE_TRACE(hello_tptest); | |
35 | ||
36 | ||
37 | struct hello_trace_struct { | |
38 | char *message; | |
39 | }; | |
40 | ||
41 | struct hello_trace_struct hello_struct = { | |
42 | .message = "ehlo\n", | |
43 | }; | |
44 | ||
45 | void tptest_probe(void *data, int anint) | |
46 | { | |
47 | struct hello_trace_struct *hello; | |
48 | char message[30]; | |
49 | hello=(struct hello_trace_struct *)data; | |
50 | //printf("this is the message: %s\n", hello->message); | |
51 | snprintf(message, 30, "this is the %s\n", hello->message); | |
52 | } | |
53 | ||
54 | ||
55 | #define HELLO_LENGTH 100 | |
56 | ||
57 | static void * register_thread_main(void *data) | |
58 | { | |
59 | int ret, i, j = 0; | |
60 | ||
61 | struct hello_trace_struct hello[HELLO_LENGTH]; | |
62 | ||
63 | for (i=0; i<HELLO_LENGTH; i++) { | |
64 | hello[i].message = malloc(6*sizeof(char)); | |
65 | hello[i].message[0] = 'a'+i%25; | |
66 | memcpy(&hello[i].message[1], "ello", 5); | |
67 | } | |
68 | ||
69 | for (i=0; i<1000; i++) { | |
70 | while (!register_trace_hello_tptest(tptest_probe, | |
71 | &hello[j%HELLO_LENGTH])) { | |
72 | usleep(10); | |
73 | j++; | |
74 | } | |
75 | printf("Registered all\n"); | |
76 | while (!unregister_trace_hello_tptest(tptest_probe, | |
77 | &hello[j%HELLO_LENGTH])) { | |
78 | usleep(10); | |
79 | j++; | |
80 | } | |
81 | printf("Unregistered all\n"); | |
82 | } | |
83 | } | |
84 | ||
85 | ||
86 | int main() | |
87 | { | |
88 | pthread_t register_thread; | |
89 | int i; | |
90 | ||
91 | pthread_create(®ister_thread, NULL, register_thread_main, NULL); | |
92 | for(i=0; i<1000000; i++) { | |
93 | trace_hello_tptest(i); | |
94 | } | |
95 | ||
96 | return 0; | |
97 | } |