blob: f20240037377ed705bf887d6f89ffba5c62d7978 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Xiao Guangrong0007ece2012-09-17 16:31:14 +08002#ifndef __PERF_STATS_H
3#define __PERF_STATS_H
4
Borislav Petkovd944c4e2014-04-25 21:31:02 +02005#include <linux/types.h>
Jiri Olsaf87027b2015-06-03 16:25:59 +02006#include <stdio.h>
Jiri Olsaa8e02322015-06-26 11:29:10 +02007#include "xyarray.h"
Jin Yaoe5fcc2a2017-12-05 22:03:01 +08008#include "rblist.h"
Xiao Guangrong0007ece2012-09-17 16:31:14 +08009
10struct stats
11{
12 double n, mean, M2;
David Ahernffe4f3c2013-08-02 14:05:40 -060013 u64 max, min;
Xiao Guangrong0007ece2012-09-17 16:31:14 +080014};
15
Jiri Olsae2f56da2015-06-04 15:50:55 +020016enum perf_stat_evsel_id {
17 PERF_STAT_EVSEL_ID__NONE = 0,
Jiri Olsa4c358d52015-06-03 16:25:52 +020018 PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
19 PERF_STAT_EVSEL_ID__TRANSACTION_START,
20 PERF_STAT_EVSEL_ID__ELISION_START,
21 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
Andi Kleen239bd472016-05-24 12:52:37 -070022 PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS,
23 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED,
24 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED,
25 PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES,
26 PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES,
Kan Liangdaefd0b2017-05-26 12:05:38 -070027 PERF_STAT_EVSEL_ID__SMI_NUM,
28 PERF_STAT_EVSEL_ID__APERF,
Jiri Olsae2f56da2015-06-04 15:50:55 +020029 PERF_STAT_EVSEL_ID__MAX,
30};
31
Jiri Olsa581cc8a2015-10-16 12:41:03 +020032struct perf_stat_evsel {
Jiri Olsaf7794d52017-07-26 14:02:05 +020033 struct stats res_stats[3];
34 enum perf_stat_evsel_id id;
35 u64 *group_data;
Jiri Olsae2f56da2015-06-04 15:50:55 +020036};
37
Jiri Olsaf87027b2015-06-03 16:25:59 +020038enum aggr_mode {
39 AGGR_NONE,
40 AGGR_GLOBAL,
41 AGGR_SOCKET,
42 AGGR_CORE,
Jiri Olsa32b8af82015-06-26 11:29:27 +020043 AGGR_THREAD,
Jiri Olsa208df992015-10-16 12:41:04 +020044 AGGR_UNSET,
Jiri Olsaf87027b2015-06-03 16:25:59 +020045};
46
Jin Yaoe5fcc2a2017-12-05 22:03:01 +080047enum {
48 CTX_BIT_USER = 1 << 0,
49 CTX_BIT_KERNEL = 1 << 1,
50 CTX_BIT_HV = 1 << 2,
51 CTX_BIT_HOST = 1 << 3,
52 CTX_BIT_IDLE = 1 << 4,
53 CTX_BIT_MAX = 1 << 5,
54};
55
56#define NUM_CTX CTX_BIT_MAX
57
58enum stat_type {
59 STAT_NONE = 0,
60 STAT_NSECS,
61 STAT_CYCLES,
62 STAT_STALLED_CYCLES_FRONT,
63 STAT_STALLED_CYCLES_BACK,
64 STAT_BRANCHES,
65 STAT_CACHEREFS,
66 STAT_L1_DCACHE,
67 STAT_L1_ICACHE,
68 STAT_LL_CACHE,
69 STAT_ITLB_CACHE,
70 STAT_DTLB_CACHE,
71 STAT_CYCLES_IN_TX,
72 STAT_TRANSACTION,
73 STAT_ELISION,
74 STAT_TOPDOWN_TOTAL_SLOTS,
75 STAT_TOPDOWN_SLOTS_ISSUED,
76 STAT_TOPDOWN_SLOTS_RETIRED,
77 STAT_TOPDOWN_FETCH_BUBBLES,
78 STAT_TOPDOWN_RECOVERY_BUBBLES,
79 STAT_SMI_NUM,
80 STAT_APERF,
81 STAT_MAX
82};
83
84struct runtime_stat {
85 struct rblist value_list;
86};
87
Jiri Olsa421a50f2015-07-21 14:31:22 +020088struct perf_stat_config {
89 enum aggr_mode aggr_mode;
Jiri Olsa711a5722015-07-21 14:31:23 +020090 bool scale;
Jiri Olsa58215222015-07-21 14:31:24 +020091 FILE *output;
Jiri Olsaec0d3d12015-07-21 14:31:25 +020092 unsigned int interval;
Jiri Olsa421a50f2015-07-21 14:31:22 +020093};
94
Xiao Guangrong0007ece2012-09-17 16:31:14 +080095void update_stats(struct stats *stats, u64 val);
96double avg_stats(struct stats *stats);
97double stddev_stats(struct stats *stats);
98double rel_stddev_stats(double stddev, double avg);
99
David Ahernffe4f3c2013-08-02 14:05:40 -0600100static inline void init_stats(struct stats *stats)
101{
102 stats->n = 0.0;
103 stats->mean = 0.0;
104 stats->M2 = 0.0;
105 stats->min = (u64) -1;
106 stats->max = 0;
107}
Jiri Olsae2f56da2015-06-04 15:50:55 +0200108
109struct perf_evsel;
Jiri Olsa24e34f62015-06-26 11:29:16 +0200110struct perf_evlist;
111
Jiri Olsae2f56da2015-06-04 15:50:55 +0200112bool __perf_evsel_stat__is(struct perf_evsel *evsel,
113 enum perf_stat_evsel_id id);
114
115#define perf_stat_evsel__is(evsel, id) \
116 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
117
118void perf_stat_evsel_id_init(struct perf_evsel *evsel);
119
Jin Yao8efb2df2017-12-05 22:03:03 +0800120extern struct runtime_stat rt_stat;
Jiri Olsaf87027b2015-06-03 16:25:59 +0200121extern struct stats walltime_nsecs_stats;
122
Andi Kleen140aead2016-01-30 09:06:49 -0800123typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
124 const char *fmt, double val);
125typedef void (*new_line_t )(void *ctx);
126
Jin Yao8efb2df2017-12-05 22:03:03 +0800127void runtime_stat__init(struct runtime_stat *st);
128void runtime_stat__exit(struct runtime_stat *st);
Andi Kleenfb4605b2016-03-01 10:57:52 -0800129void perf_stat__init_shadow_stats(void);
Jiri Olsaf87027b2015-06-03 16:25:59 +0200130void perf_stat__reset_shadow_stats(void);
Jiri Olsa54830dd2017-01-23 22:42:56 +0100131void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
Jiri Olsaf87027b2015-06-03 16:25:59 +0200132 int cpu);
Andi Kleen140aead2016-01-30 09:06:49 -0800133struct perf_stat_output_ctx {
134 void *ctx;
135 print_metric_t print_metric;
136 new_line_t new_line;
Andi Kleen37932c12017-03-20 13:17:08 -0700137 bool force_header;
Andi Kleen140aead2016-01-30 09:06:49 -0800138};
139
140void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
141 double avg, int cpu,
Andi Kleenb18f3e32017-08-31 12:40:31 -0700142 struct perf_stat_output_ctx *out,
143 struct rblist *metric_events);
Andi Kleen37932c12017-03-20 13:17:08 -0700144void perf_stat__collect_metric_expr(struct perf_evlist *);
Jiri Olsaf87027b2015-06-03 16:25:59 +0200145
Jiri Olsa24e34f62015-06-26 11:29:16 +0200146int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
147void perf_evlist__free_stats(struct perf_evlist *evlist);
148void perf_evlist__reset_stats(struct perf_evlist *evlist);
Jiri Olsaf80010e2015-07-21 14:31:27 +0200149
150int perf_stat_process_counter(struct perf_stat_config *config,
151 struct perf_evsel *counter);
Jiri Olsa0ea0e352015-10-25 15:51:32 +0100152struct perf_tool;
153union perf_event;
154struct perf_session;
155int perf_event__process_stat_event(struct perf_tool *tool,
156 union perf_event *event,
157 struct perf_session *session);
Jiri Olsae08a4562015-10-25 15:51:35 +0100158
159size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
160size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
161size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
Xiao Guangrong0007ece2012-09-17 16:31:14 +0800162#endif