stat.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <linux/compiler.h>
  2. #include "event.h"
  3. #include "tests.h"
  4. #include "stat.h"
  5. #include "counts.h"
  6. #include "debug.h"
  7. static bool has_term(struct stat_config_event *config,
  8. u64 tag, u64 val)
  9. {
  10. unsigned i;
  11. for (i = 0; i < config->nr; i++) {
  12. if ((config->data[i].tag == tag) &&
  13. (config->data[i].val == val))
  14. return true;
  15. }
  16. return false;
  17. }
  18. static int process_stat_config_event(struct perf_tool *tool __maybe_unused,
  19. union perf_event *event,
  20. struct perf_sample *sample __maybe_unused,
  21. struct machine *machine __maybe_unused)
  22. {
  23. struct stat_config_event *config = &event->stat_config;
  24. struct perf_stat_config stat_config;
  25. #define HAS(term, val) \
  26. has_term(config, PERF_STAT_CONFIG_TERM__##term, val)
  27. TEST_ASSERT_VAL("wrong nr", config->nr == PERF_STAT_CONFIG_TERM__MAX);
  28. TEST_ASSERT_VAL("wrong aggr_mode", HAS(AGGR_MODE, AGGR_CORE));
  29. TEST_ASSERT_VAL("wrong scale", HAS(SCALE, 1));
  30. TEST_ASSERT_VAL("wrong interval", HAS(INTERVAL, 1));
  31. #undef HAS
  32. perf_event__read_stat_config(&stat_config, config);
  33. TEST_ASSERT_VAL("wrong aggr_mode", stat_config.aggr_mode == AGGR_CORE);
  34. TEST_ASSERT_VAL("wrong scale", stat_config.scale == 1);
  35. TEST_ASSERT_VAL("wrong interval", stat_config.interval == 1);
  36. return 0;
  37. }
  38. int test__synthesize_stat_config(int subtest __maybe_unused)
  39. {
  40. struct perf_stat_config stat_config = {
  41. .aggr_mode = AGGR_CORE,
  42. .scale = 1,
  43. .interval = 1,
  44. };
  45. TEST_ASSERT_VAL("failed to synthesize stat_config",
  46. !perf_event__synthesize_stat_config(NULL, &stat_config, process_stat_config_event, NULL));
  47. return 0;
  48. }
  49. static int process_stat_event(struct perf_tool *tool __maybe_unused,
  50. union perf_event *event,
  51. struct perf_sample *sample __maybe_unused,
  52. struct machine *machine __maybe_unused)
  53. {
  54. struct stat_event *st = &event->stat;
  55. TEST_ASSERT_VAL("wrong cpu", st->cpu == 1);
  56. TEST_ASSERT_VAL("wrong thread", st->thread == 2);
  57. TEST_ASSERT_VAL("wrong id", st->id == 3);
  58. TEST_ASSERT_VAL("wrong val", st->val == 100);
  59. TEST_ASSERT_VAL("wrong run", st->ena == 200);
  60. TEST_ASSERT_VAL("wrong ena", st->run == 300);
  61. return 0;
  62. }
  63. int test__synthesize_stat(int subtest __maybe_unused)
  64. {
  65. struct perf_counts_values count;
  66. count.val = 100;
  67. count.ena = 200;
  68. count.run = 300;
  69. TEST_ASSERT_VAL("failed to synthesize stat_config",
  70. !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, NULL));
  71. return 0;
  72. }
  73. static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
  74. union perf_event *event,
  75. struct perf_sample *sample __maybe_unused,
  76. struct machine *machine __maybe_unused)
  77. {
  78. struct stat_round_event *stat_round = &event->stat_round;
  79. TEST_ASSERT_VAL("wrong time", stat_round->time == 0xdeadbeef);
  80. TEST_ASSERT_VAL("wrong type", stat_round->type == PERF_STAT_ROUND_TYPE__INTERVAL);
  81. return 0;
  82. }
  83. int test__synthesize_stat_round(int subtest __maybe_unused)
  84. {
  85. TEST_ASSERT_VAL("failed to synthesize stat_config",
  86. !perf_event__synthesize_stat_round(NULL, 0xdeadbeef, PERF_STAT_ROUND_TYPE__INTERVAL,
  87. process_stat_round_event, NULL));
  88. return 0;
  89. }