stat.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 "xyarray.h"
  7. #include "rblist.h"
  8. struct stats {
  9. double n, mean, M2;
  10. u64 max, min;
  11. };
  12. enum perf_stat_evsel_id {
  13. PERF_STAT_EVSEL_ID__NONE = 0,
  14. PERF_STAT_EVSEL_ID__CYCLES_IN_TX,
  15. PERF_STAT_EVSEL_ID__TRANSACTION_START,
  16. PERF_STAT_EVSEL_ID__ELISION_START,
  17. PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP,
  18. PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS,
  19. PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED,
  20. PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED,
  21. PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES,
  22. PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES,
  23. PERF_STAT_EVSEL_ID__SMI_NUM,
  24. PERF_STAT_EVSEL_ID__APERF,
  25. PERF_STAT_EVSEL_ID__MAX,
  26. };
  27. struct perf_stat_evsel {
  28. struct stats res_stats[3];
  29. enum perf_stat_evsel_id id;
  30. u64 *group_data;
  31. };
  32. enum aggr_mode {
  33. AGGR_NONE,
  34. AGGR_GLOBAL,
  35. AGGR_SOCKET,
  36. AGGR_CORE,
  37. AGGR_THREAD,
  38. AGGR_UNSET,
  39. };
  40. enum {
  41. CTX_BIT_USER = 1 << 0,
  42. CTX_BIT_KERNEL = 1 << 1,
  43. CTX_BIT_HV = 1 << 2,
  44. CTX_BIT_HOST = 1 << 3,
  45. CTX_BIT_IDLE = 1 << 4,
  46. CTX_BIT_MAX = 1 << 5,
  47. };
  48. #define NUM_CTX CTX_BIT_MAX
  49. enum stat_type {
  50. STAT_NONE = 0,
  51. STAT_NSECS,
  52. STAT_CYCLES,
  53. STAT_STALLED_CYCLES_FRONT,
  54. STAT_STALLED_CYCLES_BACK,
  55. STAT_BRANCHES,
  56. STAT_CACHEREFS,
  57. STAT_L1_DCACHE,
  58. STAT_L1_ICACHE,
  59. STAT_LL_CACHE,
  60. STAT_ITLB_CACHE,
  61. STAT_DTLB_CACHE,
  62. STAT_CYCLES_IN_TX,
  63. STAT_TRANSACTION,
  64. STAT_ELISION,
  65. STAT_TOPDOWN_TOTAL_SLOTS,
  66. STAT_TOPDOWN_SLOTS_ISSUED,
  67. STAT_TOPDOWN_SLOTS_RETIRED,
  68. STAT_TOPDOWN_FETCH_BUBBLES,
  69. STAT_TOPDOWN_RECOVERY_BUBBLES,
  70. STAT_SMI_NUM,
  71. STAT_APERF,
  72. STAT_MAX
  73. };
  74. struct runtime_stat {
  75. struct rblist value_list;
  76. };
  77. struct perf_stat_config {
  78. enum aggr_mode aggr_mode;
  79. bool scale;
  80. FILE *output;
  81. unsigned int interval;
  82. unsigned int timeout;
  83. int times;
  84. struct runtime_stat *stats;
  85. int stats_num;
  86. };
  87. void update_stats(struct stats *stats, u64 val);
  88. double avg_stats(struct stats *stats);
  89. double stddev_stats(struct stats *stats);
  90. double rel_stddev_stats(double stddev, double avg);
  91. static inline void init_stats(struct stats *stats)
  92. {
  93. stats->n = 0.0;
  94. stats->mean = 0.0;
  95. stats->M2 = 0.0;
  96. stats->min = (u64) -1;
  97. stats->max = 0;
  98. }
  99. struct perf_evsel;
  100. struct perf_evlist;
  101. struct perf_aggr_thread_value {
  102. struct perf_evsel *counter;
  103. int id;
  104. double uval;
  105. u64 val;
  106. u64 run;
  107. u64 ena;
  108. };
  109. bool __perf_evsel_stat__is(struct perf_evsel *evsel,
  110. enum perf_stat_evsel_id id);
  111. #define perf_stat_evsel__is(evsel, id) \
  112. __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
  113. extern struct runtime_stat rt_stat;
  114. extern struct stats walltime_nsecs_stats;
  115. typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
  116. const char *fmt, double val);
  117. typedef void (*new_line_t )(void *ctx);
  118. void runtime_stat__init(struct runtime_stat *st);
  119. void runtime_stat__exit(struct runtime_stat *st);
  120. void perf_stat__init_shadow_stats(void);
  121. void perf_stat__reset_shadow_stats(void);
  122. void perf_stat__reset_shadow_per_stat(struct runtime_stat *st);
  123. void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count,
  124. int cpu, struct runtime_stat *st);
  125. struct perf_stat_output_ctx {
  126. void *ctx;
  127. print_metric_t print_metric;
  128. new_line_t new_line;
  129. bool force_header;
  130. };
  131. void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
  132. double avg, int cpu,
  133. struct perf_stat_output_ctx *out,
  134. struct rblist *metric_events,
  135. struct runtime_stat *st);
  136. void perf_stat__collect_metric_expr(struct perf_evlist *);
  137. int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
  138. void perf_evlist__free_stats(struct perf_evlist *evlist);
  139. void perf_evlist__reset_stats(struct perf_evlist *evlist);
  140. void perf_evlist__reset_prev_raw_counts(struct perf_evlist *evlist);
  141. int perf_stat_process_counter(struct perf_stat_config *config,
  142. struct perf_evsel *counter);
  143. struct perf_tool;
  144. union perf_event;
  145. struct perf_session;
  146. int perf_event__process_stat_event(struct perf_tool *tool,
  147. union perf_event *event,
  148. struct perf_session *session);
  149. size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
  150. size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
  151. size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
  152. #endif