aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-stat.c1
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/counts.c52
-rw-r--r--tools/perf/util/counts.h37
-rw-r--r--tools/perf/util/evsel.h2
-rw-r--r--tools/perf/util/python-ext-sources2
-rw-r--r--tools/perf/util/stat.c49
-rw-r--r--tools/perf/util/stat.h30
8 files changed, 93 insertions, 81 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index a054ddc0b2a0..7aa039bd379a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -58,6 +58,7 @@
58#include "util/cpumap.h" 58#include "util/cpumap.h"
59#include "util/thread.h" 59#include "util/thread.h"
60#include "util/thread_map.h" 60#include "util/thread_map.h"
61#include "util/counts.h"
61 62
62#include <stdlib.h> 63#include <stdlib.h>
63#include <sys/prctl.h> 64#include <sys/prctl.h>
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 2ee81d74cf45..1ce0adc8b3cb 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -68,6 +68,7 @@ libperf-y += target.o
68libperf-y += rblist.o 68libperf-y += rblist.o
69libperf-y += intlist.o 69libperf-y += intlist.o
70libperf-y += vdso.o 70libperf-y += vdso.o
71libperf-y += counts.o
71libperf-y += stat.o 72libperf-y += stat.o
72libperf-y += stat-shadow.o 73libperf-y += stat-shadow.o
73libperf-y += record.o 74libperf-y += record.o
diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c
new file mode 100644
index 000000000000..e3fde313deb2
--- /dev/null
+++ b/tools/perf/util/counts.c
@@ -0,0 +1,52 @@
1#include <stdlib.h>
2#include "evsel.h"
3#include "counts.h"
4
5struct perf_counts *perf_counts__new(int ncpus, int nthreads)
6{
7 struct perf_counts *counts = zalloc(sizeof(*counts));
8
9 if (counts) {
10 struct xyarray *values;
11
12 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
13 if (!values) {
14 free(counts);
15 return NULL;
16 }
17
18 counts->values = values;
19 }
20
21 return counts;
22}
23
24void perf_counts__delete(struct perf_counts *counts)
25{
26 if (counts) {
27 xyarray__delete(counts->values);
28 free(counts);
29 }
30}
31
32static void perf_counts__reset(struct perf_counts *counts)
33{
34 xyarray__reset(counts->values);
35}
36
37void perf_evsel__reset_counts(struct perf_evsel *evsel)
38{
39 perf_counts__reset(evsel->counts);
40}
41
42int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
43{
44 evsel->counts = perf_counts__new(ncpus, nthreads);
45 return evsel->counts != NULL ? 0 : -ENOMEM;
46}
47
48void perf_evsel__free_counts(struct perf_evsel *evsel)
49{
50 perf_counts__delete(evsel->counts);
51 evsel->counts = NULL;
52}
diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h
new file mode 100644
index 000000000000..34d8baaf558a
--- /dev/null
+++ b/tools/perf/util/counts.h
@@ -0,0 +1,37 @@
1#ifndef __PERF_COUNTS_H
2#define __PERF_COUNTS_H
3
4#include "xyarray.h"
5
6struct perf_counts_values {
7 union {
8 struct {
9 u64 val;
10 u64 ena;
11 u64 run;
12 };
13 u64 values[3];
14 };
15};
16
17struct perf_counts {
18 s8 scaled;
19 struct perf_counts_values aggr;
20 struct xyarray *values;
21};
22
23
24static inline struct perf_counts_values*
25perf_counts(struct perf_counts *counts, int cpu, int thread)
26{
27 return xyarray__entry(counts->values, cpu, thread);
28}
29
30struct perf_counts *perf_counts__new(int ncpus, int nthreads);
31void perf_counts__delete(struct perf_counts *counts);
32
33void perf_evsel__reset_counts(struct perf_evsel *evsel);
34int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads);
35void perf_evsel__free_counts(struct perf_evsel *evsel);
36
37#endif /* __PERF_COUNTS_H */
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 6a129081f3ad..b948f69d2558 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -9,7 +9,7 @@
9#include "xyarray.h" 9#include "xyarray.h"
10#include "symbol.h" 10#include "symbol.h"
11#include "cpumap.h" 11#include "cpumap.h"
12#include "stat.h" 12#include "counts.h"
13 13
14struct perf_evsel; 14struct perf_evsel;
15 15
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 0766d98c5da5..51be28b1bca2 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -16,7 +16,7 @@ util/util.c
16util/xyarray.c 16util/xyarray.c
17util/cgroup.c 17util/cgroup.c
18util/rblist.c 18util/rblist.c
19util/stat.c 19util/counts.c
20util/strlist.c 20util/strlist.c
21util/trace-event.c 21util/trace-event.c
22../lib/rbtree.c 22../lib/rbtree.c
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index c5c709cdc3ce..415c359de465 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -97,55 +97,6 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel)
97 } 97 }
98} 98}
99 99
100struct perf_counts *perf_counts__new(int ncpus, int nthreads)
101{
102 struct perf_counts *counts = zalloc(sizeof(*counts));
103
104 if (counts) {
105 struct xyarray *values;
106
107 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
108 if (!values) {
109 free(counts);
110 return NULL;
111 }
112
113 counts->values = values;
114 }
115
116 return counts;
117}
118
119void perf_counts__delete(struct perf_counts *counts)
120{
121 if (counts) {
122 xyarray__delete(counts->values);
123 free(counts);
124 }
125}
126
127static void perf_counts__reset(struct perf_counts *counts)
128{
129 xyarray__reset(counts->values);
130}
131
132void perf_evsel__reset_counts(struct perf_evsel *evsel)
133{
134 perf_counts__reset(evsel->counts);
135}
136
137int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
138{
139 evsel->counts = perf_counts__new(ncpus, nthreads);
140 return evsel->counts != NULL ? 0 : -ENOMEM;
141}
142
143void perf_evsel__free_counts(struct perf_evsel *evsel)
144{
145 perf_counts__delete(evsel->counts);
146 evsel->counts = NULL;
147}
148
149void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) 100void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
150{ 101{
151 int i; 102 int i;
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 0b897b083682..62448c8175d3 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -33,23 +33,6 @@ enum aggr_mode {
33 AGGR_THREAD, 33 AGGR_THREAD,
34}; 34};
35 35
36struct 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;
50 struct xyarray *values;
51};
52
53struct perf_stat_config { 36struct perf_stat_config {
54 enum aggr_mode aggr_mode; 37 enum aggr_mode aggr_mode;
55 bool scale; 38 bool scale;
@@ -57,12 +40,6 @@ struct perf_stat_config {
57 unsigned int interval; 40 unsigned int interval;
58}; 41};
59 42
60static inline struct perf_counts_values*
61perf_counts(struct perf_counts *counts, int cpu, int thread)
62{
63 return xyarray__entry(counts->values, cpu, thread);
64}
65
66void update_stats(struct stats *stats, u64 val); 43void update_stats(struct stats *stats, u64 val);
67double avg_stats(struct stats *stats); 44double avg_stats(struct stats *stats);
68double stddev_stats(struct stats *stats); 45double stddev_stats(struct stats *stats);
@@ -96,13 +73,6 @@ void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
96void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, 73void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
97 double avg, int cpu, enum aggr_mode aggr); 74 double avg, int cpu, enum aggr_mode aggr);
98 75
99struct perf_counts *perf_counts__new(int ncpus, int nthreads);
100void perf_counts__delete(struct perf_counts *counts);
101
102void perf_evsel__reset_counts(struct perf_evsel *evsel);
103int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads);
104void perf_evsel__free_counts(struct perf_evsel *evsel);
105
106void perf_evsel__reset_stat_priv(struct perf_evsel *evsel); 76void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
107int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel); 77int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
108void perf_evsel__free_stat_priv(struct perf_evsel *evsel); 78void perf_evsel__free_stat_priv(struct perf_evsel *evsel);