Re: [PATCH 20/48] perf tools: Make ordered_events reusable
From: Jiri Olsa
Date: Wed Feb 24 2016 - 09:18:58 EST
On Mon, Feb 22, 2016 at 09:10:47AM +0000, Wang Nan wrote:
> ordered_events__free() leaves linked lists and timestamps not cleared,
> so unable to be reused after ordered_events__free(). Which is inconvenient
> after 'perf record' supports generating multiple perf.data output and
> process build-ids for each of them.
>
> Calls ordered_events__init() in ordered_events__free() so ordered_events
> can be reused.
>
> Signed-off-by: Wang Nan <wangnan0@xxxxxxxxxx>
> Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Zefan Li <lizefan@xxxxxxxxxx>
> Cc: pi3orama@xxxxxxx
> ---
> tools/perf/util/ordered-events.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
> index b1b9e23..70c0dc8 100644
> --- a/tools/perf/util/ordered-events.c
> +++ b/tools/perf/util/ordered-events.c
> @@ -299,6 +299,8 @@ void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t d
>
> void ordered_events__free(struct ordered_events *oe)
> {
> + ordered_events__deliver_t old_deliver = oe->deliver;
> +
> while (!list_empty(&oe->to_free)) {
> struct ordered_event *event;
>
> @@ -307,4 +309,7 @@ void ordered_events__free(struct ordered_events *oe)
> free_dup_event(oe, event->event);
> free(event);
> }
> +
> + memset(oe, '\0', sizeof(*oe));
> + ordered_events__init(oe, old_deliver);
> }
I think it'd be better to put that memset call into ordered_events__init
and introduce ordered_events__reinit that calls ordered_events__free
and ordered_events__init with oe->deliver as you do above
that way it'll be apparent when you reuse the ordered_events struct
thanks,
jirka