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.

146 lines
3.3 KiB

  1. /******************************************************************************
  2. I N S T A N C E D A T A
  3. Name: instdata.c
  4. Description:
  5. This module contains functions that access instances of an object
  6. type in performance data.
  7. Functions:
  8. FirstInstance
  9. NextInstance
  10. FindInstanceN
  11. FindInstanceParent
  12. InstanceName
  13. ******************************************************************************/
  14. #include <windows.h>
  15. #include <winperf.h>
  16. #include "perfdata.h"
  17. //*********************************************************************
  18. //
  19. // FirstInstance
  20. //
  21. // Returns pointer to the first instance of pObject type.
  22. // If pObject is NULL then NULL is returned.
  23. //
  24. PPERF_INSTANCE FirstInstance (PPERF_OBJECT pObject)
  25. {
  26. if (pObject)
  27. return (PPERF_INSTANCE)((PCHAR) pObject + pObject->DefinitionLength);
  28. else
  29. return NULL;
  30. }
  31. //*********************************************************************
  32. //
  33. // NextInstance
  34. //
  35. // Returns pointer to the next instance following pInst.
  36. //
  37. // If pInst is the last instance, bogus data maybe returned.
  38. // The caller should do the checking.
  39. //
  40. // If pInst is NULL, then NULL is returned.
  41. //
  42. PPERF_INSTANCE NextInstance (PPERF_INSTANCE pInst)
  43. {
  44. PERF_COUNTER_BLOCK *pCounterBlock;
  45. if (pInst)
  46. {
  47. pCounterBlock = (PERF_COUNTER_BLOCK *)((PCHAR) pInst + pInst->ByteLength);
  48. return (PPERF_INSTANCE)((PCHAR) pCounterBlock + pCounterBlock->ByteLength);
  49. }
  50. else
  51. return NULL;
  52. }
  53. //*********************************************************************
  54. //
  55. // FindInstanceN
  56. //
  57. // Returns the Nth instance of pObject type. If not found, NULL is
  58. // returned. 0 <= N <= NumInstances.
  59. //
  60. PPERF_INSTANCE FindInstanceN (PPERF_OBJECT pObject, DWORD N)
  61. {
  62. PPERF_INSTANCE pInst;
  63. DWORD i = 0;
  64. if (!pObject)
  65. return NULL;
  66. else if (N >= (DWORD)(pObject->NumInstances))
  67. return NULL;
  68. else
  69. {
  70. pInst = FirstInstance (pObject);
  71. while (i != N)
  72. {
  73. pInst = NextInstance (pInst);
  74. i++;
  75. }
  76. return pInst;
  77. }
  78. }
  79. //*********************************************************************
  80. //
  81. // FindInstanceParent
  82. //
  83. // Returns the pointer to an instance that is the parent of pInst.
  84. //
  85. // If pInst is NULL or the parent object is not found then NULL is
  86. // returned.
  87. //
  88. PPERF_INSTANCE FindInstanceParent (PPERF_INSTANCE pInst, PPERF_DATA pData)
  89. {
  90. PPERF_OBJECT pObject;
  91. if (!pInst)
  92. return NULL;
  93. else if (!(pObject = FindObject (pData, pInst->ParentObjectTitleIndex)))
  94. return NULL;
  95. else
  96. return FindInstanceN (pObject, pInst->ParentObjectInstance);
  97. }
  98. //*********************************************************************
  99. //
  100. // InstanceName
  101. //
  102. // Returns the name of the pInst.
  103. //
  104. // If pInst is NULL then NULL is returned.
  105. //
  106. LPTSTR InstanceName (PPERF_INSTANCE pInst)
  107. {
  108. if (pInst)
  109. return (LPTSTR) ((PCHAR) pInst + pInst->NameOffset);
  110. else
  111. return NULL;
  112. }