stat.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __PERF_STATS_H
  3. #define __PERF_STATS_H
  4. #include <linux/types.h>
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/resource.h>
  8. #include "rblist.h"
  9. struct perf_cpu_map;
  10. struct perf_stat_config;
  11. struct timespec;
  12. struct stats {
  13. double n, mean, M2;
  14. u64 max, min;
  15. };
  16. enum perf_stat_evsel_id {
  17. PERF_STAT_EVSEL_ID__NONE = 0,
  18. PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
  19. PERF_STAT_EVSEL_ID__TRANSACTION_START,
  20. PERF_STAT_EVSEL_ID__ELISION_START,
  21. PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
  22. PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS,
  23. PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED,
  24. PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED,
  25. PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES,
  26. PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES,
  27. PERF_STAT_EVSEL_ID__TOPDOWN_RETIRING,
  28. PERF_STAT_EVSEL_ID__TOPDOWN_BAD_SPEC,
  29. PERF_STAT_EVSEL_ID__TOPDOWN_FE_BOUND,
  30. PERF_STAT_EVSEL_ID__TOPDOWN_BE_BOUND,
  31. PERF_STAT_EVSEL_ID__SMI_NUM,
  32. PERF_STAT_EVSEL_ID__APERF,
  33. PERF_STAT_EVSEL_ID__MAX,
  34. };
  35. struct perf_stat_evsel {
  36. struct stats res_stats[3];
  37. enum perf_stat_evsel_id id;
  38. u64 *group_data;
  39. };
  40. enum aggr_mode {
  41. AGGR_NONE,
  42. AGGR_GLOBAL,
  43. AGGR_SOCKET,
  44. AGGR_DIE,
  45. AGGR_CORE,
  46. AGGR_THREAD,
  47. AGGR_UNSET,
  48. AGGR_NODE,
  49. };
  50. enum {
  51. CTX_BIT_USER = 1 << 0,
  52. CTX_BIT_KERNEL = 1 << 1,
  53. CTX_BIT_HV = 1 << 2,
  54. CTX_BIT_HOST = 1 << 3,
  55. CTX_BIT_IDLE = 1 << 4,
  56. CTX_BIT_MAX = 1 << 5,
  57. };
  58. #define NUM_CTX CTX_BIT_MAX
  59. enum stat_type {
  60. STAT_NONE = 0,
  61. STAT_NSECS,
  62. STAT_CYCLES,
  63. STAT_STALLED_CYCLES_FRONT,
  64. STAT_STALLED_CYCLES_BACK,
  65. STAT_BRANCHES,
  66. STAT_CACHEREFS,
  67. STAT_L1_DCACHE,
  68. STAT_L1_ICACHE,
  69. STAT_LL_CACHE,
  70. STAT_ITLB_CACHE,
  71. STAT_DTLB_CACHE,
  72. STAT_CYCLES_IN_TX,
  73. STAT_TRANSACTION,
  74. STAT_ELISION,
  75. STAT_TOPDOWN_TOTAL_SLOTS,
  76. STAT_TOPDOWN_SLOTS_ISSUED,
  77. STAT_TOPDOWN_SLOTS_RETIRED,
  78. STAT_TOPDOWN_FETCH_BUBBLES,
  79. STAT_TOPDOWN_RECOVERY_BUBBLES,
  80. STAT_TOPDOWN_RETIRING,
  81. STAT_TOPDOWN_BAD_SPEC,
  82. STAT_TOPDOWN_FE_BOUND,
  83. STAT_TOPDOWN_BE_BOUND,
  84. STAT_SMI_NUM,
  85. STAT_APERF,
  86. STAT_MAX
  87. };
  88. struct runtime_stat {
  89. struct rblist value_list;
  90. };
  91. typedef int (*aggr_get_id_t)(struct perf_stat_config *config,
  92. struct perf_cpu_map *m, int cpu);
  93. struct perf_stat_config {
  94. enum aggr_mode aggr_mode;
  95. bool scale;
  96. bool no_inherit;
  97. bool identifier;
  98. bool csv_output;
  99. bool interval_clear;
  100. bool metric_only;
  101. bool null_run;
  102. bool ru_display;
  103. bool big_num;
  104. bool no_merge;
  105. bool walltime_run_table;
  106. bool all_kernel;
  107. bool all_user;
  108. bool percore_show_thread;
  109. bool summary;
  110. bool metric_no_group;
  111. bool metric_no_merge;
  112. bool stop_read_counter;
  113. FILE *output;
  114. unsigned int interval;
  115. unsigned int timeout;
  116. int initial_delay;
  117. unsigned int unit_width;
  118. unsigned int metric_only_len;
  119. int times;
  120. int run_count;
  121. int print_free_counters_hint;
  122. int print_mixed_hw_group_error;
  123. struct runtime_stat *stats;
  124. int stats_num;
  125. const char *csv_sep;
  126. struct stats *walltime_nsecs_stats;
  127. struct rusage ru_data;
  128. struct perf_cpu_map *aggr_map;
  129. aggr_get_id_t aggr_get_id;
  130. struct perf_cpu_map *cpus_aggr_map;
  131. u64 *walltime_run;
  132. struct rblist metric_events;
  133. int ctl_fd;
  134. int ctl_fd_ack;
  135. bool ctl_fd_close;
  136. const char *cgroup_list;
  137. };
  138. void perf_stat__set_big_num(int set);
  139. void update_stats(struct stats *stats, u64 val);
  140. double avg_stats(struct stats *stats);
  141. double stddev_stats(struct stats *stats);
  142. double rel_stddev_stats(double stddev, double avg);
  143. static inline void init_stats(struct stats *stats)
  144. {
  145. stats->n = 0.0;
  146. stats->mean = 0.0;
  147. stats->M2 = 0.0;
  148. stats->min = (u64) -1;
  149. stats->max = 0;
  150. }
  151. struct evsel;
  152. struct evlist;
  153. struct perf_aggr_thread_value {
  154. struct evsel *counter;
  155. int id;
  156. double uval;
  157. u64 val;
  158. u64 run;
  159. u64 ena;
  160. };
  161. bool __perf_evsel_stat__is(struct evsel *evsel,
  162. enum perf_stat_evsel_id id);
  163. #define perf_stat_evsel__is(evsel, id) \
  164. __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
  165. extern struct runtime_stat rt_stat;
  166. extern struct stats walltime_nsecs_stats;
  167. typedef void (*print_metric_t)(struct perf_stat_config *config,
  168. void *ctx, const char *color, const char *unit,
  169. const char *fmt, double val);
  170. typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx);
  171. void runtime_stat__init(struct runtime_stat *st);
  172. void runtime_stat__exit(struct runtime_stat *st);
  173. void perf_stat__init_shadow_stats(void);
  174. void perf_stat__reset_shadow_stats(void);
  175. void perf_stat__reset_shadow_per_stat(struct runtime_stat *st);
  176. void perf_stat__update_shadow_stats(struct evsel *counter, u64 count,
  177. int cpu, struct runtime_stat *st);
  178. struct perf_stat_output_ctx {
  179. void *ctx;
  180. print_metric_t print_metric;
  181. new_line_t new_line;
  182. bool force_header;
  183. };
  184. void perf_stat__print_shadow_stats(struct perf_stat_config *config,
  185. struct evsel *evsel,
  186. double avg, int cpu,
  187. struct perf_stat_output_ctx *out,
  188. struct rblist *metric_events,
  189. struct runtime_stat *st);
  190. void perf_stat__collect_metric_expr(struct evlist *);
  191. int perf_evlist__alloc_stats(struct evlist *evlist, bool alloc_raw);
  192. void perf_evlist__free_stats(struct evlist *evlist);
  193. void perf_evlist__reset_stats(struct evlist *evlist);
  194. void perf_evlist__reset_prev_raw_counts(struct evlist *evlist);
  195. void perf_evlist__copy_prev_raw_counts(struct evlist *evlist);
  196. void perf_evlist__save_aggr_prev_raw_counts(struct evlist *evlist);
  197. int perf_stat_process_counter(struct perf_stat_config *config,
  198. struct evsel *counter);
  199. struct perf_tool;
  200. union perf_event;
  201. struct perf_session;
  202. struct target;
  203. int perf_event__process_stat_event(struct perf_session *session,
  204. union perf_event *event);
  205. size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
  206. size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
  207. size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
  208. int create_perf_stat_counter(struct evsel *evsel,
  209. struct perf_stat_config *config,
  210. struct target *target,
  211. int cpu);
  212. void
  213. perf_evlist__print_counters(struct evlist *evlist,
  214. struct perf_stat_config *config,
  215. struct target *_target,
  216. struct timespec *ts,
  217. int argc, const char **argv);
  218. struct metric_expr;
  219. double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st);
  220. #endif