Commit 06466212 authored by Ingo Molnar's avatar Ingo Molnar

Merge tag 'perf-core-for-mingo-20160224' of...

Merge tag 'perf-core-for-mingo-20160224' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core improvements from Arnaldo Carvalho de Melo:

User visible changes:

  - Hierarchy histogram mode for 'perf top' and 'perf report', showing multiple
    levels, one per --sort entry: (Namhyung Kim)

    On a mostly idle system:

    # perf top --hierarchy -s comm,dso

    Then expand some levels and use 'P' to take a snapshot:

    # cat perf.hist.0
    -  92.32%         perf
          58.20%         perf
          22.29%         libc-2.22.so
           5.97%         [kernel]
           4.18%         libelf-0.165.so
           1.69%         [unknown]
    -   4.71%         qemu-system-x86
           3.10%         [kernel]
           1.60%         qemu-system-x86_64 (deleted)
    +   2.97%         swapper
    #

  - Check availability of memory events in 'perf mem': (Jiri Olsa)

    On a Intel Broadwell machine:

    # perf mem record -e list
    ldlat-loads : available
    ldlat-stores: available
    #

  - Decode data_src values (e.g. perf.data files generated by 'perf mem record')
    in 'perf script': (Jiri Olsa)

    # perf script
      perf 693 [1] 4.088652: 1 cpu/mem-loads,ldlat=30/P: ffff88007d0b0f40 68100142 L1 hit|SNP None|TLB L1 or L2 hit|LCK No <SNIP>
                                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  - Print bpf-output events in 'perf script': (Wang Nan).

    # perf record -e bpf-output/no-inherit,name=evt/ -e ./test_bpf_output_3.c/map:channel.event=evt/ usleep 1000
    # perf script
       usleep  4882 21384.532523:   evt:  ffffffff810e97d1 sys_nanosleep ([kernel.kallsyms])
        BPF output: 0000: 52 61 69 73 65 20 61 20  Raise a
                    0008: 42 50 46 20 65 76 65 6e  BPF even
                    0010: 74 21 00 00              t!..
        BPF string: "Raise a BPF event!"
    #
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents c2b8d8c5 c92fcfde
......@@ -401,6 +401,9 @@ include::itrace.txt[]
--raw-trace::
When displaying traceevent output, do not use print fmt or plugins.
--hierarchy::
Enable hierarchical output.
include::callchain-overhead-calculation.txt[]
SEE ALSO
......
......@@ -233,6 +233,9 @@ Default is to monitor all CPUS.
--raw-trace::
When displaying traceevent output, do not use print fmt or plugins.
--hierarchy::
Enable hierarchy output.
INTERACTIVE PROMPTING KEYS
--------------------------
......
......@@ -27,3 +27,4 @@ Skip collecing build-id when recording: perf record -B
To change sampling frequency to 100 Hz: perf record -F 100
See assembly instructions with percentage: perf annotate <symbol>
If you prefer Intel style assembly, try: perf annotate -M intel
For hierarchical output, try: perf report --hierarchy
......@@ -40,10 +40,11 @@ static int parse_record_events(const struct option *opt,
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
struct perf_mem_event *e = &perf_mem_events[j];
fprintf(stderr, "%-20s%s",
e->tag, verbose ? "" : "\n");
if (verbose)
fprintf(stderr, " [%s]\n", e->name);
fprintf(stderr, "%-13s%-*s%s\n",
e->tag,
verbose ? 25 : 0,
verbose ? perf_mem_events__name(j) : "",
e->supported ? ": available" : "");
}
exit(0);
}
......@@ -92,8 +93,14 @@ static int __cmd_record(int argc, const char **argv, struct perf_mem *mem)
if (!perf_mem_events[j].record)
continue;
if (!perf_mem_events[j].supported) {
pr_err("failed: event '%s' not supported\n",
perf_mem_events__name(j));
return -1;
}
rec_argv[i++] = "-e";
rec_argv[i++] = perf_mem_events[j].name;
rec_argv[i++] = perf_mem_events__name(j);
};
for (j = 0; j < argc; j++, i++)
......@@ -355,6 +362,11 @@ int cmd_mem(int argc, const char **argv, const char *prefix __maybe_unused)
NULL
};
if (perf_mem_events__init()) {
pr_err("failed: memory events not supported\n");
return -1;
}
argc = parse_options_subcommand(argc, argv, mem_options, mem_subcommands,
mem_usage, PARSE_OPT_STOP_AT_NON_OPTION);
......
......@@ -811,6 +811,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
"only show processor socket that match with this filter"),
OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
"Show raw trace event output (do not use print fmt or plugins)"),
OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
"Show entries in a hierarchy"),
OPT_END()
};
struct perf_data_file file = {
......@@ -920,6 +922,21 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
symbol_conf.cumulate_callchain = false;
}
if (symbol_conf.report_hierarchy) {
/* disable incompatible options */
symbol_conf.event_group = false;
symbol_conf.cumulate_callchain = false;
if (field_order) {
pr_err("Error: --hierarchy and --fields options cannot be used together\n");
parse_options_usage(report_usage, options, "F", 1);
parse_options_usage(NULL, options, "hierarchy", 0);
goto error;
}
sort__need_collapse = true;
}
/* Force tty output for header output and per-thread stat. */
if (report.header || report.header_only || report.show_threads)
use_browser = 0;
......
......@@ -23,6 +23,7 @@
#include "util/stat.h"
#include <linux/bitmap.h>
#include "asm/bug.h"
#include "util/mem-events.h"
static char const *script_name;
static char const *generate_script_lang;
......@@ -60,6 +61,7 @@ enum perf_output_field {
PERF_OUTPUT_BRSTACKSYM = 1U << 16,
PERF_OUTPUT_DATA_SRC = 1U << 17,
PERF_OUTPUT_WEIGHT = 1U << 18,
PERF_OUTPUT_BPF_OUTPUT = 1U << 19,
};
struct output_option {
......@@ -85,6 +87,7 @@ struct output_option {
{.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM},
{.str = "data_src", .field = PERF_OUTPUT_DATA_SRC},
{.str = "weight", .field = PERF_OUTPUT_WEIGHT},
{.str = "bpf-output", .field = PERF_OUTPUT_BPF_OUTPUT},
};
/* default set to maintain compatibility with current format */
......@@ -105,7 +108,7 @@ static struct {
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
PERF_OUTPUT_PERIOD,
.invalid_fields = PERF_OUTPUT_TRACE,
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
[PERF_TYPE_SOFTWARE] = {
......@@ -115,7 +118,7 @@ static struct {
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
PERF_OUTPUT_EVNAME | PERF_OUTPUT_IP |
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
PERF_OUTPUT_PERIOD,
PERF_OUTPUT_PERIOD | PERF_OUTPUT_BPF_OUTPUT,
.invalid_fields = PERF_OUTPUT_TRACE,
},
......@@ -125,7 +128,7 @@ static struct {
.fields = PERF_OUTPUT_COMM | PERF_OUTPUT_TID |
PERF_OUTPUT_CPU | PERF_OUTPUT_TIME |
PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE,
PERF_OUTPUT_EVNAME | PERF_OUTPUT_TRACE
},
[PERF_TYPE_RAW] = {
......@@ -138,7 +141,7 @@ static struct {
PERF_OUTPUT_PERIOD | PERF_OUTPUT_ADDR |
PERF_OUTPUT_DATA_SRC | PERF_OUTPUT_WEIGHT,
.invalid_fields = PERF_OUTPUT_TRACE,
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
[PERF_TYPE_BREAKPOINT] = {
......@@ -150,7 +153,7 @@ static struct {
PERF_OUTPUT_SYM | PERF_OUTPUT_DSO |
PERF_OUTPUT_PERIOD,
.invalid_fields = PERF_OUTPUT_TRACE,
.invalid_fields = PERF_OUTPUT_TRACE | PERF_OUTPUT_BPF_OUTPUT,
},
};
......@@ -623,6 +626,84 @@ static void print_sample_flags(u32 flags)
printf(" %-4s ", str);
}
struct printer_data {
int line_no;
bool hit_nul;
bool is_printable;
};
static void
print_sample_bpf_output_printer(enum binary_printer_ops op,
unsigned int val,
void *extra)
{
unsigned char ch = (unsigned char)val;
struct printer_data *printer_data = extra;
switch (op) {
case BINARY_PRINT_DATA_BEGIN:
printf("\n");
break;
case BINARY_PRINT_LINE_BEGIN:
printf("%17s", !printer_data->line_no ? "BPF output:" :
" ");
break;
case BINARY_PRINT_ADDR:
printf(" %04x:", val);
break;
case BINARY_PRINT_NUM_DATA:
printf(" %02x", val);
break;
case BINARY_PRINT_NUM_PAD:
printf(" ");
break;
case BINARY_PRINT_SEP:
printf(" ");
break;
case BINARY_PRINT_CHAR_DATA:
if (printer_data->hit_nul && ch)
printer_data->is_printable = false;
if (!isprint(ch)) {
printf("%c", '.');
if (!printer_data->is_printable)
break;
if (ch == '\0')
printer_data->hit_nul = true;
else
printer_data->is_printable = false;
} else {
printf("%c", ch);
}
break;
case BINARY_PRINT_CHAR_PAD:
printf(" ");
break;
case BINARY_PRINT_LINE_END:
printf("\n");
printer_data->line_no++;
break;
case BINARY_PRINT_DATA_END:
default:
break;
}
}
static void print_sample_bpf_output(struct perf_sample *sample)
{
unsigned int nr_bytes = sample->raw_size;
struct printer_data printer_data = {0, false, true};
print_binary(sample->raw_data, nr_bytes, 8,
print_sample_bpf_output_printer, &printer_data);
if (printer_data.is_printable && printer_data.hit_nul)
printf("%17s \"%s\"\n", "BPF string:",
(char *)(sample->raw_data));
}
struct perf_script {
struct perf_tool tool;
struct perf_session *session;
......@@ -649,6 +730,23 @@ static int perf_evlist__max_name_len(struct perf_evlist *evlist)
return max;
}
static size_t data_src__printf(u64 data_src)
{
struct mem_info mi = { .data_src.val = data_src };
char decode[100];
char out[100];
static int maxlen;
int len;
perf_script__meminfo_scnprintf(decode, 100, &mi);
len = scnprintf(out, 100, "%16" PRIx64 " %s", data_src, decode);
if (maxlen < len)
maxlen = len;
return printf("%-*s", maxlen, out);
}
static void process_event(struct perf_script *script, union perf_event *event,
struct perf_sample *sample, struct perf_evsel *evsel,
struct addr_location *al)
......@@ -689,7 +787,7 @@ static void process_event(struct perf_script *script, union perf_event *event,
print_sample_addr(event, sample, thread, attr);
if (PRINT_FIELD(DATA_SRC))
printf("%16" PRIx64, sample->data_src);
data_src__printf(sample->data_src);
if (PRINT_FIELD(WEIGHT))
printf("%16" PRIu64, sample->weight);
......@@ -713,6 +811,9 @@ static void process_event(struct perf_script *script, union perf_event *event,
else if (PRINT_FIELD(BRSTACKSYM))
print_sample_brstacksym(event, sample, thread, attr);
if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
print_sample_bpf_output(sample);
printf("\n");
}
......
......@@ -1214,6 +1214,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
parse_branch_stack),
OPT_BOOLEAN(0, "raw-trace", &symbol_conf.raw_trace,
"Show raw trace event output (do not use print fmt or plugins)"),
OPT_BOOLEAN(0, "hierarchy", &symbol_conf.report_hierarchy,
"Show entries in a hierarchy"),
OPT_END()
};
const char * const top_usage[] = {
......@@ -1241,6 +1243,19 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
goto out_delete_evlist;
}
if (symbol_conf.report_hierarchy) {
/* disable incompatible options */
symbol_conf.event_group = false;
symbol_conf.cumulate_callchain = false;
if (field_order) {
pr_err("Error: --hierarchy and --fields options cannot be used together\n");
parse_options_usage(top_usage, options, "fields", 0);
parse_options_usage(NULL, options, "hierarchy", 0);
goto out_delete_evlist;
}
}
sort__mode = SORT_MODE__TOP;
/* display thread wants entries to be collapsed in a different tree */
sort__need_collapse = 1;
......
This diff is collapsed.
......@@ -396,6 +396,164 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
gtk_container_add(GTK_CONTAINER(window), view);
}
static void perf_gtk__add_hierarchy_entries(struct hists *hists,
struct rb_root *root,
GtkTreeStore *store,
GtkTreeIter *parent,
struct perf_hpp *hpp,
float min_pcnt)
{
int col_idx = 0;
struct rb_node *node;
struct hist_entry *he;
struct perf_hpp_fmt *fmt;
u64 total = hists__total_period(hists);
for (node = rb_first(root); node; node = rb_next(node)) {
GtkTreeIter iter;
float percent;
he = rb_entry(node, struct hist_entry, rb_node);
if (he->filtered)
continue;
percent = hist_entry__get_percent_limit(he);
if (percent < min_pcnt)
continue;
gtk_tree_store_append(store, &iter, parent);
col_idx = 0;
hists__for_each_format(hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) ||
perf_hpp__is_dynamic_entry(fmt))
break;
if (fmt->color)
fmt->color(fmt, hpp, he);
else
fmt->entry(fmt, hpp, he);
gtk_tree_store_set(store, &iter, col_idx++, hpp->buf, -1);
}
fmt = he->fmt;
if (fmt->color)
fmt->color(fmt, hpp, he);
else
fmt->entry(fmt, hpp, he);
gtk_tree_store_set(store, &iter, col_idx, rtrim(hpp->buf), -1);
if (!he->leaf) {
perf_gtk__add_hierarchy_entries(hists, &he->hroot_out,
store, &iter, hpp,
min_pcnt);
}
if (symbol_conf.use_callchain && he->leaf) {
if (callchain_param.mode == CHAIN_GRAPH_REL)
total = symbol_conf.cumulate_callchain ?
he->stat_acc->period : he->stat.period;
perf_gtk__add_callchain(&he->sorted_chain, store, &iter,
col_idx, total);
}
}
}
static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists,
float min_pcnt)
{
struct perf_hpp_fmt *fmt;
GType col_types[MAX_COLUMNS];
GtkCellRenderer *renderer;
GtkTreeStore *store;
GtkWidget *view;
int col_idx;
int nr_cols = 0;
char s[512];
char buf[512];
bool first = true;
struct perf_hpp hpp = {
.buf = s,
.size = sizeof(s),
};
hists__for_each_format(hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) ||
perf_hpp__is_dynamic_entry(fmt))
break;
col_types[nr_cols++] = G_TYPE_STRING;
}
col_types[nr_cols++] = G_TYPE_STRING;
store = gtk_tree_store_newv(nr_cols, col_types);
view = gtk_tree_view_new();
renderer = gtk_cell_renderer_text_new();
col_idx = 0;
hists__for_each_format(hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) ||
perf_hpp__is_dynamic_entry(fmt))
break;
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-1, fmt->name,
renderer, "markup",
col_idx++, NULL);
}
/* construct merged column header since sort keys share single column */
buf[0] = '\0';
hists__for_each_format(hists ,fmt) {
if (!perf_hpp__is_sort_entry(fmt) &&
!perf_hpp__is_dynamic_entry(fmt))
continue;
if (perf_hpp__should_skip(fmt, hists))
continue;
if (first)
first = false;
else
strcat(buf, " / ");
fmt->header(fmt, &hpp, hists_to_evsel(hists));
strcat(buf, rtrim(hpp.buf));
}
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
-1, buf,
renderer, "markup",
col_idx++, NULL);
for (col_idx = 0; col_idx < nr_cols; col_idx++) {
GtkTreeViewColumn *column;
column = gtk_tree_view_get_column(GTK_TREE_VIEW(view), col_idx);
gtk_tree_view_column_set_resizable(column, TRUE);
if (col_idx == 0) {
gtk_tree_view_set_expander_column(GTK_TREE_VIEW(view),
column);
}
}
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
g_object_unref(GTK_TREE_MODEL(store));
perf_gtk__add_hierarchy_entries(hists, &hists->entries, store,
NULL, &hpp, min_pcnt);
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(view), TRUE);
g_signal_connect(view, "row-activated",
G_CALLBACK(on_row_activated), NULL);
gtk_container_add(GTK_CONTAINER(window), view);
}
int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
const char *help,
struct hist_browser_timer *hbt __maybe_unused,
......@@ -463,7 +621,10 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist,
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
perf_gtk__show_hists(scrolled_window, hists, min_pcnt);
if (symbol_conf.report_hierarchy)
perf_gtk__show_hierarchy(scrolled_window, hists, min_pcnt);
else
perf_gtk__show_hists(scrolled_window, hists, min_pcnt);
tab_label = gtk_label_new(evname);
......
......@@ -514,6 +514,9 @@ void perf_hpp_list__column_register(struct perf_hpp_list *list,
void perf_hpp_list__register_sort_field(struct perf_hpp_list *list,
struct perf_hpp_fmt *format)
{
if (perf_hpp__is_sort_entry(format) || perf_hpp__is_dynamic_entry(format))
list->nr_sort_keys++;
list_add_tail(&format->sort_list, &list->sorts);
}
......
......@@ -410,6 +410,76 @@ static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
return hpp->buf - start;
}
static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
struct perf_hpp *hpp,
int nr_sort_key, struct hists *hists,
FILE *fp)
{
const char *sep = symbol_conf.field_sep;
struct perf_hpp_fmt *fmt;
char *buf = hpp->buf;
int ret, printed = 0;
bool first = true;
if (symbol_conf.exclude_other && !he->parent)
return 0;
ret = scnprintf(hpp->buf, hpp->size, "%*s", he->depth * HIERARCHY_INDENT, "");
advance_hpp(hpp, ret);
hists__for_each_format(he->hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) || perf_hpp__is_dynamic_entry(fmt))
break;
/*
* If there's no field_sep, we still need
* to display initial ' '.
*/
if (!sep || !first) {
ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
advance_hpp(hpp, ret);
} else
first = false;
if (perf_hpp__use_color() && fmt->color)
ret = fmt->color(fmt, hpp, he);
else
ret = fmt->entry(fmt, hpp, he);
ret = hist_entry__snprintf_alignment(he, hpp, fmt, ret);
advance_hpp(hpp, ret);
}
if (sep)
ret = scnprintf(hpp->buf, hpp->size, "%s", sep);
else
ret = scnprintf(hpp->buf, hpp->size, "%*s",
(nr_sort_key - 1) * HIERARCHY_INDENT + 2, "");
advance_hpp(hpp, ret);
/*
* No need to call hist_entry__snprintf_alignment() since this
* fmt is always the last column in the hierarchy mode.
*/
fmt = he->fmt;
if (perf_hpp__use_color() && fmt->color)
fmt->color(fmt, hpp, he);
else
fmt->entry(fmt, hpp, he);
printed += fprintf(fp, "%s\n", buf);
if (symbol_conf.use_callchain && he->leaf) {
u64 total = hists__total_period(hists);
printed += hist_entry_callchain__fprintf(he, total, 0, fp);
goto out;
}
out:
return printed;
}
static int hist_entry__fprintf(struct hist_entry *he, size_t size,
struct hists *hists,
char *bf, size_t bfsz, FILE *fp)
......@@ -424,6 +494,13 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
if (size == 0 || size > bfsz)
size = hpp.size = bfsz;
if (symbol_conf.report_hierarchy) {
int nr_sort = hists->hpp_list->nr_sort_keys;
return hist_entry__hierarchy_fprintf(he, &hpp, nr_sort,
hists, fp);
}
hist_entry__snprintf(he, &hpp);
ret = fprintf(fp, "%s\n", bf);
......@@ -434,6 +511,106 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
return ret;
}
static int print_hierarchy_indent(const char *sep, int nr_sort,
const char *line, FILE *fp)
{
if (sep != NULL || nr_sort < 1)
return 0;
return fprintf(fp, "%-.*s", (nr_sort - 1) * HIERARCHY_INDENT, line);
}
static int print_hierarchy_header(struct hists *hists, struct perf_hpp *hpp,
const char *sep, FILE *fp)
{
bool first = true;
int nr_sort;
unsigned width = 0;
unsigned header_width = 0;
struct perf_hpp_fmt *fmt;
nr_sort = hists->hpp_list->nr_sort_keys;
/* preserve max indent depth for column headers */
print_hierarchy_indent(sep, nr_sort, spaces, fp);
hists__for_each_format(hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) || perf_hpp__is_dynamic_entry(fmt))
break;
if (!first)
fprintf(fp, "%s", sep ?: " ");
else
first = false;
fmt->header(fmt, hpp, hists_to_evsel(hists));
fprintf(fp, "%s", hpp->buf);
}
/* combine sort headers with ' / ' */
first = true;
hists__for_each_format(hists, fmt) {
if (!perf_hpp__is_sort_entry(fmt) && !perf_hpp__is_dynamic_entry(fmt))
continue;
if (perf_hpp__should_skip(fmt, hists))
continue;
if (!first)
header_width += fprintf(fp, " / ");
else {
header_width += fprintf(fp, "%s", sep ?: " ");
first = false;
}
fmt->header(fmt, hpp, hists_to_evsel(hists));
rtrim(hpp->buf);
header_width += fprintf(fp, "%s", hpp->buf);
}
/* preserve max indent depth for combined sort headers */
print_hierarchy_indent(sep, nr_sort, spaces, fp);
fprintf(fp, "\n# ");
/* preserve max indent depth for initial dots */
print_hierarchy_indent(sep, nr_sort, dots, fp);
first = true;
hists__for_each_format(hists, fmt) {
if (perf_hpp__is_sort_entry(fmt) || perf_hpp__is_dynamic_entry(fmt))
break;
if (!first)
fprintf(fp, "%s", sep ?: " ");
else
first = false;
width = fmt->width(fmt, hpp, hists_to_evsel(hists));
fprintf(fp, "%.*s", width, dots);
}
hists__for_each_format(hists, fmt) {
if (!perf_hpp__is_sort_entry(fmt) && !perf_hpp__is_dynamic_entry(fmt))
continue;
if (perf_hpp__should_skip(fmt, hists))
continue;
width = fmt->width(fmt, hpp, hists_to_evsel(hists));
if (width > header_width)
header_width = width;
}
fprintf(fp, "%s%-.*s", sep ?: " ", header_width, dots);
/* preserve max indent depth for dots under sort headers */
print_hierarchy_indent(sep, nr_sort, dots, fp);
fprintf(fp, "\n#\n");
return 2;
}
size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
int max_cols, float min_pcnt, FILE *fp)
{
......@@ -465,6 +642,11 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
fprintf(fp, "# ");
if (symbol_conf.report_hierarchy) {
nr_rows += print_hierarchy_header(hists, &dummy_hpp, sep, fp);
goto print_entries;
}
hists__for_each_format(hists, fmt) {
if (perf_hpp__should_skip(fmt, hists))
continue;
......@@ -522,7 +704,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
goto out;
}
for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
for (nd = rb_first(&hists->entries); nd; nd = __rb_hierarchy_next(nd, HMD_FORCE_CHILD)) {
struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
float percent;
......
......@@ -31,9 +31,18 @@ unsigned char sane_ctype[256] = {
};
const char *graph_line =
"_____________________________________________________________________"
"_____________________________________________________________________"
"_____________________________________________________________________";
const char *graph_dotted_line =
"---------------------------------------------------------------------"
"---------------------------------------------------------------------"
"---------------------------------------------------------------------";
const char *spaces =
" "
" "
" ";
const char *dots =
"....................................................................."
"....................................................................."
".....................................................................";
......@@ -106,40 +106,61 @@ int dump_printf(const char *fmt, ...)
return ret;
}
static void trace_event_printer(enum binary_printer_ops op,
unsigned int val, void *extra)
{
const char *color = PERF_COLOR_BLUE;
union perf_event *event = (union perf_event *)extra;
unsigned char ch = (unsigned char)val;
switch (op) {
case BINARY_PRINT_DATA_BEGIN:
printf(".");
color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
event->header.size);
break;
case BINARY_PRINT_LINE_BEGIN:
printf(".");
break;
case BINARY_PRINT_ADDR:
color_fprintf(stdout, color, " %04x: ", val);
break;
case BINARY_PRINT_NUM_DATA:
color_fprintf(stdout, color, " %02x", val);
break;
case BINARY_PRINT_NUM_PAD:
color_fprintf(stdout, color, " ");
break;
case BINARY_PRINT_SEP:
color_fprintf(stdout, color, " ");
break;
case BINARY_PRINT_CHAR_DATA:
color_fprintf(stdout, color, "%c",
isprint(ch) ? ch : '.');
break;
case BINARY_PRINT_CHAR_PAD:
color_fprintf(stdout, color, " ");
break;
case BINARY_PRINT_LINE_END:
color_fprintf(stdout, color, "\n");
break;
case BINARY_PRINT_DATA_END:
printf("\n");
break;
default:
break;
}
}
void trace_event(union perf_event *event)
{
unsigned char *raw_event = (void *)event;
const char *color = PERF_COLOR_BLUE;
int i, j;
if (!dump_trace)
return;
printf(".");
color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
event->header.size);
for (i = 0; i < event->header.size; i++) {
if ((i & 15) == 0) {
printf(".");
color_fprintf(stdout, color, " %04x: ", i);
}
color_fprintf(stdout, color, " %02x", raw_event[i]);
if (((i & 15) == 15) || i == event->header.size-1) {
color_fprintf(stdout, color, " ");
for (j = 0; j < 15-(i & 15); j++)
color_fprintf(stdout, color, " ");
for (j = i & ~15; j <= i; j++) {
color_fprintf(stdout, color, "%c",
isprint(raw_event[j]) ?
raw_event[j] : '.');
}
color_fprintf(stdout, color, "\n");
}
}
printf(".\n");
print_binary(raw_event, event->header.size, 16,
trace_event_printer, event);
}
static struct debug_variable {
......
This diff is collapsed.
......@@ -237,6 +237,7 @@ struct perf_hpp_fmt {
struct perf_hpp_list {
struct list_head fields;
struct list_head sorts;
int nr_sort_keys;
};
extern struct perf_hpp_list perf_hpp_list;
......@@ -301,6 +302,11 @@ void perf_hpp__append_sort_keys(struct perf_hpp_list *list);
bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format);
bool perf_hpp__is_dynamic_entry(struct perf_hpp_fmt *format);
bool perf_hpp__defined_dynamic_entry(struct perf_hpp_fmt *fmt, struct hists *hists);
bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt);
bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt);
bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt);
int hist_entry__filter(struct hist_entry *he, int type, const void *arg);
static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format,
struct hists *hists)
......@@ -415,4 +421,22 @@ int perf_hist_config(const char *var, const char *value);
void perf_hpp_list__init(struct perf_hpp_list *list);
enum hierarchy_move_dir {
HMD_NORMAL,
HMD_FORCE_SIBLING,
HMD_FORCE_CHILD,
};
struct rb_node *rb_hierarchy_last(struct rb_node *node);
struct rb_node *__rb_hierarchy_next(struct rb_node *node,
enum hierarchy_move_dir hmd);
struct rb_node *rb_hierarchy_prev(struct rb_node *node);
static inline struct rb_node *rb_hierarchy_next(struct rb_node *node)
{
return __rb_hierarchy_next(node, HMD_NORMAL);
}
#define HIERARCHY_INDENT 3
#endif /* __PERF_HIST_H */
......@@ -2,18 +2,29 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <api/fs/fs.h>
#include "mem-events.h"
#include "debug.h"
#include "symbol.h"
#define E(t, n) { .tag = t, .name = n }
#define E(t, n, s) { .tag = t, .name = n, .sysfs_name = s }
struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
E("ldlat-loads", "cpu/mem-loads,ldlat=30/P"),
E("ldlat-stores", "cpu/mem-stores/P"),
E("ldlat-loads", "cpu/mem-loads,ldlat=30/P", "mem-loads"),
E("ldlat-stores", "cpu/mem-stores/P", "mem-stores"),
};
#undef E
#undef E
char *perf_mem_events__name(int i)
{
return (char *)perf_mem_events[i].name;
}
int perf_mem_events__parse(const char *str)
{
char *tok, *saveptr = NULL;
......@@ -49,3 +60,196 @@ int perf_mem_events__parse(const char *str)
pr_err("failed: event '%s' not found, use '-e list' to get list of available events\n", str);
return -1;
}
int perf_mem_events__init(void)
{
const char *mnt = sysfs__mount();
bool found = false;
int j;
if (!mnt)
return -ENOENT;
for (j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
char path[PATH_MAX];
struct perf_mem_event *e = &perf_mem_events[j];
struct stat st;
scnprintf(path, PATH_MAX, "%s/devices/cpu/events/%s",
mnt, e->sysfs_name);
if (!stat(path, &st))
e->supported = found = true;
}
return found ? 0 : -ENOENT;
}
static const char * const tlb_access[] = {
"N/A",
"HIT",
"MISS",
"L1",
"L2",
"Walker",
"Fault",
};
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
size_t l = 0, i;
u64 m = PERF_MEM_TLB_NA;
u64 hit, miss;
sz -= 1; /* -1 for null termination */
out[0] = '\0';
if (mem_info)
m = mem_info->data_src.mem_dtlb;
hit = m & PERF_MEM_TLB_HIT;
miss = m & PERF_MEM_TLB_MISS;
/* already taken care of */
m &= ~(PERF_MEM_TLB_HIT|PERF_MEM_TLB_MISS);
for (i = 0; m && i < ARRAY_SIZE(tlb_access); i++, m >>= 1) {
if (!(m & 0x1))
continue;
if (l) {
strcat(out, " or ");
l += 4;
}
l += scnprintf(out + l, sz - l, tlb_access[i]);
}
if (*out == '\0')
l += scnprintf(out, sz - l, "N/A");
if (hit)
l += scnprintf(out + l, sz - l, " hit");
if (miss)
l += scnprintf(out + l, sz - l, " miss");
return l;
}
static const char * const mem_lvl[] = {
"N/A",
"HIT",
"MISS",
"L1",
"LFB",
"L2",
"L3",
"Local RAM",
"Remote RAM (1 hop)",
"Remote RAM (2 hops)",
"Remote Cache (1 hop)",
"Remote Cache (2 hops)",
"I/O",
"Uncached",
};
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
size_t i, l = 0;
u64 m = PERF_MEM_LVL_NA;
u64 hit, miss;
if (mem_info)
m = mem_info->data_src.mem_lvl;
sz -= 1; /* -1 for null termination */
out[0] = '\0';
hit = m & PERF_MEM_LVL_HIT;
miss = m & PERF_MEM_LVL_MISS;
/* already taken care of */
m &= ~(PERF_MEM_LVL_HIT|PERF_MEM_LVL_MISS);
for (i = 0; m && i < ARRAY_SIZE(mem_lvl); i++, m >>= 1) {
if (!(m & 0x1))
continue;
if (l) {
strcat(out, " or ");
l += 4;
}
l += scnprintf(out + l, sz - l, mem_lvl[i]);
}
if (*out == '\0')
l += scnprintf(out, sz - l, "N/A");
if (hit)
l += scnprintf(out + l, sz - l, " hit");
if (miss)
l += scnprintf(out + l, sz - l, " miss");
return l;
}
static const char * const snoop_access[] = {
"N/A",
"None",
"Miss",
"Hit",
"HitM",
};
int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
size_t i, l = 0;
u64 m = PERF_MEM_SNOOP_NA;
sz -= 1; /* -1 for null termination */
out[0] = '\0';
if (mem_info)
m = mem_info->data_src.mem_snoop;
for (i = 0; m && i < ARRAY_SIZE(snoop_access); i++, m >>= 1) {
if (!(m & 0x1))
continue;
if (l) {
strcat(out, " or ");
l += 4;
}
l += scnprintf(out + l, sz - l, snoop_access[i]);
}
if (*out == '\0')
l += scnprintf(out, sz - l, "N/A");
return l;
}
int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
u64 mask = PERF_MEM_LOCK_NA;
int l;
if (mem_info)
mask = mem_info->data_src.mem_lock;
if (mask & PERF_MEM_LOCK_NA)
l = scnprintf(out, sz, "N/A");
else if (mask & PERF_MEM_LOCK_LOCKED)
l = scnprintf(out, sz, "Yes");
else
l = scnprintf(out, sz, "No");
return l;
}
int perf_script__meminfo_scnprintf(char *out, size_t sz, struct mem_info *mem_info)
{
int i = 0;
i += perf_mem__lvl_scnprintf(out, sz, mem_info);
i += scnprintf(out + i, sz - i, "|SNP ");
i += perf_mem__snp_scnprintf(out + i, sz - i, mem_info);
i += scnprintf(out + i, sz - i, "|TLB ");
i += perf_mem__tlb_scnprintf(out + i, sz - i, mem_info);
i += scnprintf(out + i, sz - i, "|LCK ");
i += perf_mem__lck_scnprintf(out + i, sz - i, mem_info);
return i;
}
......@@ -5,8 +5,10 @@
struct perf_mem_event {
bool record;
bool supported;
const char *tag;
const char *name;
const char *sysfs_name;
};
enum {
......@@ -18,5 +20,16 @@ enum {
extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX];
int perf_mem_events__parse(const char *str);
int perf_mem_events__init(void);
char *perf_mem_events__name(int i);
struct mem_info;
int perf_mem__tlb_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
int perf_mem__lvl_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
int perf_mem__snp_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
int perf_mem__lck_scnprintf(char *out, size_t sz, struct mem_info *mem_info);
int perf_script__meminfo_scnprintf(char *bf, size_t size, struct mem_info *mem_info);
#endif /* __PERF_MEM_EVENTS_H */
This diff is collapsed.
......@@ -96,9 +96,11 @@ struct hist_entry {
s32 socket;
s32 cpu;
u8 cpumode;
u8 depth;
/* We are added by hists__add_dummy_entry. */
bool dummy;
bool leaf;
char level;
u8 filtered;
......@@ -120,13 +122,22 @@ struct hist_entry {
char *srcline;
char *srcfile;
struct symbol *parent;
struct rb_root sorted_chain;
struct branch_info *branch_info;
struct hists *hists;
struct mem_info *mem_info;
void *raw_data;
u32 raw_size;
void *trace_output;
struct perf_hpp_fmt *fmt;
struct hist_entry *parent_he;
union {
/* this is for hierarchical entry structure */
struct {
struct rb_root hroot_in;
struct rb_root hroot_out;
}; /* non-leaf entries */
struct rb_root sorted_chain; /* leaf entry has callchains */
};
struct callchain_root callchain[0]; /* must be last member */
};
......@@ -234,6 +245,7 @@ struct sort_entry {
int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
unsigned int width);
int (*se_filter)(struct hist_entry *he, int type, const void *arg);
u8 se_width_idx;
};
......
......@@ -110,7 +110,8 @@ struct symbol_conf {
has_filter,
show_ref_callgraph,
hide_unresolved,
raw_trace;
raw_trace,
report_hierarchy;
const char *vmlinux_name,
*kallsyms_name,
*source_prefix,
......
......@@ -14,6 +14,7 @@
#include <limits.h>
#include <byteswap.h>
#include <linux/kernel.h>
#include <linux/log2.h>
#include <unistd.h>
#include "callchain.h"
#include "strlist.h"
......@@ -670,3 +671,39 @@ int fetch_current_timestamp(char *buf, size_t sz)
return 0;
}
void print_binary(unsigned char *data, size_t len,
size_t bytes_per_line, print_binary_t printer,
void *extra)
{
size_t i, j, mask;
if (!printer)
return;
bytes_per_line = roundup_pow_of_two(bytes_per_line);
mask = bytes_per_line - 1;
printer(BINARY_PRINT_DATA_BEGIN, 0, extra);
for (i = 0; i < len; i++) {
if ((i & mask) == 0) {
printer(BINARY_PRINT_LINE_BEGIN, -1, extra);
printer(BINARY_PRINT_ADDR, i, extra);
}
printer(BINARY_PRINT_NUM_DATA, data[i], extra);
if (((i & mask) == mask) || i == len - 1) {
for (j = 0; j < mask-(i & mask); j++)
printer(BINARY_PRINT_NUM_PAD, -1, extra);
printer(BINARY_PRINT_SEP, i, extra);
for (j = i & ~mask; j <= i; j++)
printer(BINARY_PRINT_CHAR_DATA, data[j], extra);
for (j = 0; j < mask-(i & mask); j++)
printer(BINARY_PRINT_CHAR_PAD, i, extra);
printer(BINARY_PRINT_LINE_END, -1, extra);
}
}
printer(BINARY_PRINT_DATA_END, -1, extra);
}
......@@ -82,6 +82,8 @@
extern const char *graph_line;
extern const char *graph_dotted_line;
extern const char *spaces;
extern const char *dots;
extern char buildid_dir[];
/* On most systems <limits.h> would have given us this, but
......@@ -345,4 +347,24 @@ const char *perf_tip(const char *dirpath);
bool is_regular_file(const char *file);
int fetch_current_timestamp(char *buf, size_t sz);
enum binary_printer_ops {
BINARY_PRINT_DATA_BEGIN,
BINARY_PRINT_LINE_BEGIN,
BINARY_PRINT_ADDR,
BINARY_PRINT_NUM_DATA,
BINARY_PRINT_NUM_PAD,
BINARY_PRINT_SEP,
BINARY_PRINT_CHAR_DATA,
BINARY_PRINT_CHAR_PAD,
BINARY_PRINT_LINE_END,
BINARY_PRINT_DATA_END,
};
typedef void (*print_binary_t)(enum binary_printer_ops,
unsigned int val,
void *extra);
void print_binary(unsigned char *data, size_t len,
size_t bytes_per_line, print_binary_t printer,
void *extra);
#endif /* GIT_COMPAT_UTIL_H */
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