blob: 1cfbe0a980ac77a1a1af31db8a01141a449a6a4f [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,
Jiri Olsa32b8af82015-06-26 11:29:27 +020033 AGGR_THREAD,
Jiri Olsaf87027b2015-06-03 16:25:59 +020034};
35
Jiri Olsa1ac77e12015-06-26 11:29:09 +020036struct perf_counts_values {
37 union {
38 struct {
39 u64 val;
40 u64 ena;
41 u64 run;
42 };
43 u64 values[3];
44 };
45};
46
47struct perf_counts {
48 s8 scaled;
49 struct perf_counts_values aggr;
Jiri Olsa57b28912015-06-26 11:29:12 +020050 struct xyarray *values;
Jiri Olsa1ac77e12015-06-26 11:29:09 +020051};
52
53static inline struct perf_counts_values*
Jiri Olsaa6fa0032015-06-26 11:29:11 +020054perf_counts(struct perf_counts *counts, int cpu, int thread)
Jiri Olsa1ac77e12015-06-26 11:29:09 +020055{
Jiri Olsa57b28912015-06-26 11:29:12 +020056 return xyarray__entry(counts->values, cpu, thread);
Jiri Olsa1ac77e12015-06-26 11:29:09 +020057}
58
Xiao Guangrong0007ece2012-09-17 16:31:14 +080059void update_stats(struct stats *stats, u64 val);
60double avg_stats(struct stats *stats);
61double stddev_stats(struct stats *stats);
62double rel_stddev_stats(double stddev, double avg);
63
David Ahernffe4f3c2013-08-02 14:05:40 -060064static inline void init_stats(struct stats *stats)
65{
66 stats->n = 0.0;
67 stats->mean = 0.0;
68 stats->M2 = 0.0;
69 stats->min = (u64) -1;
70 stats->max = 0;
71}
Jiri Olsae2f56da2015-06-04 15:50:55 +020072
73struct perf_evsel;
Jiri Olsa24e34f62015-06-26 11:29:16 +020074struct perf_evlist;
75
Jiri Olsae2f56da2015-06-04 15:50:55 +020076bool __perf_evsel_stat__is(struct perf_evsel *evsel,
77 enum perf_stat_evsel_id id);
78
79#define perf_stat_evsel__is(evsel, id) \
80 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
81
82void perf_stat_evsel_id_init(struct perf_evsel *evsel);
83
Jiri Olsaf87027b2015-06-03 16:25:59 +020084extern struct stats walltime_nsecs_stats;
85
86void perf_stat__reset_shadow_stats(void);
87void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
88 int cpu);
89void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
90 double avg, int cpu, enum aggr_mode aggr);
91
Jiri Olsaa6fa0032015-06-26 11:29:11 +020092struct perf_counts *perf_counts__new(int ncpus, int nthreads);
Jiri Olsa9df38e82015-06-14 10:19:27 +020093void perf_counts__delete(struct perf_counts *counts);
94
Jiri Olsaa8e02322015-06-26 11:29:10 +020095void perf_evsel__reset_counts(struct perf_evsel *evsel);
Jiri Olsaa6fa0032015-06-26 11:29:11 +020096int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads);
Jiri Olsaa9a3a4d2015-06-14 10:19:26 +020097void perf_evsel__free_counts(struct perf_evsel *evsel);
Jiri Olsa9689edf2015-06-26 11:29:14 +020098
99void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
100int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
101void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
Jiri Olsaa9395122015-06-26 11:29:15 +0200102
103int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
104 int ncpus, int nthreads);
105void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
Jiri Olsa24e34f62015-06-26 11:29:16 +0200106
Jiri Olsaa7d0a102015-06-26 11:29:17 +0200107int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
108
Jiri Olsa24e34f62015-06-26 11:29:16 +0200109int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
110void perf_evlist__free_stats(struct perf_evlist *evlist);
111void perf_evlist__reset_stats(struct perf_evlist *evlist);
Xiao Guangrong0007ece2012-09-17 16:31:14 +0800112#endif