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.

125 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. perfctr.c
  5. Abstract:
  6. This module contains the Win32 Performance Counter APIs
  7. Author:
  8. Russ Blake (russbl) 29-May-1992
  9. Revision History:
  10. --*/
  11. #include "basedll.h"
  12. BOOL
  13. WINAPI
  14. QueryPerformanceCounter(
  15. LARGE_INTEGER *lpPerformanceCount
  16. )
  17. /*++
  18. QueryPerformanceCounter - provides access to a high-resolution
  19. counter; frequency of this counter
  20. is supplied by QueryPerformanceFrequency
  21. Inputs:
  22. lpPerformanceCount - a pointer to variable which
  23. will receive the counter
  24. Outputs:
  25. lpPerformanceCount - the current value of the counter,
  26. or 0 if it is not available
  27. Returns:
  28. TRUE if the performance counter is supported by the
  29. hardware, or FALSE if the performance counter is not
  30. supported by the hardware.
  31. will receive the count
  32. --*/
  33. {
  34. LARGE_INTEGER PerfFreq;
  35. NTSTATUS Status;
  36. Status = NtQueryPerformanceCounter(lpPerformanceCount, &PerfFreq);
  37. if (!NT_SUCCESS(Status)) {
  38. // Call failed, report error
  39. SetLastError(RtlNtStatusToDosError(Status));
  40. return FALSE;
  41. }
  42. if (PerfFreq.LowPart == 0 && PerfFreq.HighPart == 0 ) {
  43. // Counter not supported
  44. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  45. return FALSE;
  46. }
  47. return TRUE;
  48. }
  49. BOOL
  50. WINAPI
  51. QueryPerformanceFrequency(
  52. LARGE_INTEGER *lpFrequency
  53. )
  54. /*++
  55. QueryPerformanceFrequency - provides the frequency of the high-
  56. resolution counter returned by
  57. QueryPerformanceCounter
  58. Inputs:
  59. lpFrequency - a pointer to variable which
  60. will receive the frequency
  61. Outputs:
  62. lpPerformanceCount - the frequency of the counter,
  63. or 0 if it is not available
  64. Returns:
  65. TRUE if the performance counter is supported by the
  66. hardware, or FALSE if the performance counter is not
  67. supported by the hardware.
  68. --*/
  69. {
  70. LARGE_INTEGER PerfCount;
  71. NTSTATUS Status;
  72. Status = NtQueryPerformanceCounter(&PerfCount, lpFrequency);
  73. if (!NT_SUCCESS(Status)) {
  74. // Call failed, report error
  75. SetLastError(RtlNtStatusToDosError(Status));
  76. return FALSE;
  77. }
  78. if (lpFrequency->LowPart == 0 && lpFrequency->HighPart == 0 ) {
  79. // Counter not supported
  80. SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
  81. return FALSE;
  82. }
  83. return TRUE;
  84. }