stat.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. void perf_stat__reset_shadow_stats(void);
  58. void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
  59. int cpu);
  60. void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
  61. double avg, int cpu, enum aggr_mode aggr);
  62. void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
  63. int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
  64. void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
  65. int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
  66. int ncpus, int nthreads);
  67. void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
  68. int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
  69. int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
  70. void perf_evlist__free_stats(struct perf_evlist *evlist);
  71. void perf_evlist__reset_stats(struct perf_evlist *evlist);
  72. int perf_stat_process_counter(struct perf_stat_config *config,
  73. struct perf_evsel *counter);
  74. #endif