blob: 093dc3cb28dd3f62cb593095dfdc9c59317e0446 [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>
Xiao Guangrong0007ece2012-09-17 16:31:14 +08006
7struct stats
8{
9 double n, mean, M2;
David Ahernffe4f3c2013-08-02 14:05:40 -060010 u64 max, min;
Xiao Guangrong0007ece2012-09-17 16:31:14 +080011};
12
Jiri Olsae2f56da2015-06-04 15:50:55 +020013enum perf_stat_evsel_id {
14 PERF_STAT_EVSEL_ID__NONE = 0,
Jiri Olsa4c358d52015-06-03 16:25:52 +020015 PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
16 PERF_STAT_EVSEL_ID__TRANSACTION_START,
17 PERF_STAT_EVSEL_ID__ELISION_START,
18 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
Jiri Olsae2f56da2015-06-04 15:50:55 +020019 PERF_STAT_EVSEL_ID__MAX,
20};
21
22struct perf_stat {
23 struct stats res_stats[3];
24 enum perf_stat_evsel_id id;
25};
26
Jiri Olsaf87027b2015-06-03 16:25:59 +020027enum aggr_mode {
28 AGGR_NONE,
29 AGGR_GLOBAL,
30 AGGR_SOCKET,
31 AGGR_CORE,
32};
33
Xiao Guangrong0007ece2012-09-17 16:31:14 +080034void update_stats(struct stats *stats, u64 val);
35double avg_stats(struct stats *stats);
36double stddev_stats(struct stats *stats);
37double rel_stddev_stats(double stddev, double avg);
38
David Ahernffe4f3c2013-08-02 14:05:40 -060039static inline void init_stats(struct stats *stats)
40{
41 stats->n = 0.0;
42 stats->mean = 0.0;
43 stats->M2 = 0.0;
44 stats->min = (u64) -1;
45 stats->max = 0;
46}
Jiri Olsae2f56da2015-06-04 15:50:55 +020047
48struct perf_evsel;
49bool __perf_evsel_stat__is(struct perf_evsel *evsel,
50 enum perf_stat_evsel_id id);
51
52#define perf_stat_evsel__is(evsel, id) \
53 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
54
55void perf_stat_evsel_id_init(struct perf_evsel *evsel);
56
Jiri Olsaf87027b2015-06-03 16:25:59 +020057extern struct stats walltime_nsecs_stats;
58
59void perf_stat__reset_shadow_stats(void);
60void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
61 int cpu);
62void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
63 double avg, int cpu, enum aggr_mode aggr);
64
Jiri Olsa9df38e82015-06-14 10:19:27 +020065struct perf_counts *perf_counts__new(int ncpus);
66void perf_counts__delete(struct perf_counts *counts);
67
Jiri Olsaa9a3a4d2015-06-14 10:19:26 +020068void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
69int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
70void perf_evsel__free_counts(struct perf_evsel *evsel);
Xiao Guangrong0007ece2012-09-17 16:31:14 +080071#endif