aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2018-04-02 13:24:28 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-04-03 09:23:32 -0400
commit25c312dbf88ca402bf47389c5aa4f1552799a8ca (patch)
tree5cc971e26d7a513889a9016a57b164f800dad00c /tools/perf
parent967a464a7e6d939f0b0dbb4ee41bd3d515fa9a6d (diff)
perf hists: Move hists__scnprintf_title() away from the TUI code
The previous patch made this function useful to non-TUI parts of the tools, but left it where the function from what it was carved, so that the patch showed more clearly the process. Now just move it outside the TUI parts so that we can finally use it, even when the TUI code doesn't get built/linked. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Martin Liška <mliska@suse.cz> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196935 Link: https://lkml.kernel.org/n/tip-hqj7hvcr3mu5lvcqp3cssio6@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/ui/browsers/hists.c79
-rw-r--r--tools/perf/util/hist.c81
2 files changed, 81 insertions, 79 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index c20f0ad22f34..cde9bab5061d 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -2208,85 +2208,6 @@ static inline bool is_report_browser(void *timer)
2208 return timer == NULL; 2208 return timer == NULL;
2209} 2209}
2210 2210
2211int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq)
2212{
2213 char unit;
2214 int printed;
2215 const struct dso *dso = hists->dso_filter;
2216 const struct thread *thread = hists->thread_filter;
2217 int socket_id = hists->socket_filter;
2218 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
2219 u64 nr_events = hists->stats.total_period;
2220 struct perf_evsel *evsel = hists_to_evsel(hists);
2221 const char *ev_name = perf_evsel__name(evsel);
2222 char buf[512], sample_freq_str[64] = "";
2223 size_t buflen = sizeof(buf);
2224 char ref[30] = " show reference callgraph, ";
2225 bool enable_ref = false;
2226
2227 if (symbol_conf.filter_relative) {
2228 nr_samples = hists->stats.nr_non_filtered_samples;
2229 nr_events = hists->stats.total_non_filtered_period;
2230 }
2231
2232 if (perf_evsel__is_group_event(evsel)) {
2233 struct perf_evsel *pos;
2234
2235 perf_evsel__group_desc(evsel, buf, buflen);
2236 ev_name = buf;
2237
2238 for_each_group_member(pos, evsel) {
2239 struct hists *pos_hists = evsel__hists(pos);
2240
2241 if (symbol_conf.filter_relative) {
2242 nr_samples += pos_hists->stats.nr_non_filtered_samples;
2243 nr_events += pos_hists->stats.total_non_filtered_period;
2244 } else {
2245 nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
2246 nr_events += pos_hists->stats.total_period;
2247 }
2248 }
2249 }
2250
2251 if (symbol_conf.show_ref_callgraph &&
2252 strstr(ev_name, "call-graph=no"))
2253 enable_ref = true;
2254
2255 if (show_freq)
2256 scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq);
2257
2258 nr_samples = convert_unit(nr_samples, &unit);
2259 printed = scnprintf(bf, size,
2260 "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64,
2261 nr_samples, unit, evsel->nr_members > 1 ? "s" : "",
2262 ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events);
2263
2264
2265 if (hists->uid_filter_str)
2266 printed += snprintf(bf + printed, size - printed,
2267 ", UID: %s", hists->uid_filter_str);
2268 if (thread) {
2269 if (hists__has(hists, thread)) {
2270 printed += scnprintf(bf + printed, size - printed,
2271 ", Thread: %s(%d)",
2272 (thread->comm_set ? thread__comm_str(thread) : ""),
2273 thread->tid);
2274 } else {
2275 printed += scnprintf(bf + printed, size - printed,
2276 ", Thread: %s",
2277 (thread->comm_set ? thread__comm_str(thread) : ""));
2278 }
2279 }
2280 if (dso)
2281 printed += scnprintf(bf + printed, size - printed,
2282 ", DSO: %s", dso->short_name);
2283 if (socket_id > -1)
2284 printed += scnprintf(bf + printed, size - printed,
2285 ", Processor Socket: %d", socket_id);
2286
2287 return printed;
2288}
2289
2290static int hists_browser__scnprintf_title(struct hist_browser *browser, char *bf, size_t size) 2211static int hists_browser__scnprintf_title(struct hist_browser *browser, char *bf, size_t size)
2291{ 2212{
2292 struct hist_browser_timer *hbt = browser->hbt; 2213 struct hist_browser_timer *hbt = browser->hbt;
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 7d968892ee39..4d602fba40b2 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -6,6 +6,7 @@
6#include "session.h" 6#include "session.h"
7#include "namespaces.h" 7#include "namespaces.h"
8#include "sort.h" 8#include "sort.h"
9#include "units.h"
9#include "evlist.h" 10#include "evlist.h"
10#include "evsel.h" 11#include "evsel.h"
11#include "annotate.h" 12#include "annotate.h"
@@ -14,6 +15,7 @@
14#include "ui/progress.h" 15#include "ui/progress.h"
15#include <errno.h> 16#include <errno.h>
16#include <math.h> 17#include <math.h>
18#include <inttypes.h>
17#include <sys/param.h> 19#include <sys/param.h>
18 20
19static bool hists__filter_entry_by_dso(struct hists *hists, 21static bool hists__filter_entry_by_dso(struct hists *hists,
@@ -2454,6 +2456,85 @@ u64 hists__total_period(struct hists *hists)
2454 hists->stats.total_period; 2456 hists->stats.total_period;
2455} 2457}
2456 2458
2459int __hists__scnprintf_title(struct hists *hists, char *bf, size_t size, bool show_freq)
2460{
2461 char unit;
2462 int printed;
2463 const struct dso *dso = hists->dso_filter;
2464 const struct thread *thread = hists->thread_filter;
2465 int socket_id = hists->socket_filter;
2466 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
2467 u64 nr_events = hists->stats.total_period;
2468 struct perf_evsel *evsel = hists_to_evsel(hists);
2469 const char *ev_name = perf_evsel__name(evsel);
2470 char buf[512], sample_freq_str[64] = "";
2471 size_t buflen = sizeof(buf);
2472 char ref[30] = " show reference callgraph, ";
2473 bool enable_ref = false;
2474
2475 if (symbol_conf.filter_relative) {
2476 nr_samples = hists->stats.nr_non_filtered_samples;
2477 nr_events = hists->stats.total_non_filtered_period;
2478 }
2479
2480 if (perf_evsel__is_group_event(evsel)) {
2481 struct perf_evsel *pos;
2482
2483 perf_evsel__group_desc(evsel, buf, buflen);
2484 ev_name = buf;
2485
2486 for_each_group_member(pos, evsel) {
2487 struct hists *pos_hists = evsel__hists(pos);
2488
2489 if (symbol_conf.filter_relative) {
2490 nr_samples += pos_hists->stats.nr_non_filtered_samples;
2491 nr_events += pos_hists->stats.total_non_filtered_period;
2492 } else {
2493 nr_samples += pos_hists->stats.nr_events[PERF_RECORD_SAMPLE];
2494 nr_events += pos_hists->stats.total_period;
2495 }
2496 }
2497 }
2498
2499 if (symbol_conf.show_ref_callgraph &&
2500 strstr(ev_name, "call-graph=no"))
2501 enable_ref = true;
2502
2503 if (show_freq)
2504 scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq);
2505
2506 nr_samples = convert_unit(nr_samples, &unit);
2507 printed = scnprintf(bf, size,
2508 "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64,
2509 nr_samples, unit, evsel->nr_members > 1 ? "s" : "",
2510 ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events);
2511
2512
2513 if (hists->uid_filter_str)
2514 printed += snprintf(bf + printed, size - printed,
2515 ", UID: %s", hists->uid_filter_str);
2516 if (thread) {
2517 if (hists__has(hists, thread)) {
2518 printed += scnprintf(bf + printed, size - printed,
2519 ", Thread: %s(%d)",
2520 (thread->comm_set ? thread__comm_str(thread) : ""),
2521 thread->tid);
2522 } else {
2523 printed += scnprintf(bf + printed, size - printed,
2524 ", Thread: %s",
2525 (thread->comm_set ? thread__comm_str(thread) : ""));
2526 }
2527 }
2528 if (dso)
2529 printed += scnprintf(bf + printed, size - printed,
2530 ", DSO: %s", dso->short_name);
2531 if (socket_id > -1)
2532 printed += scnprintf(bf + printed, size - printed,
2533 ", Processor Socket: %d", socket_id);
2534
2535 return printed;
2536}
2537
2457int parse_filter_percentage(const struct option *opt __maybe_unused, 2538int parse_filter_percentage(const struct option *opt __maybe_unused,
2458 const char *arg, int unset __maybe_unused) 2539 const char *arg, int unset __maybe_unused)
2459{ 2540{