aboutsummaryrefslogtreecommitdiffstats
path: root/parse-events.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-02-22 19:20:51 -0500
committerSteven Rostedt <rostedt@goodmis.org>2011-02-22 19:20:51 -0500
commitcbe4085d032839a264465e018050cdc0e5c44970 (patch)
tree3011a2bc7a1ff1890927207392f3737f76f31150 /parse-events.c
parentbd5759228f1c4f9ed8f0312749c99ff6356fe843 (diff)
parse-events: Only allocate comm when adding a new mapping
Do not go through the malloc of a comm when checking to add a new one to the pid mapping until it is known that a new one is going to be added. Moving the alloction further down saves a little time. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'parse-events.c')
-rw-r--r--parse-events.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/parse-events.c b/parse-events.c
index 8e79723..d831db7 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -229,19 +229,14 @@ int pevent_pid_is_registered(struct pevent *pevent, int pid)
229 * we must add this pid. This is much slower than when cmdlines 229 * we must add this pid. This is much slower than when cmdlines
230 * are added before the array is initialized. 230 * are added before the array is initialized.
231 */ 231 */
232static int add_new_comm(struct pevent *pevent, char *comm, int pid) 232static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
233{ 233{
234 struct cmdline *cmdlines = pevent->cmdlines; 234 struct cmdline *cmdlines = pevent->cmdlines;
235 const struct cmdline *cmdline; 235 const struct cmdline *cmdline;
236 struct cmdline key; 236 struct cmdline key;
237 237
238 if (!comm) 238 if (!pid)
239 die("malloc comm");
240
241 if (!pid) {
242 free(comm);
243 return 0; 239 return 0;
244 }
245 240
246 /* avoid duplicates */ 241 /* avoid duplicates */
247 key.pid = pid; 242 key.pid = pid;
@@ -250,7 +245,6 @@ static int add_new_comm(struct pevent *pevent, char *comm, int pid)
250 sizeof(*pevent->cmdlines), cmdline_cmp); 245 sizeof(*pevent->cmdlines), cmdline_cmp);
251 if (cmdline) { 246 if (cmdline) {
252 errno = EEXIST; 247 errno = EEXIST;
253 free(comm);
254 return -1; 248 return -1;
255 } 249 }
256 250
@@ -261,7 +255,10 @@ static int add_new_comm(struct pevent *pevent, char *comm, int pid)
261 } 255 }
262 256
263 cmdlines[pevent->cmdline_count].pid = pid; 257 cmdlines[pevent->cmdline_count].pid = pid;
264 cmdlines[pevent->cmdline_count].comm = comm; 258 cmdlines[pevent->cmdline_count].comm = strdup(comm);
259 if (!cmdlines[pevent->cmdline_count].comm)
260 die("malloc comm");
261
265 if (cmdlines[pevent->cmdline_count].comm) 262 if (cmdlines[pevent->cmdline_count].comm)
266 pevent->cmdline_count++; 263 pevent->cmdline_count++;
267 264
@@ -285,7 +282,7 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
285 struct cmdline_list *item; 282 struct cmdline_list *item;
286 283
287 if (pevent->cmdlines) 284 if (pevent->cmdlines)
288 return add_new_comm(pevent, strdup(comm), pid); 285 return add_new_comm(pevent, comm, pid);
289 286
290 item = malloc_or_die(sizeof(*item)); 287 item = malloc_or_die(sizeof(*item));
291 item->comm = strdup(comm); 288 item->comm = strdup(comm);