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.

121 lines
2.2 KiB

  1. /*++
  2. Copyright (C) 1995-1999 Microsoft Corporation
  3. Module Name:
  4. compose.c
  5. Abstract:
  6. Counter composition functions
  7. --*/
  8. #include <windows.h>
  9. #include <stdlib.h>
  10. //#include <assert.h>
  11. #include <pdh.h>
  12. //#include "pdhitype.h"
  13. #include "pdhidef.h"
  14. //#include "pdhicalc.h"
  15. double
  16. WINAPI
  17. PdhAverage(
  18. IN double *CounterArray,
  19. IN ULONG nEntries
  20. )
  21. {
  22. double sum = 0;
  23. if ((CounterArray == NULL) || (nEntries == 0))
  24. return PDH_INVALID_ARGUMENT;
  25. __try {
  26. ULONG i;
  27. for (i=0; i<nEntries; i++) {
  28. if (CounterArray[i] > 0.0)
  29. sum += CounterArray[i];
  30. }
  31. }
  32. __except (EXCEPTION_EXECUTE_HANDLER) {
  33. SetLastError( GetExceptionCode() );
  34. }
  35. return (sum / (double) nEntries);
  36. }
  37. double
  38. WINAPI
  39. PdhMax(
  40. IN double *CounterArray,
  41. IN ULONG nEntries
  42. )
  43. {
  44. double max = 0;
  45. if ((CounterArray == NULL) || (nEntries == 0))
  46. return PDH_INVALID_ARGUMENT;
  47. __try {
  48. ULONG i;
  49. for (i=0; i<nEntries; i++) {
  50. if (max < CounterArray[i])
  51. max = CounterArray[i];
  52. }
  53. }
  54. __except (EXCEPTION_EXECUTE_HANDLER) {
  55. SetLastError( GetExceptionCode() );
  56. }
  57. return (max);
  58. }
  59. double
  60. WINAPI
  61. PdhMin(
  62. IN double *CounterArray,
  63. IN ULONG nEntries
  64. )
  65. {
  66. double min = 0;
  67. if ((CounterArray == NULL) || (nEntries == 0))
  68. return PDH_INVALID_ARGUMENT;
  69. __try {
  70. ULONG i;
  71. for (i=0; i<nEntries; i++) {
  72. if (min > CounterArray[i])
  73. min = CounterArray[i];
  74. }
  75. }
  76. __except (EXCEPTION_EXECUTE_HANDLER) {
  77. SetLastError( GetExceptionCode() );
  78. }
  79. return (min);
  80. }
  81. double
  82. WINAPI
  83. PdhNormalizeCpu(
  84. IN double *CounterArray,
  85. IN ULONG nEntries
  86. )
  87. {
  88. double sum = 0;
  89. if ((CounterArray == NULL) || (nEntries == 0))
  90. return PDH_INVALID_ARGUMENT;
  91. __try {
  92. ULONG i;
  93. for (i=0; i<nEntries; i++) {
  94. if (CounterArray[i] > 0.0)
  95. sum += CounterArray[i]; // need to get weight of array
  96. }
  97. }
  98. __except (EXCEPTION_EXECUTE_HANDLER) {
  99. SetLastError( GetExceptionCode() );
  100. }
  101. return (sum / (double) nEntries);
  102. }