blob: 0150e786ccc7c1f48e407323b606f47155a076c9 [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,
Jiri Olsae2f56da2015-06-04 15:50:55 +020020 PERF_STAT_EVSEL_ID__MAX,
21};
22
Jiri Olsa581cc8a2015-10-16 12:41:03 +020023struct perf_stat_evsel {
Jiri Olsae2f56da2015-06-04 15:50:55 +020024 struct stats res_stats[3];
25 enum perf_stat_evsel_id id;
26};
27
Jiri Olsaf87027b2015-06-03 16:25:59 +020028enum aggr_mode {
29 AGGR_NONE,
30 AGGR_GLOBAL,
31 AGGR_SOCKET,
32 AGGR_CORE,
Jiri Olsa32b8af82015-06-26 11:29:27 +020033 AGGR_THREAD,
Jiri Olsa208df992015-10-16 12:41:04 +020034 AGGR_UNSET,
Jiri Olsaf87027b2015-06-03 16:25:59 +020035};
36
Jiri Olsa421a50f2015-07-21 14:31:22 +020037struct perf_stat_config {
38 enum aggr_mode aggr_mode;
Jiri Olsa711a5722015-07-21 14:31:23 +020039 bool scale;
Jiri Olsa58215222015-07-21 14:31:24 +020040 FILE *output;
Jiri Olsaec0d3d12015-07-21 14:31:25 +020041 unsigned int interval;
Jiri Olsa421a50f2015-07-21 14:31:22 +020042};
43
Xiao Guangrong0007ece2012-09-17 16:31:14 +080044void update_stats(struct stats *stats, u64 val);
45double avg_stats(struct stats *stats);
46double stddev_stats(struct stats *stats);
47double rel_stddev_stats(double stddev, double avg);
48
David Ahernffe4f3c2013-08-02 14:05:40 -060049static inline void init_stats(struct stats *stats)
50{
51 stats->n = 0.0;
52 stats->mean = 0.0;
53 stats->M2 = 0.0;
54 stats->min = (u64) -1;
55 stats->max = 0;
56}
Jiri Olsae2f56da2015-06-04 15:50:55 +020057
58struct perf_evsel;
Jiri Olsa24e34f62015-06-26 11:29:16 +020059struct perf_evlist;
60
Jiri Olsae2f56da2015-06-04 15:50:55 +020061bool __perf_evsel_stat__is(struct perf_evsel *evsel,
62 enum perf_stat_evsel_id id);
63
64#define perf_stat_evsel__is(evsel, id) \
65 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
66
67void perf_stat_evsel_id_init(struct perf_evsel *evsel);
68
Jiri Olsaf87027b2015-06-03 16:25:59 +020069extern struct stats walltime_nsecs_stats;
70
Andi Kleen140aead2016-01-30 09:06:49 -080071typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
72 const char *fmt, double val);
73typedef void (*new_line_t )(void *ctx);
74
Andi Kleenfb4605b2016-03-01 10:57:52 -080075void perf_stat__init_shadow_stats(void);
Jiri Olsaf87027b2015-06-03 16:25:59 +020076void perf_stat__reset_shadow_stats(void);
77void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
78 int cpu);
Andi Kleen140aead2016-01-30 09:06:49 -080079struct perf_stat_output_ctx {
80 void *ctx;
81 print_metric_t print_metric;
82 new_line_t new_line;
83};
84
85void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
86 double avg, int cpu,
87 struct perf_stat_output_ctx *out);
Jiri Olsaf87027b2015-06-03 16:25:59 +020088
Jiri Olsa24e34f62015-06-26 11:29:16 +020089int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
90void perf_evlist__free_stats(struct perf_evlist *evlist);
91void perf_evlist__reset_stats(struct perf_evlist *evlist);
Jiri Olsaf80010e2015-07-21 14:31:27 +020092
93int perf_stat_process_counter(struct perf_stat_config *config,
94 struct perf_evsel *counter);
Jiri Olsa0ea0e352015-10-25 15:51:32 +010095struct perf_tool;
96union perf_event;
97struct perf_session;
98int perf_event__process_stat_event(struct perf_tool *tool,
99 union perf_event *event,
100 struct perf_session *session);
Jiri Olsae08a4562015-10-25 15:51:35 +0100101
102size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
103size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
104size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
Xiao Guangrong0007ece2012-09-17 16:31:14 +0800105#endif