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.

119 lines
2.8 KiB

  1. /******************************************************************************
  2. C O U N T E R D A T A
  3. Name: cntrdata.c
  4. Description:
  5. This module contains functions that access counters of an instance
  6. of object in performance data.
  7. Functions:
  8. FirstCounter
  9. NextCounter
  10. FindCounter
  11. CounterData
  12. ******************************************************************************/
  13. #include <windows.h>
  14. #include <winperf.h>
  15. #include "perfdata.h"
  16. //*********************************************************************
  17. //
  18. // FirstCounter
  19. //
  20. // Find the first counter in pObject.
  21. //
  22. // Returns a pointer to the first counter. If pObject is NULL
  23. // then NULL is returned.
  24. //
  25. PPERF_COUNTER FirstCounter (PPERF_OBJECT pObject)
  26. {
  27. if (pObject)
  28. return (PPERF_COUNTER)((PCHAR) pObject + pObject->HeaderLength);
  29. else
  30. return NULL;
  31. }
  32. //*********************************************************************
  33. //
  34. // NextCounter
  35. //
  36. // Find the next counter of pCounter.
  37. //
  38. // If pCounter is the last counter of an object type, bogus data
  39. // maybe returned. The caller should do the checking.
  40. //
  41. // Returns a pointer to a counter. If pCounter is NULL then
  42. // NULL is returned.
  43. //
  44. PPERF_COUNTER NextCounter (PPERF_COUNTER pCounter)
  45. {
  46. if (pCounter)
  47. return (PPERF_COUNTER)((PCHAR) pCounter + pCounter->ByteLength);
  48. else
  49. return NULL;
  50. }
  51. //*********************************************************************
  52. //
  53. // FindCounter
  54. //
  55. // Find a counter specified by TitleIndex.
  56. //
  57. // Returns a pointer to the counter. If counter is not found
  58. // then NULL is returned.
  59. //
  60. PPERF_COUNTER FindCounter (PPERF_OBJECT pObject, DWORD TitleIndex)
  61. {
  62. PPERF_COUNTER pCounter;
  63. DWORD i = 0;
  64. if (pCounter = FirstCounter (pObject))
  65. while (i < pObject->NumCounters)
  66. {
  67. if (pCounter->CounterNameTitleIndex == TitleIndex)
  68. return pCounter;
  69. pCounter = NextCounter (pCounter);
  70. i++;
  71. }
  72. return NULL;
  73. }
  74. //*********************************************************************
  75. //
  76. // CounterData
  77. //
  78. // Returns counter data for an object instance. If pInst or pCount
  79. // is NULL then NULL is returne.
  80. //
  81. PVOID CounterData (PPERF_INSTANCE pInst, PPERF_COUNTER pCount)
  82. {
  83. PPERF_COUNTER_BLOCK pCounterBlock;
  84. if (pCount && pInst)
  85. {
  86. pCounterBlock = (PPERF_COUNTER_BLOCK)((PCHAR)pInst + pInst->ByteLength);
  87. return (PVOID)((PCHAR)pCounterBlock + pCount->CounterOffset);
  88. }
  89. else
  90. return NULL;
  91. }