stat.h 2.8 KB

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