Leaked source code of windows server 2003
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.

139 lines
2.7 KiB

  1. /*===================================================================
  2. Microsoft
  3. Microsoft Confidential.
  4. Copyright 1997 Microsoft Corporation. All Rights Reserved.
  5. Component: VPTOOL a WAMREG unit testing tool
  6. File: util.cpp
  7. Owner: leijin
  8. Description:
  9. Contains utility functions used by vptool.
  10. Including Debugging, timing, helping functions.
  11. Note:
  12. ===================================================================*/
  13. #ifndef _VPTOOL_UTIL_H_
  14. #define _VPTOOL_UTIL_H_
  15. #include <stdio.h>
  16. #include <wtypes.h>
  17. enum eCommand
  18. {
  19. eCommand_INSTALL = 1,
  20. eCommand_UNINSTALL,
  21. eCommand_UPGRADE,
  22. eCommand_CREATEINPROC,
  23. eCommand_CREATEOUTPROC,
  24. eCommand_CREATEINPOOL,
  25. eCommand_DELETE,
  26. eCommand_GETSTATUS,
  27. eCommand_UNLOAD,
  28. eCommand_DELETEREC,
  29. eCommand_RECOVER,
  30. eCommand_GETSIGNATURE,
  31. eCommand_SERIALIZE,
  32. eCommand_DESERIALIZE,
  33. eCommand_HELP,
  34. eCommand_2CREATE,
  35. eCommand_2DELETE,
  36. eCommand_2CREATEPOOL,
  37. eCommand_2DELETEPOOL,
  38. eCommand_2ENUMPOOL,
  39. eCommand_2RECYCLEPOOL,
  40. eCommand_2GETMODE,
  41. eCommand_2TestConn
  42. };
  43. struct CommandParam
  44. {
  45. eCommand eCmd;
  46. char *szCommandLineSwitch;
  47. char *szMetabasePath;
  48. bool fRequireMDPath;
  49. };
  50. typedef struct CommandParam CommandParam;
  51. BOOL ParseCommandLine(int argc, char **argv);
  52. void PrintHelp(BOOL fAdvanced = FALSE);
  53. DWORD Timer();
  54. VOID Report_Time(double ElaspedSec);
  55. extern const UINT rgComMax;
  56. extern CommandParam g_Command;
  57. //
  58. //
  59. struct VP_Options
  60. {
  61. BOOL fEnableTimer;
  62. };
  63. extern VP_Options g_Options;
  64. //-----------------------------------------------------------------------------
  65. // CStopWatch
  66. //-----------------------------------------------------------------------------
  67. // This class implements a simple stopwatch timer.
  68. class CStopWatch
  69. {
  70. public:
  71. CStopWatch()
  72. {
  73. Reset();
  74. }
  75. //~CStopWatch()
  76. //{ }
  77. void Start()
  78. {
  79. QueryPerformanceCounter( (LARGE_INTEGER *) &m_liBeg );
  80. }
  81. void Stop()
  82. {
  83. //LARGE_INTEGER liTmp;
  84. __int64 liEnd;
  85. QueryPerformanceCounter( (LARGE_INTEGER *) &liEnd );
  86. m_liTotal += liEnd - m_liBeg;
  87. }
  88. void Reset()
  89. {
  90. m_liBeg = m_liTotal = 0;
  91. }
  92. // Return time in seconds.
  93. double GetElapsedSec()
  94. {
  95. //LARGE_INTEGER liFreq;
  96. __int64 liFreq;
  97. QueryPerformanceFrequency( (LARGE_INTEGER *) &liFreq ); // Counts/sec
  98. if (liFreq == 0)
  99. {
  100. // Who knows? Hardware does not support.
  101. // Maybe millisec?
  102. // This is rare; modern PC's return liFreq.
  103. liFreq = 1000;
  104. }
  105. return (double) m_liTotal / (double) liFreq;
  106. }
  107. private:
  108. //LARGE_INTEGER m_liBeg;
  109. //LARGE_INTEGER m_liTotal;
  110. __int64 m_liBeg;
  111. __int64 m_liTotal;
  112. };
  113. #endif // _VPTOOL_UTIL_H