]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame_incremental - tools/perf/util/stat.h
perf stat: Move 'null_run' to 'struct perf_stat_config'
[mirror_ubuntu-hirsute-kernel.git] / tools / perf / util / stat.h
... / ...
CommitLineData
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 "xyarray.h"
8#include "rblist.h"
9#include "perf.h"
10#include "event.h"
11
12struct stats {
13 double n, mean, M2;
14 u64 max, min;
15};
16
17enum perf_stat_evsel_id {
18 PERF_STAT_EVSEL_ID__NONE = 0,
19 PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
20 PERF_STAT_EVSEL_ID__TRANSACTION_START,
21 PERF_STAT_EVSEL_ID__ELISION_START,
22 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
23 PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS,
24 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED,
25 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED,
26 PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES,
27 PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES,
28 PERF_STAT_EVSEL_ID__SMI_NUM,
29 PERF_STAT_EVSEL_ID__APERF,
30 PERF_STAT_EVSEL_ID__MAX,
31};
32
33struct perf_stat_evsel {
34 struct stats res_stats[3];
35 enum perf_stat_evsel_id id;
36 u64 *group_data;
37};
38
39enum aggr_mode {
40 AGGR_NONE,
41 AGGR_GLOBAL,
42 AGGR_SOCKET,
43 AGGR_CORE,
44 AGGR_THREAD,
45 AGGR_UNSET,
46};
47
48enum {
49 CTX_BIT_USER = 1 << 0,
50 CTX_BIT_KERNEL = 1 << 1,
51 CTX_BIT_HV = 1 << 2,
52 CTX_BIT_HOST = 1 << 3,
53 CTX_BIT_IDLE = 1 << 4,
54 CTX_BIT_MAX = 1 << 5,
55};
56
57#define NUM_CTX CTX_BIT_MAX
58
59enum stat_type {
60 STAT_NONE = 0,
61 STAT_NSECS,
62 STAT_CYCLES,
63 STAT_STALLED_CYCLES_FRONT,
64 STAT_STALLED_CYCLES_BACK,
65 STAT_BRANCHES,
66 STAT_CACHEREFS,
67 STAT_L1_DCACHE,
68 STAT_L1_ICACHE,
69 STAT_LL_CACHE,
70 STAT_ITLB_CACHE,
71 STAT_DTLB_CACHE,
72 STAT_CYCLES_IN_TX,
73 STAT_TRANSACTION,
74 STAT_ELISION,
75 STAT_TOPDOWN_TOTAL_SLOTS,
76 STAT_TOPDOWN_SLOTS_ISSUED,
77 STAT_TOPDOWN_SLOTS_RETIRED,
78 STAT_TOPDOWN_FETCH_BUBBLES,
79 STAT_TOPDOWN_RECOVERY_BUBBLES,
80 STAT_SMI_NUM,
81 STAT_APERF,
82 STAT_MAX
83};
84
85struct runtime_stat {
86 struct rblist value_list;
87};
88
89struct perf_stat_config {
90 enum aggr_mode aggr_mode;
91 bool scale;
92 bool no_inherit;
93 bool identifier;
94 bool csv_output;
95 bool interval_clear;
96 bool metric_only;
97 bool null_run;
98 FILE *output;
99 unsigned int interval;
100 unsigned int timeout;
101 unsigned int initial_delay;
102 unsigned int unit_width;
103 unsigned int metric_only_len;
104 int times;
105 int run_count;
106 struct runtime_stat *stats;
107 int stats_num;
108 const char *csv_sep;
109 struct stats *walltime_nsecs_stats;
110};
111
112void update_stats(struct stats *stats, u64 val);
113double avg_stats(struct stats *stats);
114double stddev_stats(struct stats *stats);
115double rel_stddev_stats(double stddev, double avg);
116
117static inline void init_stats(struct stats *stats)
118{
119 stats->n = 0.0;
120 stats->mean = 0.0;
121 stats->M2 = 0.0;
122 stats->min = (u64) -1;
123 stats->max = 0;
124}
125
126struct perf_evsel;
127struct perf_evlist;
128
129struct perf_aggr_thread_value {
130 struct perf_evsel *counter;
131 int id;
132 double uval;
133 u64 val;
134 u64 run;
135 u64 ena;
136};
137
138bool __perf_evsel_stat__is(struct perf_evsel *evsel,
139 enum perf_stat_evsel_id id);
140
141#define perf_stat_evsel__is(evsel, id) \
142 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
143
144extern struct runtime_stat rt_stat;
145extern struct stats walltime_nsecs_stats;
146
147typedef void (*print_metric_t)(struct perf_stat_config *config,
148 void *ctx, const char *color, const char *unit,
149 const char *fmt, double val);
150typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx);
151
152void runtime_stat__init(struct runtime_stat *st);
153void runtime_stat__exit(struct runtime_stat *st);
154void perf_stat__init_shadow_stats(void);
155void perf_stat__reset_shadow_stats(void);
156void perf_stat__reset_shadow_per_stat(struct runtime_stat *st);
157void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
158 int cpu, struct runtime_stat *st);
159struct perf_stat_output_ctx {
160 void *ctx;
161 print_metric_t print_metric;
162 new_line_t new_line;
163 bool force_header;
164};
165
166void perf_stat__print_shadow_stats(struct perf_stat_config *config,
167 struct perf_evsel *evsel,
168 double avg, int cpu,
169 struct perf_stat_output_ctx *out,
170 struct rblist *metric_events,
171 struct runtime_stat *st);
172void perf_stat__collect_metric_expr(struct perf_evlist *);
173
174int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
175void perf_evlist__free_stats(struct perf_evlist *evlist);
176void perf_evlist__reset_stats(struct perf_evlist *evlist);
177
178int perf_stat_process_counter(struct perf_stat_config *config,
179 struct perf_evsel *counter);
180struct perf_tool;
181union perf_event;
182struct perf_session;
183int perf_event__process_stat_event(struct perf_tool *tool,
184 union perf_event *event,
185 struct perf_session *session);
186
187size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
188size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
189size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
190
191int create_perf_stat_counter(struct perf_evsel *evsel,
192 struct perf_stat_config *config,
193 struct target *target);
194int perf_stat_synthesize_config(struct perf_stat_config *config,
195 struct perf_tool *tool,
196 struct perf_evlist *evlist,
197 perf_event__handler_t process,
198 bool attrs);
199#endif