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.

242 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. stats.hxx
  5. Abstract:
  6. Declares a class consisting of server statistics information.
  7. ( Multiple servers can make use of the same statistics
  8. information by creating distinct server statistics object)
  9. Author:
  10. Murali R. Krishnan ( MuraliK ) 04-Nov-1994
  11. Project:
  12. Web Server DLL
  13. Revision History:
  14. Sophia Chung ( SophiaC ) 20-Nov-1996
  15. --*/
  16. # ifndef _STATS_HXX_
  17. # define _STATS_HXX_
  18. /************************************************************
  19. * Include Headers
  20. ************************************************************/
  21. # include "ftpd.h" // for definition of FTP_STATISTICS_0
  22. # include "iperfctr.hxx" // standard macro defs for counters
  23. /************************************************************
  24. * Type Definitions
  25. ************************************************************/
  26. # define IPFTP_STATS_INCR( ctrName) \
  27. void Incr ## ctrName(void) \
  28. { \
  29. IP_INCREMENT_COUNTER( m_FTPStats.ctrName); \
  30. }
  31. # define IPFTP_STATS_DECR( ctrName) \
  32. void Decr ## ctrName(void) \
  33. { \
  34. IP_DECREMENT_COUNTER( m_FTPStats.ctrName); \
  35. }
  36. # define IPFTP_STATS_QUERY( ctrName) \
  37. LONG Query ## ctrName(void) \
  38. { \
  39. return (IP_COUNTER_VALUE( m_FTPStats.ctrName)); \
  40. }
  41. //
  42. // A counter inside the statistics block should use the following three
  43. // macros for defining "query", "incr" and "decr" methods inside
  44. // the statistics object
  45. //
  46. # define IPFTP_STATS_COUNTER( ctrName) \
  47. IPFTP_STATS_INCR( ctrName); \
  48. IPFTP_STATS_DECR( ctrName); \
  49. IPFTP_STATS_QUERY( ctrName); \
  50. class FTP_SERVER_STATISTICS {
  51. private:
  52. FTP_STATISTICS_0 m_FTPStats;
  53. CRITICAL_SECTION m_csStatsLock; // to synchronize access among threads
  54. IPFTP_STATS_INCR( CurrentAnonymousUsers);
  55. IPFTP_STATS_INCR( CurrentNonAnonymousUsers);
  56. void IncrCurrentConns( void)
  57. { IP_INCREMENT_COUNTER( m_FTPStats.CurrentConnections); }
  58. public:
  59. VOID LockStatistics( VOID) { EnterCriticalSection( &m_csStatsLock); }
  60. VOID UnlockStatistics( VOID) { LeaveCriticalSection( &m_csStatsLock); }
  61. FTP_SERVER_STATISTICS( VOID);
  62. ~FTP_SERVER_STATISTICS( VOID)
  63. { DeleteCriticalSection( &m_csStatsLock); };
  64. VOID ClearStatistics( VOID);
  65. LPFTP_STATISTICS_0 QueryStatsObj( VOID)
  66. { return &m_FTPStats; }
  67. //
  68. // copies statistics for RPC querying.
  69. //
  70. DWORD CopyToStatsBuffer( LPFTP_STATISTICS_0 lpStat );
  71. void CheckAndSetMaxConnections( void );
  72. void IncrCurrentConnections( void);
  73. IPFTP_STATS_QUERY( CurrentConnections);
  74. IPFTP_STATS_DECR( CurrentConnections);
  75. IPFTP_STATS_COUNTER( LogonAttempts);
  76. IPFTP_STATS_COUNTER( ConnectionAttempts);
  77. IPFTP_STATS_COUNTER( TotalFilesSent );
  78. IPFTP_STATS_COUNTER( TotalFilesReceived );
  79. // Anonymous Users
  80. void IncrAnonymousUsers( void);
  81. IPFTP_STATS_DECR( CurrentAnonymousUsers);
  82. IPFTP_STATS_COUNTER( TotalAnonymousUsers);
  83. // Non Anonymous Users
  84. void IncrNonAnonymousUsers( void);
  85. IPFTP_STATS_DECR( CurrentNonAnonymousUsers);
  86. IPFTP_STATS_COUNTER( TotalNonAnonymousUsers);
  87. // Large integer updates
  88. void UpdateTotalBytesSent( LONGLONG llBytes );
  89. void UpdateTotalBytesReceived( LONGLONG llBytes );
  90. // gets currenttime and stores it inside stats structure
  91. void UpdateStartTime();
  92. void UpdateStopTime();
  93. }; // FTP_SERVER_STATISTICS
  94. typedef FTP_SERVER_STATISTICS FAR * LPFTP_SERVER_STATISTICS;
  95. /************************************************************
  96. * Inline Methods
  97. ************************************************************/
  98. inline void FTP_SERVER_STATISTICS::CheckAndSetMaxConnections(void)
  99. {
  100. # ifdef IP_ENABLE_COUNTERS
  101. if ( m_FTPStats.CurrentConnections > m_FTPStats.MaxConnections ) {
  102. LockStatistics();
  103. if ( m_FTPStats.CurrentConnections > m_FTPStats.MaxConnections ) {
  104. m_FTPStats.MaxConnections = m_FTPStats.CurrentConnections;
  105. }
  106. UnlockStatistics();
  107. }
  108. # endif
  109. }
  110. inline void FTP_SERVER_STATISTICS::IncrCurrentConnections(void)
  111. {
  112. # ifdef IP_ENABLE_COUNTERS
  113. IncrCurrentConns();
  114. CheckAndSetMaxConnections();
  115. return;
  116. # endif
  117. } // FTP_SERVER_STATISTICS::IncrCurrentConnections()
  118. inline void FTP_SERVER_STATISTICS::IncrAnonymousUsers( void)
  119. {
  120. # ifdef IP_ENABLE_COUNTERS
  121. IncrTotalAnonymousUsers();
  122. IncrCurrentAnonymousUsers();
  123. if ( m_FTPStats.CurrentAnonymousUsers > m_FTPStats.MaxAnonymousUsers )
  124. {
  125. LockStatistics();
  126. if ( m_FTPStats.CurrentAnonymousUsers > m_FTPStats.MaxAnonymousUsers )
  127. {
  128. m_FTPStats.MaxAnonymousUsers = m_FTPStats.CurrentAnonymousUsers;
  129. }
  130. UnlockStatistics();
  131. }
  132. return;
  133. # endif
  134. } // FTP_SERVER_STATISTICS::IncrAnonymousUsers()
  135. inline void FTP_SERVER_STATISTICS::IncrNonAnonymousUsers( void)
  136. {
  137. # ifdef IP_ENABLE_COUNTERS
  138. IncrTotalNonAnonymousUsers();
  139. IncrCurrentNonAnonymousUsers();
  140. if ( m_FTPStats.CurrentNonAnonymousUsers > m_FTPStats.MaxNonAnonymousUsers )
  141. {
  142. LockStatistics();
  143. if ( m_FTPStats.CurrentNonAnonymousUsers >
  144. m_FTPStats.MaxNonAnonymousUsers )
  145. {
  146. m_FTPStats.MaxNonAnonymousUsers =
  147. m_FTPStats.CurrentNonAnonymousUsers;
  148. }
  149. UnlockStatistics();
  150. }
  151. return;
  152. # endif
  153. } // FTP_SERVER_STATISTICS::IncrNonAnonymousUsers()
  154. inline void FTP_SERVER_STATISTICS::UpdateTotalBytesSent( LONGLONG llBytes )
  155. {
  156. # ifdef IP_ENABLE_COUNTERS
  157. LockStatistics();
  158. m_FTPStats.TotalBytesSent.QuadPart += llBytes;
  159. UnlockStatistics();
  160. # endif
  161. }
  162. inline void FTP_SERVER_STATISTICS::UpdateTotalBytesReceived( LONGLONG llBytes )
  163. {
  164. # ifdef IP_ENABLE_COUNTERS
  165. LockStatistics();
  166. m_FTPStats.TotalBytesReceived.QuadPart += llBytes;
  167. UnlockStatistics();
  168. # endif
  169. }
  170. # endif // _STATS_HXX_
  171. /************************ End of File ***********************/