5 void update_stats(struct stats *stats, u64 val)
10 delta = val - stats->mean;
11 stats->mean += delta / stats->n;
12 stats->M2 += delta*(val - stats->mean);
21 double avg_stats(struct stats *stats)
27 * http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
29 * (\Sum n_i^2) - ((\Sum n_i)^2)/n
30 * s^2 = -------------------------------
33 * http://en.wikipedia.org/wiki/Stddev
35 * The std dev of the mean is related to the std dev by:
42 double stddev_stats(struct stats *stats)
44 double variance, variance_mean;
49 variance = stats->M2 / (stats->n - 1);
50 variance_mean = variance / stats->n;
52 return sqrt(variance_mean);
55 double rel_stddev_stats(double stddev, double avg)
60 pct = 100.0 * stddev/avg;
65 bool __perf_evsel_stat__is(struct perf_evsel *evsel,
66 enum perf_stat_evsel_id id)
68 struct perf_stat *ps = evsel->priv;
73 #define ID(id, name) [PERF_STAT_EVSEL_ID__##id] = #name
74 static const char *id_str[PERF_STAT_EVSEL_ID__MAX] = {
76 ID(CYCLES_IN_TX, cpu/cycles-t/),
77 ID(TRANSACTION_START, cpu/tx-start/),
78 ID(ELISION_START, cpu/el-start/),
79 ID(CYCLES_IN_TX_CP, cpu/cycles-ct/),
83 void perf_stat_evsel_id_init(struct perf_evsel *evsel)
85 struct perf_stat *ps = evsel->priv;
88 /* ps->id is 0 hence PERF_STAT_EVSEL_ID__NONE by default */
90 for (i = 0; i < PERF_STAT_EVSEL_ID__MAX; i++) {
91 if (!strcmp(perf_evsel__name(evsel), id_str[i])) {
98 struct perf_counts *perf_counts__new(int ncpus)
100 int size = sizeof(struct perf_counts) +
101 ncpus * sizeof(struct perf_counts_values);
106 void perf_counts__delete(struct perf_counts *counts)
111 static void perf_counts__reset(struct perf_counts *counts, int ncpus)
113 memset(counts, 0, (sizeof(*counts) +
114 (ncpus * sizeof(struct perf_counts_values))));
117 void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus)
119 perf_counts__reset(evsel->counts, ncpus);
122 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus)
124 evsel->counts = perf_counts__new(ncpus);
125 return evsel->counts != NULL ? 0 : -ENOMEM;
128 void perf_evsel__free_counts(struct perf_evsel *evsel)
130 perf_counts__delete(evsel->counts);
131 evsel->counts = NULL;