stat.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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__MAX,
  18. };
  19. struct perf_stat_evsel {
  20. struct stats res_stats[3];
  21. enum perf_stat_evsel_id id;
  22. };
  23. enum aggr_mode {
  24. AGGR_NONE,
  25. AGGR_GLOBAL,
  26. AGGR_SOCKET,
  27. AGGR_CORE,
  28. AGGR_THREAD,
  29. AGGR_UNSET,
  30. };
  31. struct perf_stat_config {
  32. enum aggr_mode aggr_mode;
  33. bool scale;
  34. FILE *output;
  35. unsigned int interval;
  36. };
  37. void update_stats(struct stats *stats, u64 val);
  38. double avg_stats(struct stats *stats);
  39. double stddev_stats(struct stats *stats);
  40. double rel_stddev_stats(double stddev, double avg);
  41. static inline void init_stats(struct stats *stats)
  42. {
  43. stats->n = 0.0;
  44. stats->mean = 0.0;
  45. stats->M2 = 0.0;
  46. stats->min = (u64) -1;
  47. stats->max = 0;
  48. }
  49. struct perf_evsel;
  50. struct perf_evlist;
  51. bool __perf_evsel_stat__is(struct perf_evsel *evsel,
  52. enum perf_stat_evsel_id id);
  53. #define perf_stat_evsel__is(evsel, id) \
  54. __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
  55. void perf_stat_evsel_id_init(struct perf_evsel *evsel);
  56. extern struct stats walltime_nsecs_stats;
  57. typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
  58. const char *fmt, double val);
  59. typedef void (*new_line_t )(void *ctx);
  60. void perf_stat__init_shadow_stats(void);
  61. void perf_stat__reset_shadow_stats(void);
  62. void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
  63. int cpu);
  64. struct perf_stat_output_ctx {
  65. void *ctx;
  66. print_metric_t print_metric;
  67. new_line_t new_line;
  68. };
  69. void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
  70. double avg, int cpu,
  71. struct perf_stat_output_ctx *out);
  72. int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
  73. void perf_evlist__free_stats(struct perf_evlist *evlist);
  74. void perf_evlist__reset_stats(struct perf_evlist *evlist);
  75. int perf_stat_process_counter(struct perf_stat_config *config,
  76. struct perf_evsel *counter);
  77. struct perf_tool;
  78. union perf_event;
  79. struct perf_session;
  80. int perf_event__process_stat_event(struct perf_tool *tool,
  81. union perf_event *event,
  82. struct perf_session *session);
  83. size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
  84. size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
  85. size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
  86. #endif