Counter Strike : Global Offensive Source Code
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.

85 lines
2.1 KiB

  1. //========= Copyright � 1996-2006, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose: routines to access Windows Performance counter data
  4. //
  5. //=============================================================================
  6. #ifndef WINPERFCOUNTER_H
  7. #define WINPERFCOUNTER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. enum EFormat
  11. {
  12. k_EFormatInt = 0, // Signed int
  13. k_EFormatFloat, // Floating point
  14. };
  15. struct PerfCounter_t
  16. {
  17. const char *m_rgchPerfObject;
  18. const char *m_rgchPerfObjectAlternative; // alternative object to query if the first one is not found - can be NULL
  19. size_t m_statsOffset;
  20. EFormat m_eFmt;
  21. float m_fUnsetValue;
  22. bool m_bAssertOnFailure;
  23. bool m_bCounterRequiresRollup; // Counters requiring rollup should be adjacent
  24. };
  25. class CWinPerfCountersPriv;
  26. class CWinPerfCounters
  27. {
  28. public:
  29. CWinPerfCounters( );
  30. ~CWinPerfCounters();
  31. bool Init( const PerfCounter_t *counterMap, int nCounters );
  32. bool TakeSample();
  33. bool WriteStats( void *pStatsStruct );
  34. void Shutdown();
  35. #ifdef DBGFLAG_VALIDATE
  36. void Validate( CValidator &validator, const char *pchName ); // Validate our internal structures
  37. #endif // DBGFLAG_VALIDATE
  38. private:
  39. CWinPerfCountersPriv *m_pPrivData;
  40. const PerfCounter_t *m_pPerfCounterMap;
  41. int m_nCounters;
  42. bool m_bInited;
  43. };
  44. class CWinNetworkPerfCounters
  45. {
  46. public:
  47. CWinNetworkPerfCounters( );
  48. ~CWinNetworkPerfCounters();
  49. bool Init();
  50. bool TakeSample();
  51. bool WriteStats( uint64 *pu64BytesSentPerSec, uint64 *pu64BytesRecvPerSec );
  52. void Shutdown();
  53. #ifdef DBGFLAG_VALIDATE
  54. void Validate( CValidator &validator, const char *pchName ); // Validate our internal structures
  55. #endif // DBGFLAG_VALIDATE
  56. private:
  57. CWinPerfCounters m_PerfCounters;
  58. static const uint32 sm_unMaxNetworkInterfacesToMeasure = 32;
  59. uint32 m_unNumInterfaces;
  60. struct Stats_t
  61. {
  62. uint32 m_rgunNetworkBytesSentStats[sm_unMaxNetworkInterfacesToMeasure];
  63. uint32 m_rgunNetworkBytesReceivedStats[sm_unMaxNetworkInterfacesToMeasure];
  64. } m_Stats;
  65. // One each for bytes sent and received
  66. PerfCounter_t m_rgPerfCounterInfo[2 * sm_unMaxNetworkInterfacesToMeasure];
  67. bool m_bInited;
  68. };
  69. #endif /* _WIN32 */
  70. #endif /* WINPERFCOUNTER_H */