Source code of Windows XP (NT5)
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.

106 lines
2.6 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: IdleStat.cpp
  4. //
  5. // Module: CMMON32.EXE
  6. //
  7. // Synopsis: Implementation of class CIdleStatistics
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // Author: Fengsun Created 10/01/97
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #include "IdleStat.h"
  16. //+---------------------------------------------------------------------------
  17. //
  18. // CIdleStatistics::Start()
  19. //
  20. // Synopsis: Start the idle statistics
  21. //
  22. // Arguments: dwThreshold: The idle threshold. Traffic in a minute Less than
  23. // the threshold is considered idle
  24. // dwTimeOut: Idle time out in minisecond
  25. //
  26. // History: fengsun created on 10/1/97
  27. //
  28. //----------------------------------------------------------------------------
  29. void CIdleStatistics::Start(DWORD dwThreshold, DWORD dwTimeOut)
  30. {
  31. MYDBGASSERT(dwTimeOut != 0);
  32. m_dwThreshold = dwThreshold;
  33. m_dwTimeOut = dwTimeOut;
  34. m_dwStartIdleTime = 0;
  35. m_DataPointsRing.Reset();
  36. }
  37. //+---------------------------------------------------------------------------
  38. //
  39. // CIdleStatistics::UpdateEveryInterval()
  40. //
  41. // Synopsis: This function should be call every Interval with a updated statistic
  42. //
  43. // Arguments: dwTraffic: the updated statistics
  44. //
  45. //
  46. // History: fengsun created on 10/1/97
  47. //
  48. //----------------------------------------------------------------------------
  49. void CIdleStatistics::UpdateEveryInterval(DWORD dwTraffic)
  50. {
  51. DWORD dwLast = m_DataPointsRing.GetOldest();
  52. m_DataPointsRing.Add(dwTraffic);
  53. if (dwLast == 0) // Started less than a minute
  54. {
  55. return;
  56. }
  57. if (dwTraffic - dwLast > m_dwThreshold)
  58. {
  59. //
  60. // Not idle
  61. //
  62. m_dwStartIdleTime = 0;
  63. }
  64. else
  65. {
  66. if (m_dwStartIdleTime == 0)
  67. {
  68. //
  69. // We are already idle for 1 minute
  70. //
  71. m_dwStartIdleTime = GetTickCount() - IDLE_INTERVAL;
  72. }
  73. }
  74. }
  75. #ifdef DEBUG
  76. //+----------------------------------------------------------------------------
  77. //
  78. // Function: CIdleStatistics::AssertValid
  79. //
  80. // Synopsis: For debug purpose only, assert the object is valid
  81. //
  82. // Arguments: None
  83. //
  84. // Returns: Nothing
  85. //
  86. // History: Created Header 2/12/98
  87. //
  88. //+----------------------------------------------------------------------------
  89. void CIdleStatistics::AssertValid() const
  90. {
  91. MYDBGASSERT(m_dwTimeOut <10000*60*1000); // less than 10000 minutes
  92. MYDBGASSERT(m_dwThreshold <= 64*1024);
  93. ASSERT_VALID(&m_DataPointsRing);
  94. }
  95. #endif