Skip to content

Commit 6026ab6

Browse files
captain5050acmel
authored andcommitted
perf stat: Move create_perf_stat_counter() to builtin-stat.c
The function create_perf_stat_counter is only used in builtin-stat.c and contains logic about retrying events specific to builtin-stat.c. Move the code to builtin-stat.c to tidy this up. Reviewed-by: James Clark <james.clark@linaro.org> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Chun-Tse Shao <ctshao@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Falcon <thomas.falcon@intel.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 79cc9b4 commit 6026ab6

3 files changed

Lines changed: 58 additions & 62 deletions

File tree

tools/perf/builtin-stat.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,62 @@ static enum counter_recovery stat_handle_error(struct evsel *counter, int err)
676676
return COUNTER_FATAL;
677677
}
678678

679+
static int create_perf_stat_counter(struct evsel *evsel,
680+
struct perf_stat_config *config,
681+
int cpu_map_idx)
682+
{
683+
struct perf_event_attr *attr = &evsel->core.attr;
684+
struct evsel *leader = evsel__leader(evsel);
685+
686+
/* Reset supported flag as creating a stat counter is retried. */
687+
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
688+
PERF_FORMAT_TOTAL_TIME_RUNNING;
689+
690+
/*
691+
* The event is part of non trivial group, let's enable
692+
* the group read (for leader) and ID retrieval for all
693+
* members.
694+
*/
695+
if (leader->core.nr_members > 1)
696+
attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
697+
698+
attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
699+
700+
/*
701+
* Some events get initialized with sample_(period/type) set,
702+
* like tracepoints. Clear it up for counting.
703+
*/
704+
attr->sample_period = 0;
705+
706+
if (config->identifier)
707+
attr->sample_type = PERF_SAMPLE_IDENTIFIER;
708+
709+
if (config->all_user) {
710+
attr->exclude_kernel = 1;
711+
attr->exclude_user = 0;
712+
}
713+
714+
if (config->all_kernel) {
715+
attr->exclude_kernel = 0;
716+
attr->exclude_user = 1;
717+
}
718+
719+
/*
720+
* Disabling all counters initially, they will be enabled
721+
* either manually by us or by kernel via enable_on_exec
722+
* set later.
723+
*/
724+
if (evsel__is_group_leader(evsel)) {
725+
attr->disabled = 1;
726+
727+
if (target__enable_on_exec(&target))
728+
attr->enable_on_exec = 1;
729+
}
730+
731+
return evsel__open_per_cpu_and_thread(evsel, evsel__cpus(evsel), cpu_map_idx,
732+
evsel->core.threads);
733+
}
734+
679735
static int __run_perf_stat(int argc, const char **argv, int run_idx)
680736
{
681737
int interval = stat_config.interval;
@@ -736,7 +792,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
736792
if (evsel__is_bperf(counter))
737793
continue;
738794
try_again:
739-
if (create_perf_stat_counter(counter, &stat_config, &target,
795+
if (create_perf_stat_counter(counter, &stat_config,
740796
evlist_cpu_itr.cpu_map_idx) < 0) {
741797

742798
/*
@@ -794,7 +850,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
794850
continue;
795851
try_again_reset:
796852
pr_debug2("reopening weak %s\n", evsel__name(counter));
797-
if (create_perf_stat_counter(counter, &stat_config, &target,
853+
if (create_perf_stat_counter(counter, &stat_config,
798854
evlist_cpu_itr.cpu_map_idx) < 0) {
799855

800856
switch (stat_handle_error(counter, errno)) {

tools/perf/util/stat.c

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -716,59 +716,3 @@ size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp)
716716

717717
return ret;
718718
}
719-
720-
int create_perf_stat_counter(struct evsel *evsel,
721-
struct perf_stat_config *config,
722-
struct target *target,
723-
int cpu_map_idx)
724-
{
725-
struct perf_event_attr *attr = &evsel->core.attr;
726-
struct evsel *leader = evsel__leader(evsel);
727-
728-
attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
729-
PERF_FORMAT_TOTAL_TIME_RUNNING;
730-
731-
/*
732-
* The event is part of non trivial group, let's enable
733-
* the group read (for leader) and ID retrieval for all
734-
* members.
735-
*/
736-
if (leader->core.nr_members > 1)
737-
attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
738-
739-
attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
740-
741-
/*
742-
* Some events get initialized with sample_(period/type) set,
743-
* like tracepoints. Clear it up for counting.
744-
*/
745-
attr->sample_period = 0;
746-
747-
if (config->identifier)
748-
attr->sample_type = PERF_SAMPLE_IDENTIFIER;
749-
750-
if (config->all_user) {
751-
attr->exclude_kernel = 1;
752-
attr->exclude_user = 0;
753-
}
754-
755-
if (config->all_kernel) {
756-
attr->exclude_kernel = 0;
757-
attr->exclude_user = 1;
758-
}
759-
760-
/*
761-
* Disabling all counters initially, they will be enabled
762-
* either manually by us or by kernel via enable_on_exec
763-
* set later.
764-
*/
765-
if (evsel__is_group_leader(evsel)) {
766-
attr->disabled = 1;
767-
768-
if (target__enable_on_exec(target))
769-
attr->enable_on_exec = 1;
770-
}
771-
772-
return evsel__open_per_cpu_and_thread(evsel, evsel__cpus(evsel), cpu_map_idx,
773-
evsel->core.threads);
774-
}

tools/perf/util/stat.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
223223
size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
224224
size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
225225

226-
int create_perf_stat_counter(struct evsel *evsel,
227-
struct perf_stat_config *config,
228-
struct target *target,
229-
int cpu_map_idx);
230226
void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config,
231227
struct target *_target, struct timespec *ts, int argc, const char **argv);
232228

0 commit comments

Comments
 (0)