blob: e0b8dc50fbb6136ed258abf01ea478d6f51b4976 [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
23struct perf_stat {
24 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,
33};
34
Jiri Olsa1ac77e12015-06-26 11:29:09 +020035struct perf_counts_values {
36 union {
37 struct {
38 u64 val;
39 u64 ena;
40 u64 run;
41 };
42 u64 values[3];
43 };
44};
45
46struct perf_counts {
47 s8 scaled;
48 struct perf_counts_values aggr;
Jiri Olsaa8e02322015-06-26 11:29:10 +020049 struct xyarray *cpu;
Jiri Olsa1ac77e12015-06-26 11:29:09 +020050};
51
52static inline struct perf_counts_values*
Jiri Olsaa6fa0032015-06-26 11:29:11 +020053perf_counts(struct perf_counts *counts, int cpu, int thread)
Jiri Olsa1ac77e12015-06-26 11:29:09 +020054{
Jiri Olsaa6fa0032015-06-26 11:29:11 +020055 return xyarray__entry(counts->cpu, cpu, thread);
Jiri Olsa1ac77e12015-06-26 11:29:09 +020056}
57
Xiao Guangrong0007ece2012-09-17 16:31:14 +080058void update_stats(struct stats *stats, u64 val);
59double avg_stats(struct stats *stats);
60double stddev_stats(struct stats *stats);
61double rel_stddev_stats(double stddev, double avg);
62
David Ahernffe4f3c2013-08-02 14:05:40 -060063static inline void init_stats(struct stats *stats)
64{
65 stats->n = 0.0;
66 stats->mean = 0.0;
67 stats->M2 = 0.0;
68 stats->min = (u64) -1;
69 stats->max = 0;
70}
Jiri Olsae2f56da2015-06-04 15:50:55 +020071
72struct perf_evsel;
73bool __perf_evsel_stat__is(struct perf_evsel *evsel,
74 enum perf_stat_evsel_id id);
75
76#define perf_stat_evsel__is(evsel, id) \
77 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
78
79void perf_stat_evsel_id_init(struct perf_evsel *evsel);
80
Jiri Olsaf87027b2015-06-03 16:25:59 +020081extern struct stats walltime_nsecs_stats;
82
83void perf_stat__reset_shadow_stats(void);
84void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
85 int cpu);
86void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
87 double avg, int cpu, enum aggr_mode aggr);
88
Jiri Olsaa6fa0032015-06-26 11:29:11 +020089struct perf_counts *perf_counts__new(int ncpus, int nthreads);
Jiri Olsa9df38e82015-06-14 10:19:27 +020090void perf_counts__delete(struct perf_counts *counts);
91
Jiri Olsaa8e02322015-06-26 11:29:10 +020092void perf_evsel__reset_counts(struct perf_evsel *evsel);
Jiri Olsaa6fa0032015-06-26 11:29:11 +020093int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads);
Jiri Olsaa9a3a4d2015-06-14 10:19:26 +020094void perf_evsel__free_counts(struct perf_evsel *evsel);
Xiao Guangrong0007ece2012-09-17 16:31:14 +080095#endif