[PATCH RFC 03/10] perf,tools: support option --socket

From: kan . liang
Date: Tue Aug 18 2015 - 12:41:56 EST


From: Kan Liang <kan.liang@xxxxxxxxx>

Introduce a new option for perf report to show the event information in
the same socket together.
When this option is set, perf report will force to sort by socket.

$ perf report --stdio --socket
# To display the perf.data header info, please use
--header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 686 of event 'cycles'
# Event count (approx.): 349215462
#
#
# Socket: 0
#
# Overhead Command Shared Object Symbol
# ........ ......... ................
.................................
#
97.05% test test [.] plusB_c
0.98% test test [.] plusA_c
0.16% test [kernel.vmlinux] [k] add_mm_counter_fast
0.15% swapper [kernel.vmlinux] [k] note_gp_changes
0.15% perf [kernel.vmlinux] [k] unmap_single_vma
0.06% perf [kernel.vmlinux] [k] run_timer_softirq
0.00% swapper [kernel.vmlinux] [k] native_write_msr
#
# Socket: 1
#
# Overhead Command Shared Object Symbol
# ........ ......... ................
.................................
#
0.93% perf [kernel.vmlinux] [k] smp_call_function_single
0.19% perf [kernel.vmlinux] [k] page_fault
0.19% swapper [kernel.vmlinux] [k] pm_qos_request
0.12% rcu_sched [kernel.vmlinux] [k]
dyntick_save_progress_counter
0.00% swapper [kernel.vmlinux] [k] wake_up_process
0.00% swapper [kernel.vmlinux] [k] __do_softirq
0.00% swapper [kernel.vmlinux] [k] run_timer_softirq
0.00% swapper [kernel.vmlinux] [k] native_write_msr
0.00% perf [kernel.vmlinux] [k] native_write_msr

Signed-off-by: Kan Liang <kan.liang@xxxxxxxxx>
---
tools/perf/Documentation/perf-report.txt | 3 +++
tools/perf/builtin-diff.c | 2 +-
tools/perf/builtin-report.c | 17 ++++++++++++++++-
tools/perf/builtin-top.c | 2 +-
tools/perf/ui/stdio/hist.c | 14 ++++++++++----
tools/perf/util/cpumap.c | 14 ++++++++++++++
tools/perf/util/cpumap.h | 2 ++
tools/perf/util/hist.h | 2 +-
tools/perf/util/sort.c | 6 ++++++
tools/perf/util/symbol.h | 1 +
10 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index ca76b0d..49a42e4 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -293,6 +293,9 @@ OPTIONS
--group::
Show event group information together.

+--socket::
+ Show event information in the same socket together.
+
--demangle::
Demangle symbol names to human readable form. It's enabled by default,
disable with --no-demangle.
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 0b180a8..0dfd91f 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -667,7 +667,7 @@ static void hists__process(struct hists *hists)
hists__precompute(hists);
hists__output_resort(hists, NULL);

- hists__fprintf(hists, true, 0, 0, 0, stdout);
+ hists__fprintf(hists, true, 0, 0, 0, stdout, -1);
}

static void data__fprintf(void)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 62b285e..6fdf9f4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -345,7 +345,17 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
continue;

hists__fprintf_nr_sample_events(hists, rep, evname, stdout);
- hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout);
+
+ if (symbol_conf.socket) {
+ int i;
+
+ for (i = 0; i < max_socket_num; i++) {
+ fprintf(stdout, "#\n# Socket: %d\n#\n", i);
+ hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout, i);
+ }
+ } else
+ hists__fprintf(hists, true, 0, 0, rep->min_percent, stdout, -1);
+
fprintf(stdout, "\n\n");
}

@@ -724,6 +734,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
"Show a column with the sum of periods"),
OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
"Show event group information together"),
+ OPT_BOOLEAN(0, "socket", &symbol_conf.socket,
+ "Show event information in the same socket together"),
OPT_CALLBACK_NOOPT('b', "branch-stack", &branch_mode, "",
"use branch records for per branch histogram filling",
parse_branch_mode),
@@ -909,6 +921,9 @@ repeat:

sort__setup_elide(stdout);

+ if (symbol_conf.socket)
+ set_max_socket_num();
+
ret = __cmd_report(&report);
if (ret == K_SWITCH_INPUT_DATA) {
perf_session__delete(session);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index bfe24f1..deffe44 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -295,7 +295,7 @@ static void perf_top__print_sym_table(struct perf_top *top)
hists__output_recalc_col_len(hists, top->print_entries - printed);
putchar('\n');
hists__fprintf(hists, false, top->print_entries - printed, win_width,
- top->min_percent, stdout);
+ top->min_percent, stdout, -1);
}

static void prompt_integer(int *target, const char *msg)
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index dfcbc90..2f512b8 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -323,7 +323,8 @@ static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
return 0;

perf_hpp__for_each_format(fmt) {
- if (perf_hpp__should_skip(fmt))
+ if (perf_hpp__should_skip(fmt) ||
+ !strcmp(fmt->name, "SOCKET"))
continue;

/*
@@ -371,7 +372,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
}

size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
- int max_cols, float min_pcnt, FILE *fp)
+ int max_cols, float min_pcnt, FILE *fp, int socket)
{
struct perf_hpp_fmt *fmt;
struct rb_node *nd;
@@ -402,7 +403,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
fprintf(fp, "# ");

perf_hpp__for_each_format(fmt) {
- if (perf_hpp__should_skip(fmt))
+ if (perf_hpp__should_skip(fmt) ||
+ !strcmp(fmt->name, "SOCKET"))
continue;

if (!first)
@@ -428,7 +430,8 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
perf_hpp__for_each_format(fmt) {
unsigned int i;

- if (perf_hpp__should_skip(fmt))
+ if (perf_hpp__should_skip(fmt) ||
+ !strcmp(fmt->name, "SOCKET"))
continue;

if (!first)
@@ -465,6 +468,9 @@ print_entries:
if (h->filtered)
continue;

+ if ((socket >= 0) && (cpu__get_socket(h->cpu) != socket))
+ continue;
+
percent = hist_entry__get_percent_limit(h);
if (percent < min_pcnt)
continue;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 7f25e6c..ae03426 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -407,6 +407,20 @@ out:
pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num);
}

+void set_max_socket_num(void)
+{
+ int cpu, socket;
+
+ set_max_cpu_num();
+
+ max_socket_num = 1;
+ for (cpu = 0; cpu < max_cpu_num; cpu++) {
+ socket = cpu__get_socket(cpu);
+ if (max_socket_num < (socket + 1))
+ max_socket_num = socket + 1;
+ }
+}
+
/* Determine highest possible node in the system for sparse allocation */
static void set_max_node_num(void)
{
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index effb56e..094edd9 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -56,9 +56,11 @@ static inline bool cpu_map__empty(const struct cpu_map *map)

int max_cpu_num;
int max_node_num;
+int max_socket_num;
int *cpunode_map;

int cpu__setup_cpunode_map(void);
+void set_max_socket_num(void);

static inline int cpu__max_node(void)
{
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index af80fb5..b188a62 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -139,7 +139,7 @@ void events_stats__inc(struct events_stats *stats, u32 type);
size_t events_stats__fprintf(struct events_stats *stats, FILE *fp);

size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
- int max_cols, float min_pcnt, FILE *fp);
+ int max_cols, float min_pcnt, FILE *fp, int socket);
size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp);

void hists__filter_by_dso(struct hists *hists);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 245e254..70f0526 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1930,6 +1930,12 @@ int setup_sorting(void)
return err;
}

+ if (symbol_conf.socket) {
+ err = sort_dimension__add("socket");
+ if (err < 0)
+ return err;
+ }
+
reset_dimensions();

/*
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index a4cde92..7c153c7 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -101,6 +101,7 @@ struct symbol_conf {
annotate_asm_raw,
annotate_src,
event_group,
+ socket,
demangle,
demangle_kernel,
filter_relative,
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/