b8b00688 |
1 | |
2 | /* LTTng user-space tracing code |
3 | * |
4 | * Copyright 2006 Mathieu Desnoyers |
5 | * |
6 | */ |
7 | |
8 | |
9 | #include <sys/types.h> |
10 | #include <sys/wait.h> |
11 | #include <unistd.h> |
92f441a7 |
12 | #include <stdlib.h> |
b8b00688 |
13 | #include <stdio.h> |
14 | #include <signal.h> |
15 | #include <syscall.h> |
92f441a7 |
16 | #include <features.h> |
17 | #include <pthread.h> |
18 | #include <malloc.h> |
19 | #include <string.h> |
b8b00688 |
20 | |
92f441a7 |
21 | #include <asm/atomic.h> |
b8b00688 |
22 | #include "lttng_usertrace.h" |
23 | |
92f441a7 |
24 | #define MAX_TRACES 16 |
25 | |
26 | struct ltt_buf { |
27 | void *start; |
28 | atomic_t offset; |
29 | atomic_t reserve_count; |
30 | atomic_t commit_count; |
31 | |
32 | atomic_t events_lost; |
33 | }; |
34 | |
35 | struct lttng_trace_info { |
36 | struct lttng_trace_info *next; |
37 | int active:1; |
38 | struct { |
39 | struct ltt_buf facilities; |
40 | struct ltt_buf cpu; |
41 | } channel; |
42 | }; |
43 | |
44 | |
45 | /* TLS for the trace info */ |
46 | static __thread struct lttng_trace_info *test; |
47 | static __thread struct lttng_trace_info lttng_trace_info[MAX_TRACES]; |
48 | |
49 | |
b8b00688 |
50 | /* signal handler */ |
51 | void __lttng_sig_trace_handler(int signo) |
52 | { |
92f441a7 |
53 | int ret; |
54 | sigset_t set, oldset; |
55 | |
b8b00688 |
56 | printf("LTTng Sig handler : pid : %lu\n", getpid()); |
92f441a7 |
57 | |
58 | /* Disable signals */ |
59 | ret = sigfillset(&set); |
60 | if(ret) { |
61 | printf("Error in sigfillset\n"); |
62 | exit(1); |
63 | } |
64 | |
65 | ret = sigprocmask(SIG_BLOCK, &set, &oldset); |
66 | if(ret) { |
67 | printf("Error in sigprocmask\n"); |
68 | exit(1); |
69 | } |
70 | |
71 | /* Get all the new traces */ |
72 | #if 0 |
73 | do { |
74 | /* FIXME : allocate the trace structure somewhere : thread private */ |
75 | ret = ltt_update(addr, &active, &filter); |
76 | |
77 | if(ret) { |
78 | printf("Error in ltt_update system call\n"); |
79 | exit(1); |
80 | } |
81 | } while(addr); |
82 | |
83 | #endif //0 |
84 | /* Enable signals */ |
85 | ret = sigprocmask(SIG_SETMASK, &oldset, NULL); |
86 | if(ret) { |
87 | printf("Error in sigprocmask\n"); |
88 | exit(1); |
89 | } |
90 | |
b8b00688 |
91 | } |
92 | |
93 | |
92f441a7 |
94 | void __lttng_init_trace_info(void) |
95 | { |
96 | memset(<tng_trace_info, 0, MAX_TRACES*sizeof(struct lttng_trace_info)); |
97 | } |
b8b00688 |
98 | |
99 | void __attribute__((constructor)) __lttng_user_init(void) |
100 | { |
101 | static struct sigaction act; |
102 | int err; |
103 | |
104 | printf("LTTng user init\n"); |
105 | |
92f441a7 |
106 | /* Init trace info */ |
107 | __lttng_init_trace_info(); |
108 | |
b8b00688 |
109 | /* Activate the signal */ |
110 | act.sa_handler = __lttng_sig_trace_handler; |
111 | err = sigemptyset(&(act.sa_mask)); |
112 | if(err) perror("Error with sigemptyset"); |
113 | err = sigaddset(&(act.sa_mask), SIGRTMIN+3); |
114 | if(err) perror("Error with sigaddset"); |
115 | err = sigaction(SIGRTMIN+3, &act, NULL); |
116 | if(err) perror("Error with sigaction"); |
117 | |
92f441a7 |
118 | /* TEST */ |
119 | err = ltt_switch((unsigned long)NULL); |
120 | if(err) { |
121 | printf("Error in ltt_switch system call\n"); |
122 | exit(1); |
123 | } |
124 | |
b8b00688 |
125 | /* Make the first ltt_update system call */ |
126 | err = ltt_update(1, NULL, NULL); |
127 | if(err) { |
128 | printf("Error in ltt_update system call\n"); |
129 | exit(1); |
130 | } |
92f441a7 |
131 | |
132 | /* Make some ltt_switch syscalls */ |
133 | err = ltt_switch((unsigned long)NULL); |
134 | if(err) { |
135 | printf("Error in ltt_switch system call\n"); |
136 | exit(1); |
137 | } |
138 | |
139 | |
140 | |
b8b00688 |
141 | } |