aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-06-18 12:21:20 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-06-18 12:21:20 -0400
commit7a5047359ba0942219b7feaf923b520deee63496 (patch)
tree036b486498982df5c179404433415ceb45324dd8
parent4b2de0ca50b576f679a3e1ffa1fd0d458aba31dd (diff)
trace-cmd: Add helper function tracecmd_add_id()
Several places are creating list of event ids as an array with the ids ending in -1. To use this, simply: int *events = NULL; intt len = 0; /* Fictious for statement */ for (event = get_event(); event; event = next_event(event)) events = tracecmd_add_id(events, event->id, len++); /* ... */ free(events); Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-cmd.h1
-rw-r--r--trace-util.c50
2 files changed, 51 insertions, 0 deletions
diff --git a/trace-cmd.h b/trace-cmd.h
index cbd563e..901a843 100644
--- a/trace-cmd.h
+++ b/trace-cmd.h
@@ -42,6 +42,7 @@ char **tracecmd_local_plugins(const char *tracing_dir);
42 42
43char **tracecmd_add_list(char **list, const char *name, int len); 43char **tracecmd_add_list(char **list, const char *name, int len);
44void tracecmd_free_list(char **list); 44void tracecmd_free_list(char **list);
45int *tracecmd_add_id(int *list, int id, int len);
45 46
46enum { 47enum {
47 RINGBUF_TYPE_PADDING = 29, 48 RINGBUF_TYPE_PADDING = 29,
diff --git a/trace-util.c b/trace-util.c
index 058c9d2..33dbdf0 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -241,6 +241,19 @@ static char *append_file(const char *dir, const char *name)
241 return file; 241 return file;
242} 242}
243 243
244/**
245 * tracecmd_add_list - add an new string to a string list.
246 * @list: list to add the string to (may be NULL)
247 * @name: the string to add
248 * @len: current length of list of strings.
249 *
250 * The typical usage is:
251 *
252 * systems = tracecmd_add_list(systems, name, len++);
253 *
254 * Returns the new allocated list with an allocated name added.
255 * The list will end with NULL.
256 */
244char **tracecmd_add_list(char **list, const char *name, int len) 257char **tracecmd_add_list(char **list, const char *name, int len)
245{ 258{
246 if (!list) 259 if (!list)
@@ -260,6 +273,12 @@ char **tracecmd_add_list(char **list, const char *name, int len)
260 return list; 273 return list;
261} 274}
262 275
276/**
277 * tracecmd_free_list - free a list created with tracecmd_add_list.
278 * @list: The list to free.
279 *
280 * Frees the list as well as the names within the list.
281 */
263void tracecmd_free_list(char **list) 282void tracecmd_free_list(char **list)
264{ 283{
265 int i; 284 int i;
@@ -274,6 +293,37 @@ void tracecmd_free_list(char **list)
274} 293}
275 294
276/** 295/**
296 * tracecmd_add_id - add an int to the event id list
297 * @list: list to add the id to
298 * @id: id to add
299 * @len: current length of list of ids.
300 *
301 * The typical usage is:
302 *
303 * events = tracecmd_add_id(events, id, len++);
304 *
305 * Returns the new allocated list with the id included.
306 * the list will contain a '-1' at the end.
307 *
308 * The returned list should be freed with free().
309 */
310int *tracecmd_add_id(int *list, int id, int len)
311{
312 if (!list)
313 list = malloc_or_die(sizeof(*list) * 2);
314 else {
315 list = realloc(list, sizeof(*list) * (len + 2));
316 if (!list)
317 die("Can ont allocate list");
318 }
319
320 list[len++] = id;
321 list[len] = -1;
322
323 return list;
324}
325
326/**
277 * tracecmd_event_systems - return list of systems for tracing 327 * tracecmd_event_systems - return list of systems for tracing
278 * @tracing_dir: directory holding the "events" directory 328 * @tracing_dir: directory holding the "events" directory
279 * 329 *