blob: c29bb94c48a4b6070a659e3674f4ae84694724f9 [file] [log] [blame]
Xiao Guangrong0007ece2012-09-17 16:31:14 +08001#ifndef __PERF_STATS_H
2#define __PERF_STATS_H
3
Borislav Petkovd944c4e2014-04-25 21:31:02 +02004#include <linux/types.h>
Jiri Olsaf87027b2015-06-03 16:25:59 +02005#include <stdio.h>
Jiri Olsaa8e02322015-06-26 11:29:10 +02006#include "xyarray.h"
Xiao Guangrong0007ece2012-09-17 16:31:14 +08007
8struct stats
9{
10 double n, mean, M2;
David Ahernffe4f3c2013-08-02 14:05:40 -060011 u64 max, min;
Xiao Guangrong0007ece2012-09-17 16:31:14 +080012};
13
Jiri Olsae2f56da2015-06-04 15:50:55 +020014enum perf_stat_evsel_id {
15 PERF_STAT_EVSEL_ID__NONE = 0,
Jiri Olsa4c358d52015-06-03 16:25:52 +020016 PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
17 PERF_STAT_EVSEL_ID__TRANSACTION_START,
18 PERF_STAT_EVSEL_ID__ELISION_START,
19 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
Andi Kleen239bd472016-05-24 12:52:37 -070020 PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS,
21 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED,
22 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED,
23 PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES,
24 PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES,
Jiri Olsae2f56da2015-06-04 15:50:55 +020025 PERF_STAT_EVSEL_ID__MAX,
26};
27
Jiri Olsa581cc8a2015-10-16 12:41:03 +020028struct perf_stat_evsel {
Jiri Olsae2f56da2015-06-04 15:50:55 +020029 struct stats res_stats[3];
30 enum perf_stat_evsel_id id;
31};
32
Jiri Olsaf87027b2015-06-03 16:25:59 +020033enum aggr_mode {
34 AGGR_NONE,
35 AGGR_GLOBAL,
36 AGGR_SOCKET,
37 AGGR_CORE,
Jiri Olsa32b8af82015-06-26 11:29:27 +020038 AGGR_THREAD,
Jiri Olsa208df992015-10-16 12:41:04 +020039 AGGR_UNSET,
Jiri Olsaf87027b2015-06-03 16:25:59 +020040};
41
Jiri Olsa421a50f2015-07-21 14:31:22 +020042struct perf_stat_config {
43 enum aggr_mode aggr_mode;
Jiri Olsa711a5722015-07-21 14:31:23 +020044 bool scale;
Jiri Olsa58215222015-07-21 14:31:24 +020045 FILE *output;
Jiri Olsaec0d3d12015-07-21 14:31:25 +020046 unsigned int interval;
Jiri Olsa421a50f2015-07-21 14:31:22 +020047};
48
Xiao Guangrong0007ece2012-09-17 16:31:14 +080049void update_stats(struct stats *stats, u64 val);
50double avg_stats(struct stats *stats);
51double stddev_stats(struct stats *stats);
52double rel_stddev_stats(double stddev, double avg);
53
David Ahernffe4f3c2013-08-02 14:05:40 -060054static inline void init_stats(struct stats *stats)
55{
56 stats->n = 0.0;
57 stats->mean = 0.0;
58 stats->M2 = 0.0;
59 stats->min = (u64) -1;
60 stats->max = 0;
61}
Jiri Olsae2f56da2015-06-04 15:50:55 +020062
63struct perf_evsel;
Jiri Olsa24e34f62015-06-26 11:29:16 +020064struct perf_evlist;
65
Jiri Olsae2f56da2015-06-04 15:50:55 +020066bool __perf_evsel_stat__is(struct perf_evsel *evsel,
67 enum perf_stat_evsel_id id);
68
69#define perf_stat_evsel__is(evsel, id) \
70 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
71
72void perf_stat_evsel_id_init(struct perf_evsel *evsel);
73
Jiri Olsaf87027b2015-06-03 16:25:59 +020074extern struct stats walltime_nsecs_stats;
75
Andi Kleen140aead2016-01-30 09:06:49 -080076typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
77 const char *fmt, double val);
78typedef void (*new_line_t )(void *ctx);
79
Andi Kleenfb4605b2016-03-01 10:57:52 -080080void perf_stat__init_shadow_stats(void);
Jiri Olsaf87027b2015-06-03 16:25:59 +020081void perf_stat__reset_shadow_stats(void);
82void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
83 int cpu);
Andi Kleen140aead2016-01-30 09:06:49 -080084struct perf_stat_output_ctx {
85 void *ctx;
86 print_metric_t print_metric;
87 new_line_t new_line;
88};
89
90void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
91 double avg, int cpu,
92 struct perf_stat_output_ctx *out);
Jiri Olsaf87027b2015-06-03 16:25:59 +020093
Jiri Olsa24e34f62015-06-26 11:29:16 +020094int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
95void perf_evlist__free_stats(struct perf_evlist *evlist);
96void perf_evlist__reset_stats(struct perf_evlist *evlist);
Jiri Olsaf80010e2015-07-21 14:31:27 +020097
98int perf_stat_process_counter(struct perf_stat_config *config,
99 struct perf_evsel *counter);
Jiri Olsa0ea0e352015-10-25 15:51:32 +0100100struct perf_tool;
101union perf_event;
102struct perf_session;
103int perf_event__process_stat_event(struct perf_tool *tool,
104 union perf_event *event,
105 struct perf_session *session);
Jiri Olsae08a4562015-10-25 15:51:35 +0100106
107size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
108size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
109size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
Xiao Guangrong0007ece2012-09-17 16:31:14 +0800110#endif