Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755600AbaAHItB (ORCPT ); Wed, 8 Jan 2014 03:49:01 -0500 Received: from lgeamrelo01.lge.com ([156.147.1.125]:63883 "EHLO LGEAMRELO01.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755941AbaAHIqz (ORCPT ); Wed, 8 Jan 2014 03:46:55 -0500 X-AuditID: 9c93017d-b7b66ae000006a2a-35-52cd1071da60 From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Paul Mackerras , Ingo Molnar , Namhyung Kim , LKML , Arun Sharma , Frederic Weisbecker , Jiri Olsa , Rodrigo Campos Subject: [PATCH 25/28] perf top: Convert to hist_entry_iter Date: Wed, 8 Jan 2014 17:46:30 +0900 Message-Id: <1389170793-21926-26-git-send-email-namhyung@kernel.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1389170793-21926-1-git-send-email-namhyung@kernel.org> References: <1389170793-21926-1-git-send-email-namhyung@kernel.org> X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reuse hist_entry_iter__add() function to share the similar code with perf report. Note that it needs to be called with hists.lock so tweak some internal functions not to deadlock or hold the lock too long. Signed-off-by: Namhyung Kim --- tools/perf/builtin-top.c | 75 ++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index f0f55e6030cd..cf330c66bed7 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -186,9 +186,6 @@ static void perf_top__record_precise_ip(struct perf_top *top, sym = he->ms.sym; notes = symbol__annotation(sym); - if (pthread_mutex_trylock(¬es->lock)) - return; - ip = he->ms.map->map_ip(he->ms.map, ip); err = hist_entry__inc_addr_samples(he, counter, ip); @@ -201,6 +198,8 @@ static void perf_top__record_precise_ip(struct perf_top *top, sym->name); sleep(1); } + + pthread_mutex_lock(¬es->lock); } static void perf_top__show_details(struct perf_top *top) @@ -236,24 +235,6 @@ out_unlock: pthread_mutex_unlock(¬es->lock); } -static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel, - struct addr_location *al, - struct perf_sample *sample) -{ - struct hist_entry *he; - - pthread_mutex_lock(&evsel->hists.lock); - he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, - sample->period, sample->weight, - sample->transaction, true); - pthread_mutex_unlock(&evsel->hists.lock); - if (he == NULL) - return NULL; - - hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); - return he; -} - static void perf_top__print_sym_table(struct perf_top *top) { char bf[160]; @@ -657,6 +638,28 @@ static int symbol_filter(struct map *map __maybe_unused, struct symbol *sym) return 0; } +static int hist_iter_cb(struct hist_entry_iter *iter, struct addr_location *al, + bool single, void *arg) +{ + struct perf_top *top = arg; + struct hist_entry *he = iter->he; + struct perf_evsel *evsel = iter->evsel; + + if (single) + hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE); + + if (sort__has_sym) { + u64 ip = al->addr; + + if (al->map) + ip = al->map->unmap_ip(al->map, ip); + + perf_top__record_precise_ip(top, he, evsel->idx, ip); + } + + return 0; +} + static void perf_event__process_sample(struct perf_tool *tool, const union perf_event *event, struct perf_evsel *evsel, @@ -664,8 +667,6 @@ static void perf_event__process_sample(struct perf_tool *tool, struct machine *machine) { struct perf_top *top = container_of(tool, struct perf_top, tool); - struct symbol *parent = NULL; - u64 ip = sample->ip; struct addr_location al; int err; @@ -741,25 +742,23 @@ static void perf_event__process_sample(struct perf_tool *tool, } if (al.sym == NULL || !al.sym->ignore) { - struct hist_entry *he; + struct hist_entry_iter *iter; - err = sample__resolve_callchain(sample, &parent, evsel, &al, - top->max_stack); - if (err) - return; + if (symbol_conf.cumulate_callchain) + iter = &hist_iter_cumulative; + else + iter = &hist_iter_normal; - he = perf_evsel__add_hist_entry(evsel, &al, sample); - if (he == NULL) { - pr_err("Problem incrementing symbol period, skipping event\n"); - return; - } + iter->add_entry_cb = hist_iter_cb; - err = hist_entry__append_callchain(he, sample); - if (err) - return; + pthread_mutex_lock(&evsel->hists.lock); + + err = hist_entry_iter__add(iter, &al, evsel, event, sample, + false, top->max_stack, top); + if (err < 0) + pr_err("Problem incrementing symbol period, skipping event\n"); - if (sort__has_sym) - perf_top__record_precise_ip(top, he, evsel->idx, ip); + pthread_mutex_unlock(&evsel->hists.lock); } return; -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/