Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Inner workings of Performance Monitor Counters on the xbox 360;
  4. // they let vprof track L2 dcache misses, LHS, etc.
  5. //
  6. //=============================================================================//
  7. #include "pch_tier0.h"
  8. #ifndef _X360
  9. #error pmc360.cpp must only be compiled for XBOX360!
  10. #else
  11. #include "tier0/platform.h"
  12. #include "tier0/vprof.h"
  13. #include <pmcpbsetup.h>
  14. #include "tier0/dbg.h"
  15. #include "pmc360.h"
  16. #include "tier0/memdbgon.h"
  17. static bool s_bInitialized = false;
  18. CPMCData::CPMCData()
  19. {
  20. }
  21. void CPMCData::InitializeOnceProgramWide( void )
  22. {
  23. #if !defined( _CERT )
  24. // Select a set of sixteen counters
  25. DmPMCInstallAndStart( PMC_SETUP_FLUSHREASONS_PB0T0 );
  26. // Reset the Performance Monitor Counters in preparation for a new sampling run.
  27. DmPMCResetCounters();
  28. #endif
  29. s_bInitialized = true;
  30. }
  31. bool CPMCData::IsInitialized()
  32. {
  33. return s_bInitialized;
  34. }
  35. void CPMCData::Start()
  36. {
  37. #if !defined( _CERT )
  38. // stop the stopwatches, save off the counter, start them again.
  39. DmPMCStop();
  40. PMCState pmcstate;
  41. // Get the counters.
  42. DmPMCGetCounters( &pmcstate );
  43. // in the default state as set up by InitializeOnceProgramWide,
  44. // counters 9 and 6 are L2 misses and LHS respectively
  45. m_OnStart.L2CacheMiss = pmcstate.pmc[9];
  46. m_OnStart.LHS = pmcstate.pmc[6];
  47. DmPMCStart();
  48. #endif
  49. }
  50. void CPMCData::End()
  51. {
  52. #if !defined( _CERT )
  53. DmPMCStop();
  54. // get end-state counters
  55. PMCState pmcstate;
  56. // Get the counters.
  57. DmPMCGetCounters( &pmcstate );
  58. // in the default state as set up by InitializeOnceProgramWide,
  59. // counters 9 and 6 are l2 misses and LHS respectively
  60. const uint64 &endL2 = pmcstate.pmc[9];
  61. const uint64 &endLHS = pmcstate.pmc[6];
  62. // compute delta between end and start. Because these are
  63. // unsigned nums, even in overflow this still works out
  64. // correctly under modular arithmetic.
  65. m_Delta.L2CacheMiss = endL2 - m_OnStart.L2CacheMiss;
  66. m_Delta.LHS = endLHS - m_OnStart.LHS;
  67. DmPMCStart();
  68. #endif
  69. }
  70. #endif