blob: da1d11c4f8c193cff476fec76868277b12f7c623 [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
71void perf_stat__reset_shadow_stats(void);
72void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
73 int cpu);
74void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
75 double avg, int cpu, enum aggr_mode aggr);
76
Jiri Olsa9689edf2015-06-26 11:29:14 +020077void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
78int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
79void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
Jiri Olsaa9395122015-06-26 11:29:15 +020080
81int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
82 int ncpus, int nthreads);
83void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
Jiri Olsa24e34f62015-06-26 11:29:16 +020084
Jiri Olsaa7d0a102015-06-26 11:29:17 +020085int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
86
Jiri Olsa24e34f62015-06-26 11:29:16 +020087int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
88void perf_evlist__free_stats(struct perf_evlist *evlist);
89void perf_evlist__reset_stats(struct perf_evlist *evlist);
Jiri Olsaf80010e2015-07-21 14:31:27 +020090
91int perf_stat_process_counter(struct perf_stat_config *config,
92 struct perf_evsel *counter);
Xiao Guangrong0007ece2012-09-17 16:31:14 +080093#endif