stat.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_stat_config {
  31. enum aggr_mode aggr_mode;
  32. bool scale;
  33. FILE *output;
  34. unsigned int interval;
  35. };
  36. void update_stats(struct stats *stats, u64 val);
  37. double avg_stats(struct stats *stats);
  38. double stddev_stats(struct stats *stats);
  39. double rel_stddev_stats(double stddev, double avg);
  40. static inline void init_stats(struct stats *stats)
  41. {
  42. stats->n = 0.0;
  43. stats->mean = 0.0;
  44. stats->M2 = 0.0;
  45. stats->min = (u64) -1;
  46. stats->max = 0;
  47. }
  48. struct perf_evsel;
  49. struct perf_evlist;
  50. bool __perf_evsel_stat__is(struct perf_evsel *evsel,
  51. enum perf_stat_evsel_id id);
  52. #define perf_stat_evsel__is(evsel, id) \
  53. __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id)
  54. void perf_stat_evsel_id_init(struct perf_evsel *evsel);
  55. extern struct stats walltime_nsecs_stats;
  56. void perf_stat__reset_shadow_stats(void);
  57. void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
  58. int cpu);
  59. void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
  60. double avg, int cpu, enum aggr_mode aggr);
  61. void perf_evsel__reset_stat_priv(struct perf_evsel *evsel);
  62. int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel);
  63. void perf_evsel__free_stat_priv(struct perf_evsel *evsel);
  64. int perf_evsel__alloc_prev_raw_counts(struct perf_evsel *evsel,
  65. int ncpus, int nthreads);
  66. void perf_evsel__free_prev_raw_counts(struct perf_evsel *evsel);
  67. int perf_evsel__alloc_stats(struct perf_evsel *evsel, bool alloc_raw);
  68. int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
  69. void perf_evlist__free_stats(struct perf_evlist *evlist);
  70. void perf_evlist__reset_stats(struct perf_evlist *evlist);
  71. int perf_stat_process_counter(struct perf_stat_config *config,
  72. struct perf_evsel *counter);
  73. #endif