[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <874nmmybg9.fsf@sejong.aot.lge.com>
Date: Tue, 25 Sep 2012 13:26:46 +0900
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...radead.org>
Cc: Ingo Molnar <mingo@...nel.org>, linux-kernel@...r.kernel.org,
Arnaldo Carvalho de Melo <acme@...hat.com>,
David Ahern <dsahern@...il.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Jiri Olsa <jolsa@...hat.com>, Mike Galbraith <efault@....de>,
Paul Mackerras <paulus@...ba.org>,
Peter Zijlstra <peterz@...radead.org>,
Stephane Eranian <eranian@...gle.com>,
Steven Rostedt <rostedt@...dmis.org>
Subject: Re: [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints
On Mon, 24 Sep 2012 12:59:42 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@...hat.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;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists