linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 01/66] perf hists: Introduce hist_entry__init function
Date: Tue, 12 Jul 2016 19:39:36 -0300	[thread overview]
Message-ID: <1468363241-14555-2-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1468363241-14555-1-git-send-email-acme@kernel.org>

From: Jiri Olsa <jolsa@kernel.org>

Move the 'struct hist_entry' initialization code to a separate function.
It'll be useful and more clear for the following patches that introduce
allocation callbacks.

Releasing the hist_entry object in hist_entry__new function
(where it's allocated) rather than in hist_entry__init.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1467701765-26194-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/hist.c | 139 ++++++++++++++++++++++++++-----------------------
 1 file changed, 73 insertions(+), 66 deletions(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index e1fcc8d7c01a..04f3b52a319c 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -352,86 +352,93 @@ void hists__delete_entries(struct hists *hists)
  * histogram, sorted on item, collects periods
  */
 
-static struct hist_entry *hist_entry__new(struct hist_entry *template,
-					  bool sample_self)
-{
-	size_t callchain_size = 0;
-	struct hist_entry *he;
+static int hist_entry__init(struct hist_entry *he,
+			    struct hist_entry *template,
+			    bool sample_self)
+{
+	*he = *template;
+
+	if (symbol_conf.cumulate_callchain) {
+		he->stat_acc = malloc(sizeof(he->stat));
+		if (he->stat_acc == NULL)
+			return -ENOMEM;
+		memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
+		if (!sample_self)
+			memset(&he->stat, 0, sizeof(he->stat));
+	}
 
-	if (symbol_conf.use_callchain)
-		callchain_size = sizeof(struct callchain_root);
+	map__get(he->ms.map);
 
-	he = zalloc(sizeof(*he) + callchain_size);
+	if (he->branch_info) {
+		/*
+		 * This branch info is (a part of) allocated from
+		 * sample__resolve_bstack() and will be freed after
+		 * adding new entries.  So we need to save a copy.
+		 */
+		he->branch_info = malloc(sizeof(*he->branch_info));
+		if (he->branch_info == NULL) {
+			map__zput(he->ms.map);
+			free(he->stat_acc);
+			return -ENOMEM;
+		}
 
-	if (he != NULL) {
-		*he = *template;
+		memcpy(he->branch_info, template->branch_info,
+		       sizeof(*he->branch_info));
 
-		if (symbol_conf.cumulate_callchain) {
-			he->stat_acc = malloc(sizeof(he->stat));
-			if (he->stat_acc == NULL) {
-				free(he);
-				return NULL;
-			}
-			memcpy(he->stat_acc, &he->stat, sizeof(he->stat));
-			if (!sample_self)
-				memset(&he->stat, 0, sizeof(he->stat));
-		}
+		map__get(he->branch_info->from.map);
+		map__get(he->branch_info->to.map);
+	}
 
-		map__get(he->ms.map);
+	if (he->mem_info) {
+		map__get(he->mem_info->iaddr.map);
+		map__get(he->mem_info->daddr.map);
+	}
 
-		if (he->branch_info) {
-			/*
-			 * This branch info is (a part of) allocated from
-			 * sample__resolve_bstack() and will be freed after
-			 * adding new entries.  So we need to save a copy.
-			 */
-			he->branch_info = malloc(sizeof(*he->branch_info));
-			if (he->branch_info == NULL) {
-				map__zput(he->ms.map);
-				free(he->stat_acc);
-				free(he);
-				return NULL;
-			}
+	if (symbol_conf.use_callchain)
+		callchain_init(he->callchain);
 
-			memcpy(he->branch_info, template->branch_info,
-			       sizeof(*he->branch_info));
+	if (he->raw_data) {
+		he->raw_data = memdup(he->raw_data, he->raw_size);
 
-			map__get(he->branch_info->from.map);
-			map__get(he->branch_info->to.map);
+		if (he->raw_data == NULL) {
+			map__put(he->ms.map);
+			if (he->branch_info) {
+				map__put(he->branch_info->from.map);
+				map__put(he->branch_info->to.map);
+				free(he->branch_info);
+			}
+			if (he->mem_info) {
+				map__put(he->mem_info->iaddr.map);
+				map__put(he->mem_info->daddr.map);
+			}
+			free(he->stat_acc);
+			return -ENOMEM;
 		}
+	}
+	INIT_LIST_HEAD(&he->pairs.node);
+	thread__get(he->thread);
 
-		if (he->mem_info) {
-			map__get(he->mem_info->iaddr.map);
-			map__get(he->mem_info->daddr.map);
-		}
+	if (!symbol_conf.report_hierarchy)
+		he->leaf = true;
 
-		if (symbol_conf.use_callchain)
-			callchain_init(he->callchain);
+	return 0;
+}
 
-		if (he->raw_data) {
-			he->raw_data = memdup(he->raw_data, he->raw_size);
+static struct hist_entry *hist_entry__new(struct hist_entry *template,
+					  bool sample_self)
+{
+	size_t callchain_size = 0;
+	struct hist_entry *he;
+	int err = 0;
 
-			if (he->raw_data == NULL) {
-				map__put(he->ms.map);
-				if (he->branch_info) {
-					map__put(he->branch_info->from.map);
-					map__put(he->branch_info->to.map);
-					free(he->branch_info);
-				}
-				if (he->mem_info) {
-					map__put(he->mem_info->iaddr.map);
-					map__put(he->mem_info->daddr.map);
-				}
-				free(he->stat_acc);
-				free(he);
-				return NULL;
-			}
-		}
-		INIT_LIST_HEAD(&he->pairs.node);
-		thread__get(he->thread);
+	if (symbol_conf.use_callchain)
+		callchain_size = sizeof(struct callchain_root);
 
-		if (!symbol_conf.report_hierarchy)
-			he->leaf = true;
+	he = zalloc(sizeof(*he) + callchain_size);
+	if (he) {
+		err = hist_entry__init(he, template, sample_self);
+		if (err)
+			zfree(&he);
 	}
 
 	return he;
-- 
2.7.4

  reply	other threads:[~2016-07-12 22:54 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-12 22:39 [GIT PULL 00/66] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-07-12 22:39 ` Arnaldo Carvalho de Melo [this message]
2016-07-12 22:39 ` [PATCH 02/66] perf hists: Introduce hist_entry_ops Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 03/66] perf hists: Introduce hists__add_entry_ops function Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 04/66] perf ui stdio: Add way to setup the color output mode selection Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 05/66] perf annotate: Introduce --stdio-color " Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 06/66] perf report: " Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 07/66] perf trace beauty msg_flags: Remove MSG_TRYHARD Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 08/66] perf trace beauty flock: Add missing fcntl.h include Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 09/66] perf trace beauty open_flags: Add missing headers Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 10/66] perf trace beauty mmap: Add more conditional defines Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 11/66] perf trace beauty flock: " Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 12/66] perf trace beauty open_flags: " Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 13/66] tools: Introduce str_error_r() Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 14/66] perf bench: Add missing pthread.h include for CPU_*() macros Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 15/66] perf tests: " Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 16/66] perf trace: Add conditional define for AT_FDCWD Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 17/66] perf tests openat-syscall-tp-fields: Add some conditional defines Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 18/66] perf bench: Disentangle headers Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 19/66] perf tools: Move syscall number fallbacks from perf-sys.h to tools/arch/x86/include/asm/ Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 20/66] perf strbuf: Add missing headers Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 21/66] perf quote: Disentangle headers Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 22/66] perf tests cpumap: Add missing headers Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 23/66] perf test fdarray: Add missing poll.h header Arnaldo Carvalho de Melo
2016-07-12 22:39 ` [PATCH 24/66] perf tests x86 rdpmc: Add missing headers Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 25/66] perf tools: Add missing header to color.c Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 26/66] perf tools: Remove needless includes from cache.h Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 27/66] perf evsel: Uninline the is_function_event method Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 28/66] perf tools: Uninline scnprintf() and vscnprint() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 29/66] tools lib traceevent: Use str_error_r() Arnaldo Carvalho de Melo
2016-07-12 23:11   ` Steven Rostedt
2016-07-12 23:14     ` Arnaldo Carvalho de Melo
2016-07-12 23:25       ` Steven Rostedt
2016-07-12 23:32         ` Arnaldo Carvalho de Melo
2016-07-13 12:30           ` Steven Rostedt
2016-07-13 13:51             ` Arnaldo Carvalho de Melo
2016-07-13 19:17               ` Steven Rostedt
2016-07-13 20:01                 ` Arnaldo Carvalho de Melo
2016-07-14  1:25                   ` Steven Rostedt
2016-07-14  1:39                     ` Arnaldo Carvalho de Melo
2016-07-17 18:49                       ` Jiri Olsa
2016-07-28 16:04                         ` Steven Rostedt
2016-07-12 22:40 ` [PATCH 30/66] tools lib api fs: " Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 31/66] tools lib: Guard the strlcpy() header with __GLIBC__ Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 32/66] tools lib subcmd: Use str_error_r() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 33/66] perf bench futex: Add missing compiler.h header Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 34/66] perf tools: event.h needs asm/perf_regs.h Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 35/66] tools: Add copy of perf_event.h to tools/include/linux/ Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 36/66] perf bench: Copy kernel files needed to build mem{cpy,set} x86_64 benchmarks Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 37/66] tools lib bpf: Copy bpf.h and bpf_common.h from the kernel Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 38/66] tools: Copy uapi/asm/perf_regs.h " Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 39/66] perf test bpf: Use epoll_wait() instead of epoll_pwait() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 40/66] tools: Copy uapi/linux/hw_breakpoint.h from the kernel Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 41/66] perf tools: Introduce weak alternative to sched_getcpu() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 42/66] perf tools: Remove unneeded magic.h include from util.h Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 43/66] perf trace: Remove unused sys/ptrace.h include Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 44/66] kvm arm/arm64: Remove trailing whitespace from headers Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 45/66] tools: Copy the header files needed by perf tools Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 46/66] perf tools: Fallback to reading sysfs to get cacheline size Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 47/66] perf trace beauty futex_op: Add missing defines for older systems Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 48/66] perf trace beauty seccomp: Remove seccomp.h include Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 49/66] perf symbols: Provide a GElf_Nhdr typedef Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 50/66] perf script python: Silence -Werror=maybe-uninitialized on gcc 5.3.0 Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 51/66] tools: Copy the bitsperlong.h files from the kernel Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 52/66] perf tools: Add the tools/ stringify copy to the MANIFEST Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 53/66] perf tools: Don't add kernel directories to the header search path Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 54/66] perf intel-pt-decoder: Avoid checking code drift on busibox's diff Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 55/66] perf tools: Add feature detection for gelf_getnote() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 56/66] perf symbols: Add Rust demangling Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 57/66] perf evlist: Make event2evsel public Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 58/66] perf tools: Introduce trace_event__tp_format_id() Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 59/66] perf python: Init perf_event_attr::size in perf.evsel constructor Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 60/66] perf python: Fix pyrf_evlist__read_on_cpu event consuming Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 61/66] perf python: Put perf.event objects into dictionary Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 62/66] perf python: Add perf.tracepoint method Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 63/66] perf python: Add struct evsel into struct pyrf_event Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 64/66] perf python: Add support to resolve tracepoint fields Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 65/66] perf python: Add tracepoint example Arnaldo Carvalho de Melo
2016-07-12 22:40 ` [PATCH 66/66] tools lib traceevent: Add filter on task CPU id Arnaldo Carvalho de Melo
2016-07-13  6:59 ` [GIT PULL 00/66] perf/core improvements and fixes Ingo Molnar
2016-07-13  7:35   ` Ingo Molnar
2016-07-13 20:49     ` Josh Poimboeuf
2016-07-13 20:54       ` Peter Zijlstra
2016-07-13 23:29         ` Arnaldo Carvalho de Melo
2016-07-13  7:37   ` Ingo Molnar
2016-07-13  7:33 ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468363241-14555-2-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).