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
31 #include <ust/kcompat/kcompat.h>
33 #define USTD_DEFAULT_TRACE_PATH "/tmp/usttrace"
35 struct ustcomm_connection
;
41 struct ustcomm_connection
*conn
;
46 /* the buffer memory */
50 /* number of subbuffers in buffer */
52 /* size of each subbuffer */
55 /* the buffer information struct */
65 struct libustd_callbacks
;
68 * struct libustd_instance - Contains the data associated with a trace instance.
69 * The lib user can read but MUST NOT change any attributes but callbacks.
70 * @callbacks: Contains the necessary callbacks for a tracing session.
72 struct libustd_instance
{
73 struct libustd_callbacks
*callbacks
;
76 struct ustcomm_ustd
*comm
;
78 pthread_mutex_t mutex
;
83 * struct libustd_callbacks - Contains the necessary callbacks for a tracing
84 * session. The user can set the unnecessary functions to NULL if he does not
87 struct libustd_callbacks
{
89 * on_open_buffer - Is called after a buffer is attached to process memory
91 * @data: pointer to the callbacks structure that has been passed to the
93 * @buf: structure that contains the data associated with the buffer
95 * Returns 0 if the callback succeeds else not 0.
97 * It has to be thread safe, because it is called by many threads.
99 int (*on_open_buffer
)(struct libustd_callbacks
*data
,
100 struct buffer_info
*buf
);
103 * on_close_buffer - Is called after a buffer is detached from process memory
105 * @data: pointer to the callbacks structure that has been passed to the
107 * @buf: structure that contains the data associated with the buffer
109 * Returns 0 if the callback succeeds else not 0.
111 * It has to be thread safe, because it is called by many threads.
113 int (*on_close_buffer
)(struct libustd_callbacks
*data
,
114 struct buffer_info
*buf
);
117 * on_read_subbuffer - Is called after a subbuffer is a reserved.
119 * @data: pointer to the callbacks structure that has been passed to the
121 * @buf: structure that contains the data associated with the buffer
123 * Returns 0 if the callback succeeds else not 0.
125 * It has to be thread safe, because it is called by many threads.
127 int (*on_read_subbuffer
)(struct libustd_callbacks
*data
,
128 struct buffer_info
*buf
);
131 * on_read_partial_subbuffer - Is called when an incomplete subbuffer
132 * is being salvaged from an app crash
134 * @data: pointer to the callbacks structure that has been passed to the
136 * @buf: structure that contains the data associated with the buffer
137 * @subbuf_index: index of the subbuffer to read in the buffer
138 * @valid_length: number of bytes considered safe to read
140 * Returns 0 if the callback succeeds else not 0.
142 * It has to be thread safe, because it is called by many threads.
144 int (*on_read_partial_subbuffer
)(struct libustd_callbacks
*data
,
145 struct buffer_info
*buf
,
147 unsigned long valid_length
);
150 * on_put_error - Is called when a put error has occured and the last
151 * subbuffer read is no longer safe to keep
153 * @data: pointer to the callbacks structure that has been passed to the
155 * @buf: structure that contains the data associated with the buffer
157 * Returns 0 if the callback succeeds else not 0.
159 * It has to be thread safe, because it is called by many threads.
161 int (*on_put_error
)(struct libustd_callbacks
*data
,
162 struct buffer_info
*buf
);
165 * on_new_thread - Is called when a new thread is created
167 * @data: pointer to the callbacks structure that has been passed to the
170 * Returns 0 if the callback succeeds else not 0.
172 * It has to be thread safe, because it is called by many threads.
174 int (*on_new_thread
)(struct libustd_callbacks
*data
);
177 * on_close_thread - Is called just before a thread is destroyed
179 * @data: pointer to the callbacks structure that has been passed to the
182 * Returns 0 if the callback succeeds else not 0.
184 * It has to be thread safe, because it is called by many threads.
186 int (*on_close_thread
)(struct libustd_callbacks
*data
);
189 * on_trace_end - Is called at the very end of the tracing session. At
190 * this time, everything has been closed and the threads have
193 * @instance: pointer to the instance structure that has been passed to
196 * Returns 0 if the callback succeeds else not 0.
198 * After this callback is called, no other callback will be called
199 * again and the tracing instance will be deleted automatically by
200 * libustd. After this call, the user must not use the libustd instance.
202 int (*on_trace_end
)(struct libustd_instance
*instance
);
205 * The library's data.
211 * libustd_new_instance - Is called to create a new tracing session.
213 * @callbacks: Pointer to a callbacks structure that contain the user
214 * callbacks and data.
215 * @sock_path: Path to the socket used for communication with the traced app
217 * Returns the instance if the function succeeds else NULL.
219 struct libustd_instance
*
220 libustd_new_instance(
221 struct libustd_callbacks
*callbacks
, char *sock_path
);
224 * libustd_delete_instance - Is called to free a libustd_instance struct
226 * @instance: The tracing session instance that needs to be freed.
228 * This function should only be called if the instance has not been started,
229 * as it will automatically be called at the end of libustd_start_instance.
231 void libustd_delete_instance(struct libustd_instance
*instance
);
234 * libustd_init_instance - Is called to initiliaze a new tracing session
236 * @instance: The tracing session instance that needs to be started.
238 * Returns 0 if the function succeeds.
240 * This function must be called between libustd_new_instance and
241 * libustd_start_instance. It sets up the communication between the library
242 * and the tracing application.
244 int libustd_init_instance(struct libustd_instance
*instance
);
247 * libustd_start_instance - Is called to start a new tracing session.
249 * @instance: The tracing session instance that needs to be started.
251 * Returns 0 if the function succeeds.
253 * This is a blocking function. The caller will be blocked on it until the
254 * tracing session is stopped by the user using libustd_stop_instance or until
255 * the traced application terminates
257 int libustd_start_instance(struct libustd_instance
*instance
);
260 * libustd_stop_instance - Is called to stop a tracing session.
262 * @instance: The tracing session instance that needs to be stoped.
263 * @send_msg: If true, a message will be sent to the listening thread through
264 * the daemon socket to force it to return from the poll syscall
265 * and realize that it must close. This is not necessary if the
266 * instance is being stopped as part of an interrupt handler, as
267 * the interrupt itself will cause poll to return.
269 * Returns 0 if the function succeeds.
271 * This function returns immediately, it only tells libustd to stop the
272 * instance. The on_trace_end callback will be called when the tracing session
273 * will really be stopped. The instance is deleted automatically by libustd
274 * after on_trace_end is called.
276 int libustd_stop_instance(struct libustd_instance
*instance
, int send_msg
);