lkml.org 
[lkml]   [2012]   [Apr]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 02/15] tools/events: Add files to create libtraceevent.a
Em Fri, Apr 06, 2012 at 12:47:53AM +0200, Frederic Weisbecker escreveu:
> From: Steven Rostedt <srostedt@redhat.com>
> +struct cmdline {
> + char *comm;
> + int pid;
> +};

In perf we have 'struct thread' for that and some more stuff, they are
kept in an rb_tree located in a 'struct machine', 'machine's exist to
support KVM.

At some point would be good to avoid this, but then it would make this
code need parts of perf, that would have to then be moved to
tools/libsymbol/ or some other more suitable name.

> +static int cmdline_cmp(const void *a, const void *b)
> +{
> + const struct cmdline *ca = a;
> + const struct cmdline *cb = b;
> +
> + if (ca->pid < cb->pid)
> + return -1;
> + if (ca->pid > cb->pid)
> + return 1;
> +
> + return 0;
> +}
> +
> +struct cmdline_list {
> + struct cmdline_list *next;
> + char *comm;
> + int pid;
> +};
> +
> +static int cmdline_init(struct pevent *pevent)
> +{
> + struct cmdline_list *cmdlist = pevent->cmdlist;
> + struct cmdline_list *item;
> + struct cmdline *cmdlines;
> + int i;
> +
> + cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);

My biggest pet peeve, looks like this is New Hampshire code, all these
"do foo or die" strikes a nerve in me :-(

Die calls in library code should just... die.

Only tools can die, libraries just can't, IMHO.

> +struct func_map {
> + unsigned long long addr;
> + char *func;
> + char *mod;
> +};
> +
> +struct func_list {
> + struct func_list *next;
> + unsigned long long addr;
> + char *func;
> + char *mod;
> +};

For this we have tools/perf/utils/symbol.c, that supports userland as
well as java JIT maps, etc. The perf.data file doesn't have to carry a
copy of kallsyms, etc, build-id support is there to make sure we don't
misresolve symbols using the right DSO found in a cache or in -debuginfo
packages, etc.

> +int pevent_register_function(struct pevent *pevent, char *func,
> + unsigned long long addr, char *mod)
> +{
> + struct func_list *item;
> +
> + item = malloc_or_die(sizeof(*item));
> +
> + item->next = pevent->funclist;
> + item->func = strdup(func);
> + if (mod)
> + item->mod = strdup(mod);
> + else
> + item->mod = NULL;

strdup can fail, and no, we shouldn't die if that happens :-)



\
 
 \ /
  Last update: 2012-04-11 17:23    [W:0.177 / U:0.432 seconds]
©2003-2014 Jasper Spaans. Advertise on this site