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.

123 lines
2.5 KiB

  1. /******************************************************************************
  2. O B J E C T D A T A
  3. Name: objdata.c
  4. Description:
  5. This module contains functions that access objects in performance
  6. data.
  7. Functions:
  8. FirstObject
  9. NextObject
  10. FindObject
  11. FindObjectN
  12. ******************************************************************************/
  13. #include <windows.h>
  14. #include <winperf.h>
  15. #include "perfdata.h"
  16. //*********************************************************************
  17. //
  18. // FirstObject
  19. //
  20. // Returns pointer to the first object in pData.
  21. // If pData is NULL then NULL is returned.
  22. //
  23. PPERF_OBJECT FirstObject (PPERF_DATA pData)
  24. {
  25. if (pData)
  26. return ((PPERF_OBJECT) ((PBYTE) pData + pData->HeaderLength));
  27. else
  28. return NULL;
  29. }
  30. //*********************************************************************
  31. //
  32. // NextObject
  33. //
  34. // Returns pointer to the next object following pObject.
  35. //
  36. // If pObject is the last object, bogus data maybe returned.
  37. // The caller should do the checking.
  38. //
  39. // If pObject is NULL, then NULL is returned.
  40. //
  41. PPERF_OBJECT NextObject (PPERF_OBJECT pObject)
  42. {
  43. if (pObject)
  44. return ((PPERF_OBJECT) ((PBYTE) pObject + pObject->TotalByteLength));
  45. else
  46. return NULL;
  47. }
  48. //*********************************************************************
  49. //
  50. // FindObject
  51. //
  52. // Returns pointer to object with TitleIndex. If not found, NULL
  53. // is returned.
  54. //
  55. PPERF_OBJECT FindObject (PPERF_DATA pData, DWORD TitleIndex)
  56. {
  57. PPERF_OBJECT pObject;
  58. DWORD i = 0;
  59. if (pObject = FirstObject (pData))
  60. while (i < pData->NumObjectTypes)
  61. {
  62. if (pObject->ObjectNameTitleIndex == TitleIndex)
  63. return pObject;
  64. pObject = NextObject (pObject);
  65. i++;
  66. }
  67. return NULL;
  68. }
  69. //*********************************************************************
  70. //
  71. // FindObjectN
  72. //
  73. // Find the Nth object in pData. If not found, NULL is returned.
  74. // 0 <= N < NumObjectTypes.
  75. //
  76. PPERF_OBJECT FindObjectN (PPERF_DATA pData, DWORD N)
  77. {
  78. PPERF_OBJECT pObject;
  79. DWORD i = 0;
  80. if (!pData)
  81. return NULL;
  82. else if (N >= pData->NumObjectTypes)
  83. return NULL;
  84. else
  85. {
  86. pObject = FirstObject (pData);
  87. while (i != N)
  88. {
  89. pObject = NextObject (pObject);
  90. i++;
  91. }
  92. return pObject;
  93. }
  94. }