Skip to content

Commit bfd8f72

Browse files
Andi Kleenacmel
authored andcommitted
perf record: Synthesize unit/scale/... in event update
Move the code to synthesize event updates for scale/unit/cpus to a common utility file, and use it both from stat and record. This allows to access scale and other extra qualifiers from perf script. Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20171117214300.32746-2-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 4ca69ca commit bfd8f72

File tree

4 files changed

+86
-58
lines changed

4 files changed

+86
-58
lines changed

tools/perf/builtin-record.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ static int record__open(struct record *rec)
372372
ui__error("%s\n", msg);
373373
goto out;
374374
}
375+
376+
pos->supported = true;
375377
}
376378

377379
if (perf_evlist__apply_filters(evlist, &pos)) {
@@ -784,6 +786,13 @@ static int record__synthesize(struct record *rec, bool tail)
784786
perf_event__synthesize_guest_os, tool);
785787
}
786788

789+
err = perf_event__synthesize_extra_attr(&rec->tool,
790+
rec->evlist,
791+
process_synthesized_event,
792+
data->is_pipe);
793+
if (err)
794+
goto out;
795+
787796
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
788797
process_synthesized_event, opts->sample_address,
789798
opts->proc_map_timeout, 1);

tools/perf/builtin-stat.c

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -458,19 +458,8 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf
458458
workload_exec_errno = info->si_value.sival_int;
459459
}
460460

461-
static bool has_unit(struct perf_evsel *counter)
462-
{
463-
return counter->unit && *counter->unit;
464-
}
465-
466-
static bool has_scale(struct perf_evsel *counter)
467-
{
468-
return counter->scale != 1;
469-
}
470-
471461
static int perf_stat_synthesize_config(bool is_pipe)
472462
{
473-
struct perf_evsel *counter;
474463
int err;
475464

476465
if (is_pipe) {
@@ -482,53 +471,10 @@ static int perf_stat_synthesize_config(bool is_pipe)
482471
}
483472
}
484473

485-
/*
486-
* Synthesize other events stuff not carried within
487-
* attr event - unit, scale, name
488-
*/
489-
evlist__for_each_entry(evsel_list, counter) {
490-
if (!counter->supported)
491-
continue;
492-
493-
/*
494-
* Synthesize unit and scale only if it's defined.
495-
*/
496-
if (has_unit(counter)) {
497-
err = perf_event__synthesize_event_update_unit(NULL, counter, process_synthesized_event);
498-
if (err < 0) {
499-
pr_err("Couldn't synthesize evsel unit.\n");
500-
return err;
501-
}
502-
}
503-
504-
if (has_scale(counter)) {
505-
err = perf_event__synthesize_event_update_scale(NULL, counter, process_synthesized_event);
506-
if (err < 0) {
507-
pr_err("Couldn't synthesize evsel scale.\n");
508-
return err;
509-
}
510-
}
511-
512-
if (counter->own_cpus) {
513-
err = perf_event__synthesize_event_update_cpus(NULL, counter, process_synthesized_event);
514-
if (err < 0) {
515-
pr_err("Couldn't synthesize evsel scale.\n");
516-
return err;
517-
}
518-
}
519-
520-
/*
521-
* Name is needed only for pipe output,
522-
* perf.data carries event names.
523-
*/
524-
if (is_pipe) {
525-
err = perf_event__synthesize_event_update_name(NULL, counter, process_synthesized_event);
526-
if (err < 0) {
527-
pr_err("Couldn't synthesize evsel name.\n");
528-
return err;
529-
}
530-
}
531-
}
474+
err = perf_event__synthesize_extra_attr(NULL,
475+
evsel_list,
476+
process_synthesized_event,
477+
is_pipe);
532478

533479
err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads,
534480
process_synthesized_event,

tools/perf/util/header.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,74 @@ int perf_event__synthesize_attrs(struct perf_tool *tool,
32583258
return err;
32593259
}
32603260

3261+
static bool has_unit(struct perf_evsel *counter)
3262+
{
3263+
return counter->unit && *counter->unit;
3264+
}
3265+
3266+
static bool has_scale(struct perf_evsel *counter)
3267+
{
3268+
return counter->scale != 1;
3269+
}
3270+
3271+
int perf_event__synthesize_extra_attr(struct perf_tool *tool,
3272+
struct perf_evlist *evsel_list,
3273+
perf_event__handler_t process,
3274+
bool is_pipe)
3275+
{
3276+
struct perf_evsel *counter;
3277+
int err;
3278+
3279+
/*
3280+
* Synthesize other events stuff not carried within
3281+
* attr event - unit, scale, name
3282+
*/
3283+
evlist__for_each_entry(evsel_list, counter) {
3284+
if (!counter->supported)
3285+
continue;
3286+
3287+
/*
3288+
* Synthesize unit and scale only if it's defined.
3289+
*/
3290+
if (has_unit(counter)) {
3291+
err = perf_event__synthesize_event_update_unit(tool, counter, process);
3292+
if (err < 0) {
3293+
pr_err("Couldn't synthesize evsel unit.\n");
3294+
return err;
3295+
}
3296+
}
3297+
3298+
if (has_scale(counter)) {
3299+
err = perf_event__synthesize_event_update_scale(tool, counter, process);
3300+
if (err < 0) {
3301+
pr_err("Couldn't synthesize evsel counter.\n");
3302+
return err;
3303+
}
3304+
}
3305+
3306+
if (counter->own_cpus) {
3307+
err = perf_event__synthesize_event_update_cpus(tool, counter, process);
3308+
if (err < 0) {
3309+
pr_err("Couldn't synthesize evsel cpus.\n");
3310+
return err;
3311+
}
3312+
}
3313+
3314+
/*
3315+
* Name is needed only for pipe output,
3316+
* perf.data carries event names.
3317+
*/
3318+
if (is_pipe) {
3319+
err = perf_event__synthesize_event_update_name(tool, counter, process);
3320+
if (err < 0) {
3321+
pr_err("Couldn't synthesize evsel name.\n");
3322+
return err;
3323+
}
3324+
}
3325+
}
3326+
return 0;
3327+
}
3328+
32613329
int perf_event__process_attr(struct perf_tool *tool __maybe_unused,
32623330
union perf_event *event,
32633331
struct perf_evlist **pevlist)

tools/perf/util/header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ int perf_event__synthesize_features(struct perf_tool *tool,
107107
struct perf_evlist *evlist,
108108
perf_event__handler_t process);
109109

110+
int perf_event__synthesize_extra_attr(struct perf_tool *tool,
111+
struct perf_evlist *evsel_list,
112+
perf_event__handler_t process,
113+
bool is_pipe);
114+
110115
int perf_event__process_feature(struct perf_tool *tool,
111116
union perf_event *event,
112117
struct perf_session *session);

0 commit comments

Comments
 (0)