bottlegraph.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "bottlegraph.h"
  2. #include "thread_manager.h"
  3. #include "stats.h"
  4. // Implement data needed to plot bottle graphs [Du Bois, OOSPLA 2013]
  5. BottleGraphManager::BottleGraphManager(int max_threads)
  6. : m_running(max_threads, false)
  7. , m_contrib(max_threads, SubsecondTime::Zero())
  8. , m_runtime(max_threads, SubsecondTime::Zero())
  9. {
  10. }
  11. void BottleGraphManager::threadStart(thread_id_t thread_id)
  12. {
  13. m_contrib[thread_id] = SubsecondTime::Zero();
  14. m_runtime[thread_id] = SubsecondTime::Zero();
  15. registerStatsMetric("thread", thread_id, "bottle_contrib_time", &m_contrib[thread_id]);
  16. registerStatsMetric("thread", thread_id, "bottle_runtime_time", &m_runtime[thread_id]);
  17. }
  18. void BottleGraphManager::update(SubsecondTime time, thread_id_t thread_id, bool running)
  19. {
  20. if (time > m_time_last)
  21. {
  22. UInt64 n_running = 0;
  23. for(thread_id_t _thread_id = 0; _thread_id < (thread_id_t)Sim()->getThreadManager()->getNumThreads(); ++_thread_id)
  24. if (m_running[_thread_id])
  25. ++n_running;
  26. SubsecondTime time_delta = time - m_time_last;
  27. if (n_running)
  28. for(thread_id_t _thread_id = 0; _thread_id < (thread_id_t)Sim()->getThreadManager()->getNumThreads(); ++_thread_id)
  29. if (m_running[_thread_id])
  30. {
  31. m_contrib[_thread_id] += time_delta / n_running;
  32. m_runtime[_thread_id] += time_delta;
  33. }
  34. m_time_last = time;
  35. }
  36. if (thread_id != INVALID_THREAD_ID)
  37. m_running[thread_id] = running;
  38. }