Code base to fix the print errors in UST (v4)
[lttng-ust.git] / include / ust / ustconsumer.h
CommitLineData
d159ac37 1/*
9dc7b7ff 2 * libustconsumer header file
d159ac37
AH
3 *
4 * Copyright 2005-2010 -
5 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 * Copyright 2010-
7 * Oumarou Dicko <oumarou.dicko@polymtl.ca>
8 * Michael Sills-Lavoie <michael.sills-lavoie@polymtl.ca>
9 * Alexis Halle <alexis.halle@polymtl.ca>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
9dc7b7ff
NC
26#ifndef _USTCONSUMER_H
27#define _USTCONSUMER_H
d159ac37
AH
28
29#include <pthread.h>
30#include <dirent.h>
f3f8cc91 31#include <ust/kcompat/kcompat.h>
4723ca09 32#include <urcu/list.h>
d159ac37 33
9dc7b7ff 34#define USTCONSUMER_DEFAULT_TRACE_PATH "/tmp/usttrace"
d159ac37 35
4723ca09 36struct ustcomm_sock;
f3f8cc91 37
d159ac37 38struct buffer_info {
72098143 39 char *name;
d89b8191 40 char *trace;
72098143
NC
41 char *channel;
42 int channel_cpu;
43
d159ac37 44 pid_t pid;
4723ca09
NC
45 int app_sock;
46 /* The pipe file descriptor */
47 int pipe_fd;
d159ac37
AH
48
49 int shmid;
50 int bufstruct_shmid;
51
52 /* the buffer memory */
53 void *mem;
54 /* buffer size */
55 int memlen;
56 /* number of subbuffers in buffer */
57 int n_subbufs;
58 /* size of each subbuffer */
59 int subbuf_size;
cd6b7243
DG
60 /* subbuf size count order */
61 int subbuf_size_order;
62 /* alloc size of all subbuf */
63 int alloc_size;
d159ac37
AH
64
65 /* the buffer information struct */
66 void *bufstruct_mem;
67
68 long consumed_old;
69
70 s64 pidunique;
71
72 void *user_data;
73};
74
9dc7b7ff 75struct ustconsumer_callbacks;
d159ac37
AH
76
77/**
9dc7b7ff 78 * struct ustconsumer_instance - Contains the data associated with a trace instance.
d159ac37
AH
79 * The lib user can read but MUST NOT change any attributes but callbacks.
80 * @callbacks: Contains the necessary callbacks for a tracing session.
81 */
9dc7b7ff
NC
82struct ustconsumer_instance {
83 struct ustconsumer_callbacks *callbacks;
d159ac37
AH
84 int quit_program;
85 int is_init;
0222e121 86 struct cds_list_head connections;
4723ca09
NC
87 int epoll_fd;
88 struct ustcomm_sock *listen_sock;
d159ac37
AH
89 char *sock_path;
90 pthread_mutex_t mutex;
91 int active_buffers;
92};
93
94/**
9dc7b7ff 95* struct ustconsumer_callbacks - Contains the necessary callbacks for a tracing
d159ac37
AH
96* session. The user can set the unnecessary functions to NULL if he does not
97* need them.
98*/
9dc7b7ff 99struct ustconsumer_callbacks {
d159ac37
AH
100 /**
101 * on_open_buffer - Is called after a buffer is attached to process memory
102 *
103 * @data: pointer to the callbacks structure that has been passed to the
104 * library.
105 * @buf: structure that contains the data associated with the buffer
106 *
107 * Returns 0 if the callback succeeds else not 0.
108 *
109 * It has to be thread safe, because it is called by many threads.
110 */
9dc7b7ff 111 int (*on_open_buffer)(struct ustconsumer_callbacks *data,
d159ac37
AH
112 struct buffer_info *buf);
113
114 /**
115 * on_close_buffer - Is called after a buffer is detached from process memory
116 *
117 * @data: pointer to the callbacks structure that has been passed to the
118 * library.
119 * @buf: structure that contains the data associated with the buffer
120 *
121 * Returns 0 if the callback succeeds else not 0.
122 *
123 * It has to be thread safe, because it is called by many threads.
124 */
9dc7b7ff 125 int (*on_close_buffer)(struct ustconsumer_callbacks *data,
d159ac37
AH
126 struct buffer_info *buf);
127
128 /**
129 * on_read_subbuffer - Is called after a subbuffer is a reserved.
130 *
131 * @data: pointer to the callbacks structure that has been passed to the
132 * library.
133 * @buf: structure that contains the data associated with the buffer
134 *
135 * Returns 0 if the callback succeeds else not 0.
136 *
137 * It has to be thread safe, because it is called by many threads.
138 */
9dc7b7ff 139 int (*on_read_subbuffer)(struct ustconsumer_callbacks *data,
d159ac37
AH
140 struct buffer_info *buf);
141
142 /**
143 * on_read_partial_subbuffer - Is called when an incomplete subbuffer
144 * is being salvaged from an app crash
145 *
146 * @data: pointer to the callbacks structure that has been passed to the
147 * library.
148 * @buf: structure that contains the data associated with the buffer
149 * @subbuf_index: index of the subbuffer to read in the buffer
150 * @valid_length: number of bytes considered safe to read
151 *
152 * Returns 0 if the callback succeeds else not 0.
153 *
154 * It has to be thread safe, because it is called by many threads.
155 */
9dc7b7ff 156 int (*on_read_partial_subbuffer)(struct ustconsumer_callbacks *data,
d159ac37
AH
157 struct buffer_info *buf,
158 long subbuf_index,
159 unsigned long valid_length);
160
161 /**
162 * on_put_error - Is called when a put error has occured and the last
163 * subbuffer read is no longer safe to keep
164 *
165 * @data: pointer to the callbacks structure that has been passed to the
166 * library.
167 * @buf: structure that contains the data associated with the buffer
168 *
169 * Returns 0 if the callback succeeds else not 0.
170 *
171 * It has to be thread safe, because it is called by many threads.
172 */
9dc7b7ff 173 int (*on_put_error)(struct ustconsumer_callbacks *data,
d159ac37
AH
174 struct buffer_info *buf);
175
176 /**
177 * on_new_thread - Is called when a new thread is created
178 *
179 * @data: pointer to the callbacks structure that has been passed to the
180 * library.
181 *
182 * Returns 0 if the callback succeeds else not 0.
183 *
184 * It has to be thread safe, because it is called by many threads.
185 */
9dc7b7ff 186 int (*on_new_thread)(struct ustconsumer_callbacks *data);
d159ac37
AH
187
188 /**
189 * on_close_thread - Is called just before a thread is destroyed
190 *
191 * @data: pointer to the callbacks structure that has been passed to the
192 * library.
193 *
194 * Returns 0 if the callback succeeds else not 0.
195 *
196 * It has to be thread safe, because it is called by many threads.
197 */
9dc7b7ff 198 int (*on_close_thread)(struct ustconsumer_callbacks *data);
d159ac37
AH
199
200 /**
201 * on_trace_end - Is called at the very end of the tracing session. At
202 * this time, everything has been closed and the threads have
203 * been destroyed.
204 *
205 * @instance: pointer to the instance structure that has been passed to
206 * the library.
207 *
208 * Returns 0 if the callback succeeds else not 0.
209 *
210 * After this callback is called, no other callback will be called
211 * again and the tracing instance will be deleted automatically by
9dc7b7ff 212 * libustconsumer. After this call, the user must not use the libustconsumer instance.
d159ac37 213 */
9dc7b7ff 214 int (*on_trace_end)(struct ustconsumer_instance *instance);
d159ac37
AH
215
216 /**
217 * The library's data.
218 */
219 void *user_data;
220};
221
222/**
9dc7b7ff 223 * ustconsumer_new_instance - Is called to create a new tracing session.
d159ac37
AH
224 *
225 * @callbacks: Pointer to a callbacks structure that contain the user
226 * callbacks and data.
227 * @sock_path: Path to the socket used for communication with the traced app
228 *
229 * Returns the instance if the function succeeds else NULL.
230 */
9dc7b7ff
NC
231struct ustconsumer_instance *
232ustconsumer_new_instance(
233 struct ustconsumer_callbacks *callbacks, char *sock_path);
d159ac37
AH
234
235/**
9dc7b7ff 236 * ustconsumer_delete_instance - Is called to free a ustconsumer_instance struct
d159ac37
AH
237 *
238 * @instance: The tracing session instance that needs to be freed.
239 *
240 * This function should only be called if the instance has not been started,
9dc7b7ff 241 * as it will automatically be called at the end of ustconsumer_start_instance.
d159ac37 242 */
9dc7b7ff 243void ustconsumer_delete_instance(struct ustconsumer_instance *instance);
d159ac37
AH
244
245/**
9dc7b7ff 246 * ustconsumer_init_instance - Is called to initiliaze a new tracing session
d159ac37
AH
247 *
248 * @instance: The tracing session instance that needs to be started.
249 *
250 * Returns 0 if the function succeeds.
251 *
9dc7b7ff
NC
252 * This function must be called between ustconsumer_new_instance and
253 * ustconsumer_start_instance. It sets up the communication between the library
d159ac37
AH
254 * and the tracing application.
255 */
9dc7b7ff 256int ustconsumer_init_instance(struct ustconsumer_instance *instance);
d159ac37
AH
257
258/**
9dc7b7ff 259 * ustconsumer_start_instance - Is called to start a new tracing session.
d159ac37
AH
260 *
261 * @instance: The tracing session instance that needs to be started.
262 *
263 * Returns 0 if the function succeeds.
264 *
265 * This is a blocking function. The caller will be blocked on it until the
9dc7b7ff 266 * tracing session is stopped by the user using ustconsumer_stop_instance or until
d159ac37
AH
267 * the traced application terminates
268 */
9dc7b7ff 269int ustconsumer_start_instance(struct ustconsumer_instance *instance);
d159ac37
AH
270
271/**
9dc7b7ff 272 * ustconsumer_stop_instance - Is called to stop a tracing session.
d159ac37
AH
273 *
274 * @instance: The tracing session instance that needs to be stoped.
275 * @send_msg: If true, a message will be sent to the listening thread through
276 * the daemon socket to force it to return from the poll syscall
277 * and realize that it must close. This is not necessary if the
278 * instance is being stopped as part of an interrupt handler, as
279 * the interrupt itself will cause poll to return.
280 *
281 * Returns 0 if the function succeeds.
282 *
9dc7b7ff 283 * This function returns immediately, it only tells libustconsumer to stop the
d159ac37 284 * instance. The on_trace_end callback will be called when the tracing session
9dc7b7ff 285 * will really be stopped. The instance is deleted automatically by libustconsumer
d159ac37
AH
286 * after on_trace_end is called.
287 */
9dc7b7ff 288int ustconsumer_stop_instance(struct ustconsumer_instance *instance, int send_msg);
d159ac37 289
9dc7b7ff 290#endif /* _USTCONSUMER_H */
d159ac37 291
This page took 0.054841 seconds and 4 git commands to generate.