at master 5.8 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __PERF_STATS_H 3#define __PERF_STATS_H 4 5#include <linux/types.h> 6#include <stdio.h> 7#include <sys/types.h> 8#include <sys/resource.h> 9#include "cpumap.h" 10#include "counts.h" 11 12struct perf_cpu_map; 13struct perf_stat_config; 14struct timespec; 15 16struct stats { 17 double n, mean, M2; 18 u64 max, min; 19}; 20 21/* hold aggregated event info */ 22struct perf_stat_aggr { 23 /* aggregated values */ 24 struct perf_counts_values counts; 25 /* number of entries (CPUs) aggregated */ 26 int nr; 27 /* whether any entry has failed to read/process event */ 28 bool failed; 29 /* to mark this data is processed already */ 30 bool used; 31}; 32 33/* per-evsel event stats */ 34struct perf_stat_evsel { 35 /* used for repeated runs */ 36 struct stats res_stats; 37 /* number of allocated 'aggr' */ 38 int nr_aggr; 39 /* aggregated event values */ 40 struct perf_stat_aggr *aggr; 41 /* used for group read */ 42 u64 *group_data; 43}; 44 45enum aggr_mode { 46 AGGR_NONE, 47 AGGR_GLOBAL, 48 AGGR_SOCKET, 49 AGGR_DIE, 50 AGGR_CLUSTER, 51 AGGR_CACHE, 52 AGGR_CORE, 53 AGGR_THREAD, 54 AGGR_UNSET, 55 AGGR_NODE, 56 AGGR_MAX 57}; 58 59typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, struct perf_cpu cpu); 60 61struct perf_stat_config { 62 enum aggr_mode aggr_mode; 63 u32 aggr_level; 64 bool scale; 65 bool no_inherit; 66 bool identifier; 67 bool csv_output; 68 bool json_output; 69 bool interval_clear; 70 bool metric_only; 71 bool null_run; 72 bool ru_display; 73 bool big_num; 74 bool hybrid_merge; 75 bool walltime_run_table; 76 bool all_kernel; 77 bool all_user; 78 bool percore_show_thread; 79 bool summary; 80 bool no_csv_summary; 81 bool metric_no_group; 82 bool metric_no_merge; 83 bool metric_no_threshold; 84 bool hardware_aware_grouping; 85 bool stop_read_counter; 86 bool iostat_run; 87 char *user_requested_cpu_list; 88 bool system_wide; 89 FILE *output; 90 unsigned int interval; 91 unsigned int timeout; 92 unsigned int unit_width; 93 unsigned int metric_only_len; 94 int times; 95 int run_count; 96 int print_free_counters_hint; 97 const char *csv_sep; 98 struct stats *walltime_nsecs_stats; 99 struct rusage ru_data; 100 struct cpu_aggr_map *aggr_map; 101 aggr_get_id_t aggr_get_id; 102 struct cpu_aggr_map *cpus_aggr_map; 103 u64 *walltime_run; 104 int ctl_fd; 105 int ctl_fd_ack; 106 bool ctl_fd_close; 107 const char *cgroup_list; 108 unsigned int topdown_level; 109}; 110 111extern struct perf_stat_config stat_config; 112 113void perf_stat__set_big_num(int set); 114 115void update_stats(struct stats *stats, u64 val); 116double avg_stats(struct stats *stats); 117double stddev_stats(struct stats *stats); 118double rel_stddev_stats(double stddev, double avg); 119 120static inline void init_stats(struct stats *stats) 121{ 122 stats->n = 0.0; 123 stats->mean = 0.0; 124 stats->M2 = 0.0; 125 stats->min = (u64) -1; 126 stats->max = 0; 127} 128 129struct evsel; 130struct evlist; 131 132enum metric_threshold_classify { 133 METRIC_THRESHOLD_UNKNOWN, 134 METRIC_THRESHOLD_BAD, 135 METRIC_THRESHOLD_NEARLY_BAD, 136 METRIC_THRESHOLD_LESS_GOOD, 137 METRIC_THRESHOLD_GOOD, 138}; 139const char *metric_threshold_classify__color(enum metric_threshold_classify thresh); 140 141typedef void (*print_metric_t)(struct perf_stat_config *config, 142 void *ctx, 143 enum metric_threshold_classify thresh, 144 const char *fmt, 145 const char *unit, 146 double val); 147typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx); 148 149/* Used to print the display name of the Default metricgroup for now. */ 150typedef void (*print_metricgroup_header_t)(struct perf_stat_config *config, 151 void *ctx, const char *metricgroup_name); 152 153void perf_stat__reset_shadow_stats(void); 154struct perf_stat_output_ctx { 155 void *ctx; 156 print_metric_t print_metric; 157 new_line_t new_line; 158 print_metricgroup_header_t print_metricgroup_header; 159 bool force_header; 160}; 161 162void perf_stat__print_shadow_stats(struct perf_stat_config *config, 163 struct evsel *evsel, 164 int aggr_idx, 165 struct perf_stat_output_ctx *out); 166bool perf_stat__skip_metric_event(struct evsel *evsel, u64 ena, u64 run); 167void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *config, 168 struct evsel *evsel, 169 int aggr_idx, 170 int *num, 171 void *from, 172 struct perf_stat_output_ctx *out); 173 174int evlist__alloc_stats(struct perf_stat_config *config, 175 struct evlist *evlist, bool alloc_raw); 176void evlist__free_stats(struct evlist *evlist); 177void evlist__reset_stats(struct evlist *evlist); 178void evlist__reset_prev_raw_counts(struct evlist *evlist); 179void evlist__copy_prev_raw_counts(struct evlist *evlist); 180void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); 181 182int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); 183void evlist__reset_aggr_stats(struct evlist *evlist); 184void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist); 185 186int perf_stat_process_counter(struct perf_stat_config *config, 187 struct evsel *counter); 188void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist); 189void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist); 190 191struct perf_tool; 192union perf_event; 193struct perf_session; 194struct target; 195 196int perf_event__process_stat_event(const struct perf_tool *tool, 197 struct perf_session *session, 198 union perf_event *event); 199 200size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); 201size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); 202size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); 203 204void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config, 205 struct target *_target, struct timespec *ts, int argc, const char **argv); 206 207struct metric_expr; 208double test_generic_metric(struct metric_expr *mexp, int aggr_idx); 209#endif