Lines Matching +full:skip +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0
24 stats->n++;
25 delta = val - stats->mean;
26 stats->mean += delta / stats->n;
27 stats->M2 += delta*(val - stats->mean);
29 if (val > stats->max)
30 stats->max = val;
32 if (val < stats->min)
33 stats->min = val;
38 return stats->mean;
44 * (\Sum n_i^2) - ((\Sum n_i)^2)/n
45 * s^2 = -------------------------------
46 * n - 1
53 * s_mean = -------
61 if (stats->n < 2)
64 variance = stats->M2 / (stats->n - 1);
65 variance_mean = variance / stats->n;
82 struct perf_stat_evsel *ps = evsel->stats;
83 struct perf_stat_aggr *aggr = ps->aggr;
86 memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr);
91 struct perf_stat_evsel *ps = evsel->stats;
93 init_stats(&ps->res_stats);
99 struct perf_stat_evsel *ps = evsel->stats;
104 ps->nr_aggr = nr_aggr;
105 ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr));
106 if (ps->aggr == NULL)
107 return -ENOMEM;
118 return -1;
129 return -ENOMEM;
131 evsel->stats = ps;
134 evsel->stats = NULL;
136 return -ENOMEM;
145 struct perf_stat_evsel *ps = evsel->stats;
148 zfree(&ps->aggr);
149 zfree(&ps->group_data);
151 zfree(&evsel->stats);
157 int nthreads = perf_thread_map__nr(evsel->core.threads);
162 evsel->prev_raw_counts = counts;
164 return counts ? 0 : -ENOMEM;
169 perf_counts__delete(evsel->prev_raw_counts);
170 evsel->prev_raw_counts = NULL;
175 if (evsel->prev_raw_counts)
176 perf_counts__reset(evsel->prev_raw_counts);
184 return -ENOMEM;
189 int evlist__alloc_stats(struct perf_stat_config *config,
195 if (config && config->aggr_map)
196 nr_aggr = config->aggr_map->nr;
207 return -1;
249 int idx, nthreads = perf_thread_map__nr(evsel->core.threads);
253 *perf_counts(evsel->counts, idx, thread) =
254 *perf_counts(evsel->prev_raw_counts, idx, thread);
269 struct perf_stat_evsel *ps = evsel->stats;
273 * in the evsel->stats.res_stats. See perf_stat_process_counter().
275 *ps->aggr[0].counts.values = avg_stats(&ps->res_stats);
278 void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist)
282 if (config->aggr_mode != AGGR_GLOBAL)
305 int cpu_map_idx, bool *skip)
307 struct hashmap *mask = counter->per_pkg_mask;
313 *skip = false;
315 if (!counter->per_pkg)
324 return -ENOMEM;
326 counter->per_pkg_mask = mask;
331 * instance to mark a package as used (skip=1). Otherwise
337 if (!(vals->run && vals->ena))
342 return -1;
345 * On multi-die system, die_id > 0. On no-die system, die_id = 0.
350 return -1;
354 return -ENOMEM;
358 *skip = true;
368 struct perf_stat_config *config)
371 if (evsel->err || evsel->counts->scaled == -1)
375 if (config->aggr_mode == AGGR_GLOBAL)
379 if (count->ena != 0 && count->run != 0)
386 process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
390 struct perf_stat_evsel *ps = evsel->stats;
392 bool skip = false;
394 if (check_per_pkg(evsel, count, cpu_map_idx, &skip)) {
395 pr_err("failed to read per-pkg counter\n");
396 return -1;
399 if (skip)
402 if (!evsel->snapshot)
404 perf_counts_values__scale(count, config->scale, NULL);
406 if (config->aggr_mode == AGGR_THREAD) {
407 struct perf_counts_values *aggr_counts = &ps->aggr[thread].counts;
410 * Skip value 0 when enabling --per-thread globally,
413 if (count->val == 0 && config->system_wide)
416 ps->aggr[thread].nr++;
418 aggr_counts->val += count->val;
419 aggr_counts->ena += count->ena;
420 aggr_counts->run += count->run;
424 if (ps->aggr) {
425 struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx);
426 struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu);
430 for (i = 0; i < ps->nr_aggr; i++) {
431 if (!aggr_cpu_id__equal(&aggr_id, &config->aggr_map->map[i]))
434 ps_aggr = &ps->aggr[i];
435 ps_aggr->nr++;
439 * in interval mode. But per-task counters can have 0 enabled time
442 if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) {
443 ps_aggr->counts.val = 0;
444 ps_aggr->counts.ena = 0;
445 ps_aggr->counts.run = 0;
446 ps_aggr->failed = true;
449 if (!ps_aggr->failed) {
450 ps_aggr->counts.val += count->val;
451 ps_aggr->counts.ena += count->ena;
452 ps_aggr->counts.run += count->run;
461 static int process_counter_maps(struct perf_stat_config *config,
464 int nthreads = perf_thread_map__nr(counter->core.threads);
470 if (process_counter_values(config, counter, idx, thread,
471 perf_counts(counter->counts, idx, thread)))
472 return -1;
479 int perf_stat_process_counter(struct perf_stat_config *config,
482 struct perf_stat_evsel *ps = counter->stats;
486 if (counter->per_pkg)
489 ret = process_counter_maps(config, counter);
493 if (config->aggr_mode != AGGR_GLOBAL)
498 * so we can use ps->aggr[0] as the actual output.
500 count = ps->aggr[0].counts.values;
501 update_stats(&ps->res_stats, *count);
504 fprintf(config->output, "%s: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n",
513 struct perf_stat_evsel *ps_a = evsel->stats;
514 struct perf_stat_evsel *ps_b = alias->stats;
517 if (ps_a->aggr == NULL && ps_b->aggr == NULL)
520 if (ps_a->nr_aggr != ps_b->nr_aggr) {
522 return -1;
525 for (i = 0; i < ps_a->nr_aggr; i++) {
526 struct perf_counts_values *aggr_counts_a = &ps_a->aggr[i].counts;
527 struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
531 aggr_counts_a->val += aggr_counts_b->val;
532 aggr_counts_a->ena += aggr_counts_b->ena;
533 aggr_counts_a->run += aggr_counts_b->run;
544 if (evsel_a->scale != evsel_b->scale)
547 if (evsel_a->cgrp != evsel_b->cgrp)
550 if (strcmp(evsel_a->unit, evsel_b->unit))
556 return evsel_a->pmu != evsel_b->pmu;
561 struct evlist *evlist = evsel->evlist;
564 alias = list_prepare_entry(evsel, &(evlist->core.entries), core.node);
565 list_for_each_entry_continue(alias, &evlist->core.entries, core.node) {
569 alias->merged_stat = true;
575 const struct perf_stat_config *config)
577 return config->hybrid_merge && evsel__is_hybrid(evsel);
580 static void evsel__merge_stats(struct evsel *evsel, struct perf_stat_config *config)
583 if (evsel->merged_stat)
586 if (evsel->auto_merge_stats || evsel__should_merge_hybrid(evsel, config))
591 void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist)
595 if (config->aggr_mode == AGGR_NONE)
599 evsel__merge_stats(evsel, config);
604 struct perf_stat_evsel *ps = evsel->stats;
610 /* collect per-core counts */
611 perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) {
612 struct perf_stat_aggr *aggr = &ps->aggr[idx];
618 counts.val += aggr->counts.val;
619 counts.ena += aggr->counts.ena;
620 counts.run += aggr->counts.run;
623 /* update aggregated per-core counts for each CPU */
624 perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) {
625 struct perf_stat_aggr *aggr = &ps->aggr[idx];
631 aggr->counts.val = counts.val;
632 aggr->counts.ena = counts.ena;
633 aggr->counts.run = counts.run;
635 aggr->used = true;
639 /* we have an aggr_map for cpu, but want to aggregate the counters per-core */
642 struct perf_stat_evsel *ps = evsel->stats;
647 if (!evsel->percore)
650 perf_cpu_map__for_each_cpu(cpu, idx, evsel->core.cpus) {
651 struct perf_stat_aggr *aggr = &ps->aggr[idx];
653 if (aggr->used)
661 /* process cpu stats on per-core events */
662 void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist)
666 if (config->aggr_mode != AGGR_NONE)
677 struct perf_record_stat *st = &event->stat;
681 count.val = st->val;
682 count.ena = st->ena;
683 count.run = st->run;
685 counter = evlist__id2evsel(session->evlist, st->id);
688 return -EINVAL;
690 cpu_map_idx = perf_cpu_map__idx(evsel__cpus(counter), (struct perf_cpu){.cpu = st->cpu});
691 if (cpu_map_idx == -1) {
692 pr_err("Invalid CPU %d for event %s.\n", st->cpu, evsel__name(counter));
693 return -EINVAL;
695 ptr = perf_counts(counter->counts, cpu_map_idx, st->thread);
698 st->cpu, st->thread, evsel__name(counter));
699 return -EINVAL;
702 counter->supported = true;
712 st->id, st->cpu, st->thread);
714 st->val, st->ena, st->run);
724 ret = fprintf(fp, "\n... time %" PRI_lu64 ", type %s\n", rd->time,
725 rd->type == PERF_STAT_ROUND_TYPE__FINAL ? "FINAL" : "INTERVAL");
735 perf_event__read_stat_config(&sc, &event->stat_config);
746 struct perf_stat_config *config,
750 struct perf_event_attr *attr = &evsel->core.attr;
753 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
761 if (leader->core.nr_members > 1)
762 attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
764 attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
770 attr->sample_period = 0;
772 if (config->identifier)
773 attr->sample_type = PERF_SAMPLE_IDENTIFIER;
775 if (config->all_user) {
776 attr->exclude_kernel = 1;
777 attr->exclude_user = 0;
780 if (config->all_kernel) {
781 attr->exclude_kernel = 0;
782 attr->exclude_user = 1;
791 attr->disabled = 1;
794 attr->enable_on_exec = 1;
800 return evsel__open_per_thread(evsel, evsel->core.threads);