perf: Add duration_time to perf stat
Currently it's not possible to get the wall clock time of a measurement in CSV mode output, it's only in the non CSV perf stat output. Often this is needed to normalize event counts to time.
Add a new duration_time event that can be specified and reports the wall clock time in ns.
PATCH 1/4 perf, tools: Revert checks for duration_time
From: Andi Kleen <[email protected]>
This reverts e864c5ca145e perf stat: Hide internal duration_time counter but doing it manually since the code has now moved to a different file.
The next patch will properly implement duration_time as a full event, so no need to hide it anymore.
--- tools/perf/util/stat-display.c | 18 ------------------ 1 file changed, 18 deletions(-)
tools/perf/util/stat-display.c +0 -18
@@ -18,11 +18,6 @@#define CNTR_NOT_SUPPORTED "<not supported>"#define CNTR_NOT_COUNTED "<not counted>" -static bool is_duration_time (struct perf_evsel *evsel) -{ -return !strcmp (evsel->name,"duration_time" ); -} -static void print_running (struct perf_stat_config *config,u64 run,u64 ena) {
@@ -628,9 +623,6 @@ static void print_aggr(struct perf_stat_config *config, ad.id = id = config->aggr_map->map[s]; first = true;evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ; - ad.val = ad.ena = ad.run =0 ; ad.nr =0 ;if (!collect_data (config, counter, aggr_cb, &ad))
@@ -848,8 +840,6 @@ static void print_no_aggr_metric(struct perf_stat_config *config,if (prefix)fputs (prefix, config->output);evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;if (first) {aggr_printout (config, counter, cpu,0 ); first = false;
@@ -906,8 +896,6 @@ static void print_metric_headers(struct perf_stat_config *config,/* Print metrics headers only */ evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ; os.evsel = counter; out.ctx = &os; out.print_metric = print_metric_header;
@@ -1136,15 +1124,11 @@ perf_evlist__print_counters(struct perf_evlist *evlist,break ;case AGGR_THREAD :evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_aggr_thread (config, _target, counter, prefix); }break ;case AGGR_GLOBAL :evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_counter_aggr (config, counter, prefix); }if (metric_only)
@@ -1155,8 +1139,6 @@ perf_evlist__print_counters(struct perf_evlist *evlist,print_no_aggr_metric (config, evlist, prefix); else {evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_counter (config, counter, prefix); } }
Signature · 1 line
2.20.1
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf stat: Revert checks for duration_time
perf stat: Revert checks for duration_time
Commit-ID: c2b3c170db610896e4e633cba2135045333811c2 Gitweb: https://git.kernel.org/tip/c2b3c170db610896e4e633cba2135045333811c2 Author: Andi Kleen <[email protected]> AuthorDate: Tue, 26 Mar 2019 15:18:20 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 1 Apr 2019 14:49:24 -0300
perf stat: Revert checks for duration_time
This reverts e864c5ca145e ("perf stat: Hide internal duration_time counter") but doing it manually since the code has now moved to a different file.
The next patch will properly implement duration_time as a full event, so no need to hide it anymore.
--- tools/perf/util/stat-display.c | 18 ------------------ 1 file changed, 18 deletions(-)
tools/perf/util/stat-display.c +0 -18
@@ -18,11 +18,6 @@#define CNTR_NOT_SUPPORTED "<not supported>"#define CNTR_NOT_COUNTED "<not counted>" -static bool is_duration_time (struct perf_evsel *evsel) -{ -return !strcmp (evsel->name,"duration_time" ); -} -static void print_running (struct perf_stat_config *config,u64 run,u64 ena) {
@@ -628,9 +623,6 @@ static void print_aggr(struct perf_stat_config *config, ad.id = id = config->aggr_map->map[s]; first = true;evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ; - ad.val = ad.ena = ad.run =0 ; ad.nr =0 ;if (!collect_data (config, counter, aggr_cb, &ad))
@@ -848,8 +840,6 @@ static void print_no_aggr_metric(struct perf_stat_config *config,if (prefix)fputs (prefix, config->output);evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;if (first) {aggr_printout (config, counter, cpu,0 ); first = false;
@@ -906,8 +896,6 @@ static void print_metric_headers(struct perf_stat_config *config,/* Print metrics headers only */ evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ; os.evsel = counter; out.ctx = &os; out.print_metric = print_metric_header;
@@ -1136,15 +1124,11 @@ perf_evlist__print_counters(struct perf_evlist *evlist,break ;case AGGR_THREAD :evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_aggr_thread (config, _target, counter, prefix); }break ;case AGGR_GLOBAL :evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_counter_aggr (config, counter, prefix); }if (metric_only)
@@ -1155,8 +1139,6 @@ perf_evlist__print_counters(struct perf_evlist *evlist,print_no_aggr_metric (config, evlist, prefix); else {evlist__for_each_entry (evlist, counter) { -if (is_duration_time (counter)) -continue ;print_counter (config, counter, prefix); } }
PATCH 2/4 perf, tools: Implement duration_time as a proper event
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
The perf metric expression use duration_time internally to normalize events. Normal perf stat without -x also prints the duration time. But when using -x, the interval is not output anywhere, which is inconvenient for any post processing which often wants to normalize values to time.
So implement duration_time as a proper perf event that can be specified explicitely with -e.
The previous implementation of duration_time only worked for metric processing. This adds the concept of a tool event that is handled by the tool. On the kernel level it is still mapped to the dummy software event, but the values are not read anymore, but instead computed by the tool.
Add proper plumbing to handle this in the event parser,
and display it in perf stat. We don't want duration_time to be added up, so it's only printed for the first CPU.
% perf stat -e duration_time,cycles true
Performance counter stats for 'true':
555,476 ns duration_time
771,958 cycles
0.000555476 seconds time elapsed
0.000644000 seconds user
0.000000000 seconds sys--- tools/perf/builtin-stat.c | 28 ++++++++++++++++++------- tools/perf/util/evsel.h | 6 ++++++ tools/perf/util/parse-events.c | 38 +++++++++++++++++++++++++++++----- tools/perf/util/parse-events.h | 4 ++++ tools/perf/util/parse-events.l | 11 +++++++++- tools/perf/util/parse-events.y | 12 +++++++++++ 6 files changed, 86 insertions(+), 13 deletions(-)
tools/perf/builtin-stat.c +21 -7
@@ -244,11 +244,25 @@ perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, process_synthesized_event, NULL); } +static int read_single_counter (struct perf_evsel *counter,int cpu, +int thread,struct timespec *rs) +{ +if (counter->tool_event ==PERF_TOOL_DURATION_TIME ) { +u64 val = rs->tv_nsec + rs->tv_sec*1000000000ULL ; +struct perf_counts_values *count = +perf_counts (counter->counts, cpu, thread); + count->ena = count->run = val; + count->val = val; +return 0 ; + } +return perf_evsel__read_counter (counter, cpu, thread); +} +/* * Read out the results of a single counter: * do not aggregate counts across CPUs in system-wide mode */ -static int read_counter (struct perf_evsel *counter) +static int read_counter (struct perf_evsel *counter,struct timespec *rs) {int nthreads =thread_map__nr (evsel_list->threads);int ncpus, cpu, thread;
@@ -275,7 +289,7 @@ static int read_counter(struct perf_evsel *counter)* (via perf_evsel__read_counter) and sets threir count->loaded. */ if (!count->loaded && -perf_evsel__read_counter (counter, cpu, thread)) { +read_single_counter (counter, cpu, thread, rs)) { counter->counts->scaled =-1 ;perf_counts (counter->counts, cpu, thread)->ena =0 ;perf_counts (counter->counts, cpu, thread)->run =0 ;
@@ -304,13 +318,13 @@ static int read_counter(struct perf_evsel *counter)return 0 ; } -static void read_counters (void ) +static void read_counters (struct timespec *rs) {struct perf_evsel *counter;int ret;evlist__for_each_entry (evsel_list, counter) { - ret =read_counter (counter); + ret =read_counter (counter, rs);if (ret)pr_debug ("failed to read counter %s\n" , counter->name);
@@ -323,11 +337,11 @@ static void process_interval(void) {struct timespec ts, rs; -read_counters (); -clock_gettime (CLOCK_MONOTONIC , &ts);diff_timespec (&rs, &ts, &ref_time); +read_counters (&rs); +if (STAT_RECORD ) {if (WRITE_STAT_ROUND_EVENT (rs.tv_sec *NSEC_PER_SEC + rs.tv_nsec,INTERVAL ))pr_err ("failed to write stat round event\n" );
@@ -593,7 +607,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)* avoid arbitrary skew, we must read all counters before closing any * group leaders. */ -read_counters (); +read_counters (&(struct timespec ) { .tv_nsec = t1-t0 });perf_evlist__close (evsel_list);return WEXITSTATUS (status);
tools/perf/util/evsel.h +6 -0
@@ -75,6 +75,11 @@ struct perf_stat_evsel;typedef int (perf_evsel__sb_cb_t )(union perf_event *event,void *data); +enum perf_tool_event { +PERF_TOOL_NONE =0 , +PERF_TOOL_DURATION_TIME =1 , +}; +/** struct perf_evsel - event selector * * @evlist - evlist this evsel is in, if it is in one.
@@ -121,6 +126,7 @@ struct perf_evsel {unsigned int sample_size;int id_pos;int is_pos; +enum perf_tool_event tool_event;bool uniquified_name;bool snapshot;bool supported;
tools/perf/util/parse-events.c +33 -5
@@ -317,10 +317,12 @@ static struct perf_evsel * __add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, char *name, struct perf_pmu *pmu, - struct list_head *config_terms, bool auto_merge_stats) + struct list_head *config_terms, bool auto_merge_stats, + const char *cpu_list) { struct perf_evsel *evsel; -struct cpu_map *cpus = pmu ? pmu->cpus :NULL ; +struct cpu_map *cpus = pmu ? pmu->cpus : + cpu_list ?cpu_map__new (cpu_list) :NULL ;event_attr_init (attr);
@@ -348,7 +350,25 @@ static int add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, char *name, struct list_head *config_terms) { - return __add_event(list, idx, attr, name, NULL, config_terms, false) ? 0 : -ENOMEM; + return __add_event(list, idx, attr, name, NULL, config_terms, false, NULL) ? 0 : -ENOMEM; +} + +static int add_event_tool (struct list_head *list,int *idx, +enum perf_tool_event tool_event) +{ +struct perf_evsel *evsel; +struct perf_event_attr attr = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_DUMMY , + }; + + evsel =__add_event (list, idx, &attr,NULL ,NULL ,NULL , false,"0" ); +if (!evsel) +return -ENOMEM ; + evsel->tool_event = tool_event; +if (tool_event ==PERF_TOOL_DURATION_TIME ) + evsel->unit =strdup ("ns" ); +return 0 ; }static int parse_aliases (char *str,const char *names[][PERF_EVSEL__MAX_ALIASES ],int size)
@@ -1233,6 +1253,13 @@ int parse_events_add_numeric(struct parse_events_state *parse_state, get_config_name(head_config), &config_terms); } +int parse_events_add_tool (struct parse_events_state *parse_state, +struct list_head *list, +enum perf_tool_event tool_event) +{ +return add_event_tool (list, &parse_state->idx, tool_event); +} + int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, char *name, struct list_head *head_config,
@@ -1267,7 +1294,8 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,if (!head_config) { attr.type = pmu->type; - evsel =__add_event (list, &parse_state->idx, &attr,NULL , pmu,NULL , auto_merge_stats); + evsel =__add_event (list, &parse_state->idx, &attr,NULL , pmu,NULL , + auto_merge_stats,NULL );if (evsel) { evsel->pmu_name = name; evsel->use_uncore_alias = use_uncore_alias;
@@ -1295,7 +1323,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, evsel =__add_event (list, &parse_state->idx, &attr,get_config_name (head_config), pmu, - &config_terms, auto_merge_stats); + &config_terms, auto_merge_stats,NULL );if (evsel) { evsel->unit = info.unit; evsel->scale = info.scale;
tools/perf/util/parse-events.h +4 -0
@@ -160,6 +160,10 @@ int parse_events_add_numeric(struct parse_events_state *parse_state,struct list_head *list, u32 type, u64 config, struct list_head *head_config); +enum perf_tool_event ; +int parse_events_add_tool (struct parse_events_state *parse_state, +struct list_head *list, +enum perf_tool_event tool_event); int parse_events_add_cache(struct list_head *list, int *idx, char *type, char *op_result1, char *op_result2, struct parse_events_error *error,
tools/perf/util/parse-events.l +10 -1
@@ -15,6 +15,7 @@ #include "../perf.h" #include "parse-events.h" #include "parse-events-bison.h" +#include "evsel.h" char *parse_events_get_text(yyscan_t yyscanner); YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
@@ -154,6 +155,14 @@ static int sym(yyscan_t scanner, int type, int config) return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; } +static int tool(yyscan_t scanner, enum perf_tool_event event) +{ + YYSTYPE *yylval = parse_events_get_lval(scanner); + + yylval->num = event; + return PE_VALUE_SYM_TOOL; +} + static int term(yyscan_t scanner, int type) { YYSTYPE *yylval = parse_events_get_lval(scanner);
@@ -322,7 +331,7 @@ cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } -duration_time { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } +duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } /*
tools/perf/util/parse-events.y +12 -0
@@ -14,6 +14,7 @@ #include <linux/types.h> #include "util.h" #include "pmu.h" +#include "evsel.h" #include "debug.h" #include "parse-events.h" #include "parse-events-bison.h"
@@ -45,6 +46,7 @@ static void inc_group_count(struct list_head *list, %token PE_START_EVENTS PE_START_TERMS %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM +%token PE_VALUE_SYM_TOOL %token PE_EVENT_NAME %token PE_NAME %token PE_BPF_OBJECT PE_BPF_SOURCE
@@ -58,6 +60,7 @@ static void inc_group_count(struct list_head *list, %type <num> PE_VALUE %type <num> PE_VALUE_SYM_HW %type <num> PE_VALUE_SYM_SW +%type <num> PE_VALUE_SYM_TOOL %type <num> PE_RAW %type <num> PE_TERM %type <str> PE_NAME
@@ -321,6 +324,15 @@ value_sym sep_slash_slash_dc ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); $$ = list; } +| +PE_VALUE_SYM_TOOL sep_slash_slash_dc +{ + struct list_head *list; + + ALLOC_LIST(list); + ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); + $$ = list; +} event_legacy_cache: PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
Signature · 1 line
2.20.1
Re: [PATCH 2/4] perf, tools: Implement duration_time as a proper event
Quoted 54 lines · Andi Kleen
From: Andi Kleen <[email protected]>
The perf metric expression use
duration_timeinternally to normalize events. Normal perf stat without -x also prints the duration time. But when using -x, the interval is not output anywhere, which is inconvenient for any post processing which often wants to normalize values to time.So implement
duration_timeas a proper perf event that can be specified explicitely with -e.The previous implementation of
duration_timeonly worked for metric processing. This adds the concept of a tool event that is handled by the tool. On the kernel level it is still mapped to the dummy software event, but the values are not read anymore, but instead computed by the tool.Add proper plumbing to handle this in the event parser,
and display it in perf stat. We don't wantduration_timeto be added up, so it's only printed for the first CPU.% perf stat -e duration_time,cycles true
Performance counter stats for 'true':
555,476 ns duration_time 771,958 cycles 0.000555476 seconds time elapsed 0.000644000 seconds user 0.000000000 seconds sysSigned-off-by Andi Kleen <[email protected]>--- tools/perf/builtin-stat.c | 28 ++++++++++++++++++------- tools/perf/util/evsel.h | 6 ++++++ tools/perf/util/parse-events.c | 38 +++++++++++++++++++++++++++++----- tools/perf/util/parse-events.h | 4 ++++ tools/perf/util/parse-events.l | 11 +++++++++- tools/perf/util/parse-events.y | 12 +++++++++++ 6 files changed, 86 insertions(+), 13 deletions(-)tools/perf/builtin-stat.c +3
-0@@ -244,11 +244,25 @@ perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, process_synthesized_event, NULL); } +static int read_single_counter (struct perf_evsel *counter,int cpu, +int thread,struct timespec *rs) +{
tools/perf/builtin-stat.c perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, · line 259
Quoted 10 lines
tools/perf/builtin-stat.c +10
-0+if (counter->tool_event ==PERF_TOOL_DURATION_TIME ) { +u64 val = rs->tv_nsec + rs->tv_sec*1000000000ULL ; +struct perf_counts_values *count = +perf_counts (counter->counts, cpu, thread); + count->ena = count->run = val; + count->val = val; +return 0 ; + } +return perf_evsel__read_counter (counter, cpu, thread); +}
so now that we have time in a separate event, we could get rid of the isolated update_stats(&walltime_nsecs_stats) calls and move them to perf_stat__update_shadow_stats?
jirka
Re: [PATCH 2/4] perf, tools: Implement duration_time as a proper event
Quoted 4 lines
so now that we have time in a separate event, we could get rid of the isolated
update_stats(&walltime_nsecs_stats)calls and move them toperf_stat__update_shadow_stats?
In theory yes, but it would require perf stat always setting up the duration_time event implicitely and then special handling.
For stat it would need to be hidden to keep the same output.
It's probably simpler to keep the old way for that.
-Andi
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf stat: Implement duration_time as a proper event
In reply to Andi Kleenperf stat: Implement duration_time as a proper event
Commit-ID: f0fbb114e3025f3f737a1e1c5c39c5b2b2e671bd Gitweb: https://git.kernel.org/tip/f0fbb114e3025f3f737a1e1c5c39c5b2b2e671bd Author: Andi Kleen <[email protected]> AuthorDate: Tue, 26 Mar 2019 15:18:21 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 1 Apr 2019 14:49:24 -0300
perf stat: Implement duration_time as a proper event
The perf metric expression use 'duration_time' internally to normalize events. Normal 'perf stat' without -x also prints the duration time. But when using -x, the interval is not output anywhere, which is inconvenient for any post processing which often wants to normalize values to time.
So implement 'duration_time' as a proper perf event that can be specified explicitely with -e.
The previous implementation of 'duration_time' only worked for metric processing. This adds the concept of a tool event that is handled by the tool. On the kernel level it is still mapped to the dummy software event, but the values are not read anymore, but instead computed by the tool.
Add proper plumbing to handle this in the event parser, and display it in 'perf stat'. We don't want 'duration_time' to be added up, so it's only printed for the first CPU.
% perf stat -e duration_time,cycles true
Performance counter stats for 'true':
555,476 ns duration_time
771,958 cycles
0.000555476 seconds time elapsed
0.000644000 seconds user
0.000000000 seconds sys--- tools/perf/builtin-stat.c | 28 +++++++++++++++++++++------- tools/perf/util/evsel.h | 6 ++++++ tools/perf/util/parse-events.c | 38 +++++++++++++++++++++++++++++++++----- tools/perf/util/parse-events.h | 4 ++++ tools/perf/util/parse-events.l | 11 ++++++++++- tools/perf/util/parse-events.y | 12 ++++++++++++ 6 files changed, 86 insertions(+), 13 deletions(-)
tools/perf/builtin-stat.c +21 -7
@@ -244,11 +244,25 @@ perf_evsel__write_stat_event(struct perf_evsel *counter, u32 cpu, u32 thread, process_synthesized_event, NULL); } +static int read_single_counter (struct perf_evsel *counter,int cpu, +int thread,struct timespec *rs) +{ +if (counter->tool_event ==PERF_TOOL_DURATION_TIME ) { +u64 val = rs->tv_nsec + rs->tv_sec*1000000000ULL ; +struct perf_counts_values *count = +perf_counts (counter->counts, cpu, thread); + count->ena = count->run = val; + count->val = val; +return 0 ; + } +return perf_evsel__read_counter (counter, cpu, thread); +} +/* * Read out the results of a single counter: * do not aggregate counts across CPUs in system-wide mode */ -static int read_counter (struct perf_evsel *counter) +static int read_counter (struct perf_evsel *counter,struct timespec *rs) {int nthreads =thread_map__nr (evsel_list->threads);int ncpus, cpu, thread;
@@ -275,7 +289,7 @@ static int read_counter(struct perf_evsel *counter)* (via perf_evsel__read_counter) and sets threir count->loaded. */ if (!count->loaded && -perf_evsel__read_counter (counter, cpu, thread)) { +read_single_counter (counter, cpu, thread, rs)) { counter->counts->scaled =-1 ;perf_counts (counter->counts, cpu, thread)->ena =0 ;perf_counts (counter->counts, cpu, thread)->run =0 ;
@@ -304,13 +318,13 @@ static int read_counter(struct perf_evsel *counter)return 0 ; } -static void read_counters (void ) +static void read_counters (struct timespec *rs) {struct perf_evsel *counter;int ret;evlist__for_each_entry (evsel_list, counter) { - ret =read_counter (counter); + ret =read_counter (counter, rs);if (ret)pr_debug ("failed to read counter %s\n" , counter->name);
@@ -323,11 +337,11 @@ static void process_interval(void) {struct timespec ts, rs; -read_counters (); -clock_gettime (CLOCK_MONOTONIC , &ts);diff_timespec (&rs, &ts, &ref_time); +read_counters (&rs); +if (STAT_RECORD ) {if (WRITE_STAT_ROUND_EVENT (rs.tv_sec *NSEC_PER_SEC + rs.tv_nsec,INTERVAL ))pr_err ("failed to write stat round event\n" );
@@ -593,7 +607,7 @@ try_again:* avoid arbitrary skew, we must read all counters before closing any * group leaders. */ -read_counters (); +read_counters (&(struct timespec ) { .tv_nsec = t1-t0 });perf_evlist__close (evsel_list);return WEXITSTATUS (status);
tools/perf/util/evsel.h +6 -0
@@ -75,6 +75,11 @@ struct perf_stat_evsel;typedef int (perf_evsel__sb_cb_t )(union perf_event *event,void *data); +enum perf_tool_event { +PERF_TOOL_NONE =0 , +PERF_TOOL_DURATION_TIME =1 , +}; +/** struct perf_evsel - event selector * * @evlist - evlist this evsel is in, if it is in one.
@@ -121,6 +126,7 @@ struct perf_evsel {unsigned int sample_size;int id_pos;int is_pos; +enum perf_tool_event tool_event;bool uniquified_name;bool snapshot;bool supported;
tools/perf/util/parse-events.c +33 -5
@@ -317,10 +317,12 @@ static struct perf_evsel * __add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, char *name, struct perf_pmu *pmu, - struct list_head *config_terms, bool auto_merge_stats) + struct list_head *config_terms, bool auto_merge_stats, + const char *cpu_list) { struct perf_evsel *evsel; -struct cpu_map *cpus = pmu ? pmu->cpus :NULL ; +struct cpu_map *cpus = pmu ? pmu->cpus : + cpu_list ?cpu_map__new (cpu_list) :NULL ;event_attr_init (attr);
@@ -348,7 +350,25 @@ static int add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, char *name, struct list_head *config_terms) { - return __add_event(list, idx, attr, name, NULL, config_terms, false) ? 0 : -ENOMEM; + return __add_event(list, idx, attr, name, NULL, config_terms, false, NULL) ? 0 : -ENOMEM; +} + +static int add_event_tool (struct list_head *list,int *idx, +enum perf_tool_event tool_event) +{ +struct perf_evsel *evsel; +struct perf_event_attr attr = { + .type =PERF_TYPE_SOFTWARE , + .config =PERF_COUNT_SW_DUMMY , + }; + + evsel =__add_event (list, idx, &attr,NULL ,NULL ,NULL , false,"0" ); +if (!evsel) +return -ENOMEM ; + evsel->tool_event = tool_event; +if (tool_event ==PERF_TOOL_DURATION_TIME ) + evsel->unit =strdup ("ns" ); +return 0 ; }static int parse_aliases (char *str,const char *names[][PERF_EVSEL__MAX_ALIASES ],int size)
@@ -1233,6 +1253,13 @@ int parse_events_add_numeric(struct parse_events_state *parse_state, get_config_name(head_config), &config_terms); } +int parse_events_add_tool (struct parse_events_state *parse_state, +struct list_head *list, +enum perf_tool_event tool_event) +{ +return add_event_tool (list, &parse_state->idx, tool_event); +} + int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, char *name, struct list_head *head_config,
@@ -1267,7 +1294,8 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,if (!head_config) { attr.type = pmu->type; - evsel =__add_event (list, &parse_state->idx, &attr,NULL , pmu,NULL , auto_merge_stats); + evsel =__add_event (list, &parse_state->idx, &attr,NULL , pmu,NULL , + auto_merge_stats,NULL );if (evsel) { evsel->pmu_name = name; evsel->use_uncore_alias = use_uncore_alias;
@@ -1295,7 +1323,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state, evsel =__add_event (list, &parse_state->idx, &attr,get_config_name (head_config), pmu, - &config_terms, auto_merge_stats); + &config_terms, auto_merge_stats,NULL );if (evsel) { evsel->unit = info.unit; evsel->scale = info.scale;
tools/perf/util/parse-events.h +4 -0
@@ -160,6 +160,10 @@ int parse_events_add_numeric(struct parse_events_state *parse_state,struct list_head *list, u32 type, u64 config, struct list_head *head_config); +enum perf_tool_event ; +int parse_events_add_tool (struct parse_events_state *parse_state, +struct list_head *list, +enum perf_tool_event tool_event); int parse_events_add_cache(struct list_head *list, int *idx, char *type, char *op_result1, char *op_result2, struct parse_events_error *error,
tools/perf/util/parse-events.l +10 -1
@@ -15,6 +15,7 @@ #include "../perf.h" #include "parse-events.h" #include "parse-events-bison.h" +#include "evsel.h" char *parse_events_get_text(yyscan_t yyscanner); YYSTYPE *parse_events_get_lval(yyscan_t yyscanner);
@@ -154,6 +155,14 @@ static int sym(yyscan_t scanner, int type, int config) return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; } +static int tool(yyscan_t scanner, enum perf_tool_event event) +{ + YYSTYPE *yylval = parse_events_get_lval(scanner); + + yylval->num = event; + return PE_VALUE_SYM_TOOL; +} + static int term(yyscan_t scanner, int type) { YYSTYPE *yylval = parse_events_get_lval(scanner);
@@ -322,7 +331,7 @@ cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } -duration_time { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } +duration_time { return tool(yyscanner, PERF_TOOL_DURATION_TIME); } bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } /*
tools/perf/util/parse-events.y +12 -0
@@ -14,6 +14,7 @@ #include <linux/types.h> #include "util.h" #include "pmu.h" +#include "evsel.h" #include "debug.h" #include "parse-events.h" #include "parse-events-bison.h"
@@ -45,6 +46,7 @@ static void inc_group_count(struct list_head *list, %token PE_START_EVENTS PE_START_TERMS %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM +%token PE_VALUE_SYM_TOOL %token PE_EVENT_NAME %token PE_NAME %token PE_BPF_OBJECT PE_BPF_SOURCE
@@ -58,6 +60,7 @@ static void inc_group_count(struct list_head *list, %type <num> PE_VALUE %type <num> PE_VALUE_SYM_HW %type <num> PE_VALUE_SYM_SW +%type <num> PE_VALUE_SYM_TOOL %type <num> PE_RAW %type <num> PE_TERM %type <str> PE_NAME
@@ -321,6 +324,15 @@ value_sym sep_slash_slash_dc ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); $$ = list; } +| +PE_VALUE_SYM_TOOL sep_slash_slash_dc +{ + struct list_head *list; + + ALLOC_LIST(list); + ABORT_ON(parse_events_add_tool(_parse_state, list, $1)); + $$ = list; +} event_legacy_cache: PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
PATCH 3/4 perf, tools: Support name for duration_time
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Implement printing the correct name for duration_time
--- tools/perf/util/evsel.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +10 -1
@@ -579,6 +579,12 @@ static int perf_evsel__raw_name(struct perf_evsel *evsel, char *bf, size_t size)return ret +perf_evsel__add_modifiers (evsel, bf + ret, size - ret); } +static int perf_evsel__tool_name (char *bf,size_t size) +{ +int ret =scnprintf (bf, size,"duration_time" ); +return ret; +} +const char *perf_evsel__name (struct perf_evsel *evsel) {char bf[128 ];
@@ -600,7 +606,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)break ;case PERF_TYPE_SOFTWARE : -perf_evsel__sw_name (evsel, bf,sizeof (bf)); +if (evsel->tool_event) +perf_evsel__tool_name (bf,sizeof (bf)); +else +perf_evsel__sw_name (evsel, bf,sizeof (bf));break ;case PERF_TYPE_TRACEPOINT :
Signature · 1 line
2.20.1
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf evsel: Support printing evsel name for 'duration_time'
perf evsel: Support printing evsel name for 'duration_time'
Commit-ID: 3371f389e4be6efc496ca395b21911a8f2c2d23f Gitweb: https://git.kernel.org/tip/3371f389e4be6efc496ca395b21911a8f2c2d23f Author: Andi Kleen <[email protected]> AuthorDate: Tue, 26 Mar 2019 15:18:22 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 1 Apr 2019 14:49:24 -0300
perf evsel: Support printing evsel name for 'duration_time'
Implement printing the correct name for duration_time
--- tools/perf/util/evsel.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +10 -1
@@ -580,6 +580,12 @@ static int perf_evsel__raw_name(struct perf_evsel *evsel, char *bf, size_t size)return ret +perf_evsel__add_modifiers (evsel, bf + ret, size - ret); } +static int perf_evsel__tool_name (char *bf,size_t size) +{ +int ret =scnprintf (bf, size,"duration_time" ); +return ret; +} +const char *perf_evsel__name (struct perf_evsel *evsel) {char bf[128 ];
@@ -601,7 +607,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)break ;case PERF_TYPE_SOFTWARE : -perf_evsel__sw_name (evsel, bf,sizeof (bf)); +if (evsel->tool_event) +perf_evsel__tool_name (bf,sizeof (bf)); +else +perf_evsel__sw_name (evsel, bf,sizeof (bf));break ;case PERF_TYPE_TRACEPOINT :
PATCH 4/4 perf, tools, list: Output tool events
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add support to perf list to output tool internal events, currently only duration_time.
--- tools/perf/builtin-list.c | 6 ++++-- tools/perf/util/parse-events.c | 20 ++++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-)
tools/perf/builtin-list.c +4 -2
@@ -70,10 +70,11 @@ int cmd_list(int argc, const char **argv)print_symbol_events (NULL ,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , raw_dump); else if (strcmp(argv[i], "sw") == 0 || - strcmp(argv[i], "software") == 0) + strcmp(argv[i], "software") == 0) { print_symbol_events(NULL, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); - else if (strcmp(argv[i], "cache") == 0 || + print_tool_events(NULL, raw_dump); + } else if (strcmp(argv[i], "cache") == 0 || strcmp(argv[i], "hwcache") == 0) print_hwcache_events(NULL, raw_dump); else if (strcmp(argv[i], "pmu") == 0)
@@ -113,6 +114,7 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);print_symbol_events (s,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , raw_dump); +print_tool_events (s, raw_dump);print_hwcache_events (s, raw_dump); print_pmu_events(s, raw_dump, !desc_flag, long_desc_flag,
tools/perf/util/parse-events.c +20 -0
@@ -2457,6 +2457,25 @@ int print_hwcache_events(const char *event_glob, bool name_only)return evt_num; } +static void print_tool_event (const char *name,const char *event_glob, +bool name_only) +{ +if (event_glob && !strglobmatch (name, event_glob)) +return ; +if (name_only) +printf ("%s " , name); +else +printf (" %-50s [%s]\n" , name,"Tool event" ); + +} + +void print_tool_events (const char *event_glob,bool name_only) +{ +print_tool_event ("duration_time" , event_glob, name_only); +if (pager_in_use ()) +printf ("\n" ); +} +void print_symbol_events (const char *event_glob,unsigned type,struct event_symbol *syms,unsigned max,bool name_only)
@@ -2540,6 +2559,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,print_symbol_events (event_glob,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , name_only); +print_tool_events (event_glob, name_only);print_hwcache_events (event_glob, name_only);
tools/perf/util/parse-events.h +1 -0
@@ -204,6 +204,7 @@ extern struct event_symbol event_symbols_sw[];void print_symbol_events (const char *event_glob,unsigned type,struct event_symbol *syms,unsigned max,bool name_only); +void print_tool_events (const char *event_glob,bool name_only);void print_tracepoint_events (const char *subsys_glob,const char *event_glob,bool name_only);int print_hwcache_events (const char *event_glob,bool name_only);
Signature · 1 line
2.20.1
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf list: Output tool events
perf list: Output tool events
Commit-ID: 5e0861baa3fa73e8bd861a4b7ba7fa992b1dff82 Gitweb: https://git.kernel.org/tip/5e0861baa3fa73e8bd861a4b7ba7fa992b1dff82 Author: Andi Kleen <[email protected]> AuthorDate: Tue, 26 Mar 2019 15:18:23 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 1 Apr 2019 14:49:25 -0300
perf list: Output tool events
Add support in 'perf list' to output tool internal events, currently only 'duration_time'.
Committer testing:
$ perf list dur*
List of pre-defined events (to be used in -e):
duration_time [Tool event]
Metric Groups:
$ perf list sw
List of pre-defined events (to be used in -e):
alignment-faults [Software event]
bpf-output [Software event]
context-switches OR cs [Software event]
cpu-clock [Software event]
cpu-migrations OR migrations [Software event]
dummy [Software event]
emulation-faults [Software event]
major-faults [Software event]
minor-faults [Software event]
page-faults OR faults [Software event]
task-clock [Software event] duration_time [Tool event]
$ perf list | grep duration
duration_time [Tool event]
[L1D miss outstandings duration in cycles]
page walk duration are excluded in Skylake]
load. EPT page walk duration are excluded in Skylake]
page walk duration are excluded in Skylake]
store. EPT page walk duration are excluded in Skylake]
(instruction fetch) request. EPT page walk duration are excluded in
instruction fetch request. EPT page walk duration are excluded in
$--- tools/perf/builtin-list.c | 6 ++++-- tools/perf/util/parse-events.c | 20 ++++++++++++++++++++ tools/perf/util/parse-events.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-)
tools/perf/builtin-list.c +4 -2
@@ -70,10 +70,11 @@ int cmd_list(int argc, const char **argv)print_symbol_events (NULL ,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , raw_dump); else if (strcmp(argv[i], "sw") == 0 || - strcmp(argv[i], "software") == 0) + strcmp(argv[i], "software") == 0) { print_symbol_events(NULL, PERF_TYPE_SOFTWARE, event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); - else if (strcmp(argv[i], "cache") == 0 || + print_tool_events(NULL, raw_dump); + } else if (strcmp(argv[i], "cache") == 0 || strcmp(argv[i], "hwcache") == 0) print_hwcache_events(NULL, raw_dump); else if (strcmp(argv[i], "pmu") == 0)
@@ -113,6 +114,7 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);print_symbol_events (s,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , raw_dump); +print_tool_events (s, raw_dump);print_hwcache_events (s, raw_dump); print_pmu_events(s, raw_dump, !desc_flag, long_desc_flag,
tools/perf/util/parse-events.c +20 -0
@@ -2457,6 +2457,25 @@ out_enomem:return evt_num; } +static void print_tool_event (const char *name,const char *event_glob, +bool name_only) +{ +if (event_glob && !strglobmatch (name, event_glob)) +return ; +if (name_only) +printf ("%s " , name); +else +printf (" %-50s [%s]\n" , name,"Tool event" ); + +} + +void print_tool_events (const char *event_glob,bool name_only) +{ +print_tool_event ("duration_time" , event_glob, name_only); +if (pager_in_use ()) +printf ("\n" ); +} +void print_symbol_events (const char *event_glob,unsigned type,struct event_symbol *syms,unsigned max,bool name_only)
@@ -2540,6 +2559,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag,print_symbol_events (event_glob,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , name_only); +print_tool_events (event_glob, name_only);print_hwcache_events (event_glob, name_only);
tools/perf/util/parse-events.h +1 -0
@@ -204,6 +204,7 @@ extern struct event_symbol event_symbols_sw[];void print_symbol_events (const char *event_glob,unsigned type,struct event_symbol *syms,unsigned max,bool name_only); +void print_tool_events (const char *event_glob,bool name_only);void print_tracepoint_events (const char *subsys_glob,const char *event_glob,bool name_only);int print_hwcache_events (const char *event_glob,bool name_only);
Jiri Olsa
Acked-byQuoted 6 lines · Andi Kleen
Currently it's not possible to get the wall clock time of a measurement in CSV mode output, it's only in the non CSV perf stat output. Often this is needed to normalize event counts to time.
Add a new
duration_timeevent that can be specified and reports the wall clock time in ns.
thanks,
jirka