hooks_manager_init.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "hooks_manager.h"
  2. #include "hooks_py.h"
  3. #include "subsecond_time.h"
  4. #include "fixed_point.h"
  5. #include "simulator.h"
  6. #include "stats.h"
  7. #include "dvfs_manager.h"
  8. // Example live-analysis code: print out the IPC for core 0
  9. void hook_print_core0_ipc(void*, subsecond_time_t _time)
  10. {
  11. SubsecondTime time(_time);
  12. static StatsMetricBase *s_time = NULL;
  13. static UInt64 l_time = 0;
  14. static StatsMetricBase *s_instructions = NULL;
  15. static UInt64 l_instructions = 0;
  16. static const ComponentPeriod *clock = NULL;
  17. if (!s_time) {
  18. s_time = Sim()->getStatsManager()->getMetricObject("performance_model", 0, "elapsed_time");
  19. s_instructions = Sim()->getStatsManager()->getMetricObject("performance_model", 0, "instruction_count");
  20. clock = Sim()->getDvfsManager()->getCoreDomain(0);
  21. LOG_ASSERT_ERROR(s_time && s_instructions && clock, "Could not find stats / dvfs domain for core 0");
  22. } else {
  23. UInt64 d_instructions = s_instructions->recordMetric() - l_instructions;
  24. UInt64 d_time = s_time->recordMetric() - l_time;
  25. UInt64 d_cycles = SubsecondTime::divideRounded(SubsecondTime::FS(d_time), *clock);
  26. if (d_cycles) {
  27. FixedPoint ipc = FixedPoint(d_instructions) / d_cycles;
  28. printf("t = %" PRIu64 " ns, ipKc = %" PRId64 "\n", time.getNS(), FixedPoint::floor(ipc * 1000));
  29. }
  30. }
  31. l_time = s_time->recordMetric();
  32. l_instructions = s_instructions->recordMetric();
  33. }
  34. // Handy place to instantiate all classes that need to register hooks but are otherwise unconnected to the basic simulator
  35. void HooksManager::init(void)
  36. {
  37. HooksPy::init();
  38. //registerHook(HookType::HOOK_PERIODIC, (HookCallbackFunc)hook_print_core0_ipc, NULL);
  39. }
  40. void HooksManager::fini(void)
  41. {
  42. HooksPy::fini();
  43. }