Win32.WMPerfMonPluginMemory.Mod 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. MODULE WMPerfMonPluginMemory; (** AUTHOR "staubesv"; PURPOSE "Performance Monitor memory utilization plugin"; *)
  2. IMPORT
  3. Kernel32, Modules, WMPerfMonPlugins, Heaps;
  4. CONST
  5. ModuleName = "WMPerfMonPluginMemory";
  6. TYPE
  7. (* Heaps.GetHeapInfo is a slow operation. HeapHelper provides its results to multiple plugins *)
  8. HeapHelper = OBJECT(WMPerfMonPlugins.Helper)
  9. VAR
  10. free, total, largest : SIZE;
  11. PROCEDURE Update;
  12. BEGIN
  13. Heaps.GetHeapInfo(total, free, largest);
  14. END Update;
  15. END HeapHelper;
  16. TYPE
  17. MemoryLoad* = OBJECT(WMPerfMonPlugins.Plugin)
  18. VAR
  19. h : HeapHelper;
  20. PROCEDURE Init*(p : WMPerfMonPlugins.Parameter);
  21. VAR ds : WMPerfMonPlugins.DatasetDescriptor;
  22. BEGIN
  23. p.name := "Heap"; p.description := "Heap statistics"; p.modulename := ModuleName;
  24. p.autoMax := TRUE; p.unit := "KB"; p.minDigits := 7;
  25. p.noSuperSampling := TRUE;
  26. p.helper := heapHelper; h := heapHelper;
  27. NEW(ds, 3);
  28. ds[0].name := "Size"; INCL(ds[0].flags, WMPerfMonPlugins.Maximum);
  29. ds[1].name := "Free";
  30. ds[2].name := "LargestBlock"; INCL(ds[2].flags, WMPerfMonPlugins.Standalone);
  31. p.datasetDescriptor := ds;
  32. END Init;
  33. PROCEDURE UpdateDataset*;
  34. BEGIN
  35. dataset[0] := h.total DIV 1024;
  36. dataset[1] := h.free DIV 1024;
  37. dataset[2] := h.largest DIV 1024;
  38. END UpdateDataset;
  39. END MemoryLoad;
  40. TYPE
  41. WindowsMemoryLoad = OBJECT(WMPerfMonPlugins.Plugin)
  42. VAR
  43. status : Kernel32.MemoryStatusEx;
  44. PROCEDURE Init(p : WMPerfMonPlugins.Parameter);
  45. VAR ds : WMPerfMonPlugins.DatasetDescriptor;
  46. BEGIN
  47. p.name := "Memory"; p.description := "Windows Memory Statistics"; p.modulename := ModuleName;
  48. p.noSuperSampling := TRUE;
  49. p.autoMax := TRUE; p.unit := "KB"; p.minDigits := 7;
  50. NEW(ds, 7);
  51. ds[0].name := "Memory Load [%]";
  52. ds[1].name := "Total (Physical)";
  53. ds[2].name := "Free (Physical)";
  54. ds[3].name := "Total (Page file)";
  55. ds[4].name := "Free (Page file)";
  56. ds[5].name := "Total (Virtual)";
  57. ds[6].name := "Free (Virtual)";
  58. p.datasetDescriptor := ds;
  59. END Init;
  60. PROCEDURE UpdateDataset;
  61. BEGIN
  62. status.dwLength := 64;
  63. IF (Kernel32.GlobalMemoryStatusEx(status) = Kernel32.True) THEN
  64. dataset[0] := status.dwMemoryLoad;
  65. dataset[1] := status.ullTotalPhys DIV 1024;
  66. dataset[2] := status.ullAvailPhys DIV 1024;
  67. dataset[3] := status.ullTotalPageFile DIV 1024;
  68. dataset[4] := status.ullAvailPageFile DIV 1024;
  69. dataset[5] := status.ullTotalVirtual DIV 1024;
  70. dataset[6] := status.ullAvailVirtual DIV 1024;
  71. END;
  72. END UpdateDataset;
  73. END WindowsMemoryLoad;
  74. VAR
  75. heapHelper : HeapHelper;
  76. PROCEDURE InitPlugins;
  77. VAR
  78. par : WMPerfMonPlugins.Parameter;
  79. ml : MemoryLoad;
  80. wml : WindowsMemoryLoad;
  81. BEGIN
  82. NEW(par); NEW(ml, par);
  83. NEW(par); NEW(wml, par);
  84. END InitPlugins;
  85. PROCEDURE Install*;
  86. END Install;
  87. PROCEDURE Cleanup;
  88. BEGIN
  89. WMPerfMonPlugins.updater.RemoveByModuleName(ModuleName);
  90. END Cleanup;
  91. BEGIN
  92. NEW(heapHelper);
  93. InitPlugins;
  94. Modules.InstallTermHandler(Cleanup);
  95. END WMPerfMonPluginMemory.
  96. WMPerfMonPluginMemory.Install ~ SystemTools.Free WMPerfMonPluginMemory ~