stat.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 {
  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. };
  30. struct perf_counts_values {
  31. union {
  32. struct {
  33. u64 val;
  34. u64 ena;
  35. u64 run;
  36. };
  37. u64 values[3];
  38. };
  39. };
  40. struct perf_counts {
  41. s8 scaled;
  42. struct perf_counts_values aggr;
  43. struct xyarray *values;
  44. };
  45. static inline struct perf_counts_values*
  46. perf_counts(struct perf_counts *counts, int cpu, int thread)
  47. {
  48. return xyarray__entry(counts->values, cpu, thread);
  49. }
  50. void update_stats(struct stats *stats, u64 val);
  51. double avg_stats(struct stats *stats);
  52. double stddev_stats(struct stats *stats);
  53. double rel_stddev_stats(double stddev, double avg);
  54. static inline void init_stats(struct stats *stats)
  55. {
  56. stats->n = 0.0;
  57. stats->mean = 0.0;
  58. stats->M2 = 0.0;
  59. stats->min = (u64) -1;
  60. stats->max = 0;
  61. }
  62. struct perf_evsel;
  63. struct perf_evlist;
  64. bool __perf_evsel_stat__is(struct perf_evsel *evsel,
  65. enum perf_stat_evsel_id id);
  66. #define perf_stat_evsel__is(evsel, id) \
  67. __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
  68. void perf_stat_evsel_id_init(struct perf_evsel *evsel);
  69. extern struct stats walltime_nsecs_stats;
  70. void perf_stat__reset_shadow_stats(void);
  71. void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
  72. int cpu);
  73. void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
  74. double avg, int cpu, enum aggr_mode aggr);
  75. struct perf_counts *perf_counts__new(int ncpus, int nthreads);
  76. void perf_counts__delete(struct perf_counts *counts);
  77. void perf_evsel__reset_counts(struct perf_evsel *evsel);
  78. int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads);
  79. void perf_evsel__free_counts(struct perf_evsel *evsel);
  80. void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
  81. int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
  82. void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
  83. int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
  84. int ncpus, int nthreads);
  85. void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
  86. int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
  87. int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
  88. void perf_evlist__free_stats(struct perf_evlist *evlist);
  89. void perf_evlist__reset_stats(struct perf_evlist *evlist);
  90. #endif