projects/linux·blob master · refs

210 lines · 5.6 KiB

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 hide_zero;
73 bool ru_display;
74 bool big_num;
75 bool hybrid_merge;
76 bool walltime_run_table;
77 bool all_kernel;
78 bool all_user;
79 bool percore_show_thread;
80 bool summary;
81 bool no_csv_summary;
82 bool metric_no_group;
83 bool metric_no_merge;
84 bool metric_no_threshold;
85 bool hardware_aware_grouping;
86 bool stop_read_counter;
87 bool iostat_run;
88 char *user_requested_cpu_list;
89 bool system_wide;
90 FILE *output;
91 unsigned int interval;
92 unsigned int timeout;
93 unsigned int unit_width;
94 unsigned int metric_only_len;
95 int times;
96 int run_count;
97 int print_free_counters_hint;
98 const char *csv_sep;
99 struct stats *walltime_nsecs_stats;
100 struct rusage ru_data;
101 struct cpu_aggr_map *aggr_map;
102 aggr_get_id_t aggr_get_id;
103 struct cpu_aggr_map *cpus_aggr_map;
104 u64 *walltime_run;
105 int ctl_fd;
106 int ctl_fd_ack;
107 bool ctl_fd_close;
108 const char *cgroup_list;
109 unsigned int topdown_level;
110};
111
112extern struct perf_stat_config stat_config;
113
114void perf_stat__set_big_num(int set);
115
116void update_stats(struct stats *stats, u64 val);
117double avg_stats(struct stats *stats);
118double stddev_stats(struct stats *stats);
119double rel_stddev_stats(double stddev, double avg);
120
121static inline void init_stats(struct stats *stats)
122{
123 stats->n = 0.0;
124 stats->mean = 0.0;
125 stats->M2 = 0.0;
126 stats->min = (u64) -1;
127 stats->max = 0;
128}
129
130struct evsel;
131struct evlist;
132
133enum metric_threshold_classify {
134 METRIC_THRESHOLD_UNKNOWN,
135 METRIC_THRESHOLD_BAD,
136 METRIC_THRESHOLD_NEARLY_BAD,
137 METRIC_THRESHOLD_LESS_GOOD,
138 METRIC_THRESHOLD_GOOD,
139};
140const char *metric_threshold_classify__color(enum metric_threshold_classify thresh);
141
142typedef void (*print_metric_t)(struct perf_stat_config *config,
143 void *ctx,
144 enum metric_threshold_classify thresh,
145 const char *fmt,
146 const char *unit,
147 double val);
148typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx);
149
150/* Used to print the display name of the Default metricgroup for now. */
151typedef void (*print_metricgroup_header_t)(struct perf_stat_config *config,
152 void *ctx, const char *metricgroup_name);
153
154void perf_stat__reset_shadow_stats(void);
155struct perf_stat_output_ctx {
156 void *ctx;
157 print_metric_t print_metric;
158 new_line_t new_line;
159 print_metricgroup_header_t print_metricgroup_header;
160 bool force_header;
161};
162
163void perf_stat__print_shadow_stats(struct perf_stat_config *config,
164 struct evsel *evsel,
165 int aggr_idx,
166 struct perf_stat_output_ctx *out);
167bool perf_stat__skip_metric_event(struct evsel *evsel);
168void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *config,
169 struct evsel *evsel,
170 int aggr_idx,
171 int *num,
172 void *from,
173 struct perf_stat_output_ctx *out);
174
175int evlist__alloc_stats(struct perf_stat_config *config,
176 struct evlist *evlist, bool alloc_raw);
177void evlist__free_stats(struct evlist *evlist);
178void evlist__reset_stats(struct evlist *evlist);
179void evlist__reset_prev_raw_counts(struct evlist *evlist);
180void evlist__copy_prev_raw_counts(struct evlist *evlist);
181void evlist__save_aggr_prev_raw_counts(struct evlist *evlist);
182
183int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr);
184void evlist__reset_aggr_stats(struct evlist *evlist);
185void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist);
186
187int perf_stat_process_counter(struct perf_stat_config *config,
188 struct evsel *counter);
189void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist);
190void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist);
191
192struct perf_tool;
193union perf_event;
194struct perf_session;
195struct target;
196
197int perf_event__process_stat_event(const struct perf_tool *tool,
198 struct perf_session *session,
199 union perf_event *event);
200
201size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
202size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
203size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
204
205void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *config,
206 struct target *_target, struct timespec *ts, int argc, const char **argv);
207
208struct metric_expr;
209double test_generic_metric(struct metric_expr *mexp, int aggr_idx);
210#endif