lkml.org 
[lkml]   [2012]   [Sep]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints
Date
On Mon, 24 Sep 2012 12:59:42 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> The existing constructor receives a perf_event_attr filled with the
> event type and the config.
>
> To reduce the boilerplate for tracepoints, provide a new constructor,
> perf_evsel__newtp() that receives the tracepoint name and will open
> the debugfs file, call into libtraceevent new pevent_parse_format file
> to fill its ->tp_format member, so that users can then just call
> perf_evsel__field() to access its fields.
[snip]
> +static struct event_format *event_format__new(const char *sys, const char *name)
> +{
> + int fd, n;
> + char *filename;
> + void *bf = NULL, *nbf;
> + size_t size = 0, alloc_size = 0;
> + struct event_format *format = NULL;
> +
> + if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, name) < 0)
> + goto out;
> +
> + fd = open(filename, O_RDONLY);
> + if (fd < 0)
> + goto out_free_filename;
> +
> + do {
> + if (size == alloc_size) {
> + alloc_size += BUFSIZ;
> + nbf = realloc(bf, alloc_size);
> + if (nbf == NULL)
> + goto out_free_bf;
> + bf = nbf;
> + }
> +
> + n = read(fd, bf + size, BUFSIZ);

Wouldn't it be better doing s/BUFSIZ/alloc_size - size/ ? Although
there'll be no partial reading issue when working on debugfs I guess.

Thanks,
Namhyung


> + if (n < 0)
> + goto out_free_bf;
> + size += n;
> + } while (n > 0);
> +
> + pevent_parse_format(&format, bf, size, sys);
> +
> +out_free_bf:
> + free(bf);
> + close(fd);
> +out_free_filename:
> + free(filename);
> +out:
> + return format;
> +}


\
 
 \ /
  Last update: 2012-09-25 07:21    [W:0.196 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site