at v4.15-rc4 118 lines 3.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef __PERF_STATS_H 3#define __PERF_STATS_H 4 5#include <linux/types.h> 6#include <stdio.h> 7#include "xyarray.h" 8 9struct stats 10{ 11 double n, mean, M2; 12 u64 max, min; 13}; 14 15enum perf_stat_evsel_id { 16 PERF_STAT_EVSEL_ID__NONE = 0, 17 PERF_STAT_EVSEL_ID__CYCLES_IN_TX, 18 PERF_STAT_EVSEL_ID__TRANSACTION_START, 19 PERF_STAT_EVSEL_ID__ELISION_START, 20 PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP, 21 PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS, 22 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED, 23 PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED, 24 PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES, 25 PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES, 26 PERF_STAT_EVSEL_ID__SMI_NUM, 27 PERF_STAT_EVSEL_ID__APERF, 28 PERF_STAT_EVSEL_ID__MAX, 29}; 30 31struct perf_stat_evsel { 32 struct stats res_stats[3]; 33 enum perf_stat_evsel_id id; 34 u64 *group_data; 35}; 36 37enum aggr_mode { 38 AGGR_NONE, 39 AGGR_GLOBAL, 40 AGGR_SOCKET, 41 AGGR_CORE, 42 AGGR_THREAD, 43 AGGR_UNSET, 44}; 45 46struct perf_stat_config { 47 enum aggr_mode aggr_mode; 48 bool scale; 49 FILE *output; 50 unsigned int interval; 51}; 52 53void update_stats(struct stats *stats, u64 val); 54double avg_stats(struct stats *stats); 55double stddev_stats(struct stats *stats); 56double rel_stddev_stats(double stddev, double avg); 57 58static inline void init_stats(struct stats *stats) 59{ 60 stats->n = 0.0; 61 stats->mean = 0.0; 62 stats->M2 = 0.0; 63 stats->min = (u64) -1; 64 stats->max = 0; 65} 66 67struct perf_evsel; 68struct perf_evlist; 69 70bool __perf_evsel_stat__is(struct perf_evsel *evsel, 71 enum perf_stat_evsel_id id); 72 73#define perf_stat_evsel__is(evsel, id) \ 74 __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) 75 76void perf_stat_evsel_id_init(struct perf_evsel *evsel); 77 78extern struct stats walltime_nsecs_stats; 79 80typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, 81 const char *fmt, double val); 82typedef void (*new_line_t )(void *ctx); 83 84void perf_stat__init_shadow_stats(void); 85void perf_stat__reset_shadow_stats(void); 86void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count, 87 int cpu); 88struct perf_stat_output_ctx { 89 void *ctx; 90 print_metric_t print_metric; 91 new_line_t new_line; 92 bool force_header; 93}; 94 95struct rblist; 96void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 97 double avg, int cpu, 98 struct perf_stat_output_ctx *out, 99 struct rblist *metric_events); 100void perf_stat__collect_metric_expr(struct perf_evlist *); 101 102int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); 103void perf_evlist__free_stats(struct perf_evlist *evlist); 104void perf_evlist__reset_stats(struct perf_evlist *evlist); 105 106int perf_stat_process_counter(struct perf_stat_config *config, 107 struct perf_evsel *counter); 108struct perf_tool; 109union perf_event; 110struct perf_session; 111int perf_event__process_stat_event(struct perf_tool *tool, 112 union perf_event *event, 113 struct perf_session *session); 114 115size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); 116size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); 117size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); 118#endif