2 * libustconsumer header file
4 * Copyright 2005-2010 -
5 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
7 * Oumarou Dicko <oumarou.dicko@polymtl.ca>
8 * Michael Sills-Lavoie <michael.sills-lavoie@polymtl.ca>
9 * Alexis Halle <alexis.halle@polymtl.ca>
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.
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.
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
26 #ifndef _USTCONSUMER_H
27 #define _USTCONSUMER_H
31 #include <ust/kcompat/kcompat.h>
32 #include <urcu/list.h>
34 #define USTCONSUMER_DEFAULT_TRACE_PATH "/tmp/usttrace"
46 /* The pipe file descriptor */
52 /* the buffer memory */
56 /* number of subbuffers in buffer */
58 /* size of each subbuffer */
61 /* the buffer information struct */
71 struct ustconsumer_callbacks
;
74 * struct ustconsumer_instance - Contains the data associated with a trace instance.
75 * The lib user can read but MUST NOT change any attributes but callbacks.
76 * @callbacks: Contains the necessary callbacks for a tracing session.
78 struct ustconsumer_instance
{
79 struct ustconsumer_callbacks
*callbacks
;
82 struct cds_list_head connections
;
84 struct ustcomm_sock
*listen_sock
;
86 pthread_mutex_t mutex
;
91 * struct ustconsumer_callbacks - Contains the necessary callbacks for a tracing
92 * session. The user can set the unnecessary functions to NULL if he does not
95 struct ustconsumer_callbacks
{
97 * on_open_buffer - Is called after a buffer is attached to process memory
99 * @data: pointer to the callbacks structure that has been passed to the
101 * @buf: structure that contains the data associated with the buffer
103 * Returns 0 if the callback succeeds else not 0.
105 * It has to be thread safe, because it is called by many threads.
107 int (*on_open_buffer
)(struct ustconsumer_callbacks
*data
,
108 struct buffer_info
*buf
);
111 * on_close_buffer - Is called after a buffer is detached from process memory
113 * @data: pointer to the callbacks structure that has been passed to the
115 * @buf: structure that contains the data associated with the buffer
117 * Returns 0 if the callback succeeds else not 0.
119 * It has to be thread safe, because it is called by many threads.
121 int (*on_close_buffer
)(struct ustconsumer_callbacks
*data
,
122 struct buffer_info
*buf
);
125 * on_read_subbuffer - Is called after a subbuffer is a reserved.
127 * @data: pointer to the callbacks structure that has been passed to the
129 * @buf: structure that contains the data associated with the buffer
131 * Returns 0 if the callback succeeds else not 0.
133 * It has to be thread safe, because it is called by many threads.
135 int (*on_read_subbuffer
)(struct ustconsumer_callbacks
*data
,
136 struct buffer_info
*buf
);
139 * on_read_partial_subbuffer - Is called when an incomplete subbuffer
140 * is being salvaged from an app crash
142 * @data: pointer to the callbacks structure that has been passed to the
144 * @buf: structure that contains the data associated with the buffer
145 * @subbuf_index: index of the subbuffer to read in the buffer
146 * @valid_length: number of bytes considered safe to read
148 * Returns 0 if the callback succeeds else not 0.
150 * It has to be thread safe, because it is called by many threads.
152 int (*on_read_partial_subbuffer
)(struct ustconsumer_callbacks
*data
,
153 struct buffer_info
*buf
,
155 unsigned long valid_length
);
158 * on_put_error - Is called when a put error has occured and the last
159 * subbuffer read is no longer safe to keep
161 * @data: pointer to the callbacks structure that has been passed to the
163 * @buf: structure that contains the data associated with the buffer
165 * Returns 0 if the callback succeeds else not 0.
167 * It has to be thread safe, because it is called by many threads.
169 int (*on_put_error
)(struct ustconsumer_callbacks
*data
,
170 struct buffer_info
*buf
);
173 * on_new_thread - Is called when a new thread is created
175 * @data: pointer to the callbacks structure that has been passed to the
178 * Returns 0 if the callback succeeds else not 0.
180 * It has to be thread safe, because it is called by many threads.
182 int (*on_new_thread
)(struct ustconsumer_callbacks
*data
);
185 * on_close_thread - Is called just before a thread is destroyed
187 * @data: pointer to the callbacks structure that has been passed to the
190 * Returns 0 if the callback succeeds else not 0.
192 * It has to be thread safe, because it is called by many threads.
194 int (*on_close_thread
)(struct ustconsumer_callbacks
*data
);
197 * on_trace_end - Is called at the very end of the tracing session. At
198 * this time, everything has been closed and the threads have
201 * @instance: pointer to the instance structure that has been passed to
204 * Returns 0 if the callback succeeds else not 0.
206 * After this callback is called, no other callback will be called
207 * again and the tracing instance will be deleted automatically by
208 * libustconsumer. After this call, the user must not use the libustconsumer instance.
210 int (*on_trace_end
)(struct ustconsumer_instance
*instance
);
213 * The library's data.
219 * ustconsumer_new_instance - Is called to create a new tracing session.
221 * @callbacks: Pointer to a callbacks structure that contain the user
222 * callbacks and data.
223 * @sock_path: Path to the socket used for communication with the traced app
225 * Returns the instance if the function succeeds else NULL.
227 struct ustconsumer_instance
*
228 ustconsumer_new_instance(
229 struct ustconsumer_callbacks
*callbacks
, char *sock_path
);
232 * ustconsumer_delete_instance - Is called to free a ustconsumer_instance struct
234 * @instance: The tracing session instance that needs to be freed.
236 * This function should only be called if the instance has not been started,
237 * as it will automatically be called at the end of ustconsumer_start_instance.
239 void ustconsumer_delete_instance(struct ustconsumer_instance
*instance
);
242 * ustconsumer_init_instance - Is called to initiliaze a new tracing session
244 * @instance: The tracing session instance that needs to be started.
246 * Returns 0 if the function succeeds.
248 * This function must be called between ustconsumer_new_instance and
249 * ustconsumer_start_instance. It sets up the communication between the library
250 * and the tracing application.
252 int ustconsumer_init_instance(struct ustconsumer_instance
*instance
);
255 * ustconsumer_start_instance - Is called to start a new tracing session.
257 * @instance: The tracing session instance that needs to be started.
259 * Returns 0 if the function succeeds.
261 * This is a blocking function. The caller will be blocked on it until the
262 * tracing session is stopped by the user using ustconsumer_stop_instance or until
263 * the traced application terminates
265 int ustconsumer_start_instance(struct ustconsumer_instance
*instance
);
268 * ustconsumer_stop_instance - Is called to stop a tracing session.
270 * @instance: The tracing session instance that needs to be stoped.
271 * @send_msg: If true, a message will be sent to the listening thread through
272 * the daemon socket to force it to return from the poll syscall
273 * and realize that it must close. This is not necessary if the
274 * instance is being stopped as part of an interrupt handler, as
275 * the interrupt itself will cause poll to return.
277 * Returns 0 if the function succeeds.
279 * This function returns immediately, it only tells libustconsumer to stop the
280 * instance. The on_trace_end callback will be called when the tracing session
281 * will really be stopped. The instance is deleted automatically by libustconsumer
282 * after on_trace_end is called.
284 int ustconsumer_stop_instance(struct ustconsumer_instance
*instance
, int send_msg
);
286 #endif /* _USTCONSUMER_H */