Commit 5cedb413 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf c2c: Use mem_info refcnt logic

Switch to refcnt logic instead of duplicating mem_info objects. No
functional change, just saving some memory.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180307155020.32613-7-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 9f87498f
...@@ -237,9 +237,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, ...@@ -237,9 +237,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
if (mi == NULL) if (mi == NULL)
return -ENOMEM; return -ENOMEM;
mi_dup = memdup(mi, sizeof(*mi)); /*
if (!mi_dup) * The mi object is released in hists__add_entry_ops,
goto free_mi; * if it gets sorted out into existing data, so we need
* to take the copy now.
*/
mi_dup = mem_info__get(mi);
c2c_decode_stats(&stats, mi); c2c_decode_stats(&stats, mi);
...@@ -247,7 +250,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, ...@@ -247,7 +250,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
&al, NULL, NULL, mi, &al, NULL, NULL, mi,
sample, true); sample, true);
if (he == NULL) if (he == NULL)
goto free_mi_dup; goto free_mi;
c2c_he = container_of(he, struct c2c_hist_entry, he); c2c_he = container_of(he, struct c2c_hist_entry, he);
c2c_add_stats(&c2c_he->stats, &stats); c2c_add_stats(&c2c_he->stats, &stats);
...@@ -272,19 +275,15 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, ...@@ -272,19 +275,15 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
mi = mi_dup; mi = mi_dup;
mi_dup = memdup(mi, sizeof(*mi));
if (!mi_dup)
goto free_mi;
c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2); c2c_hists = he__get_c2c_hists(he, c2c.cl_sort, 2);
if (!c2c_hists) if (!c2c_hists)
goto free_mi_dup; goto free_mi;
he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
&al, NULL, NULL, mi, &al, NULL, NULL, mi,
sample, true); sample, true);
if (he == NULL) if (he == NULL)
goto free_mi_dup; goto free_mi;
c2c_he = container_of(he, struct c2c_hist_entry, he); c2c_he = container_of(he, struct c2c_hist_entry, he);
c2c_add_stats(&c2c_he->stats, &stats); c2c_add_stats(&c2c_he->stats, &stats);
...@@ -303,10 +302,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused, ...@@ -303,10 +302,9 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
addr_location__put(&al); addr_location__put(&al);
return ret; return ret;
free_mi_dup:
free(mi_dup);
free_mi: free_mi:
free(mi); mem_info__put(mi_dup);
mem_info__put(mi);
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment