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