PDA

View Full Version : How to obtain kernel memory data?



jassing
11-10-2009, 12:54 PM
if you open up task manager, and select "performance" tab; in the lower right corner you see "Kernel Memory" info -- total, paged & nonpaged.

Anyone have an idea on how I can obtain that data in LUA, or dll, or action plugin?

jassing
11-20-2009, 03:26 AM
With the help of Reteset, here's the code I ended up with.

-- Requires Memory plugin.

function System.GetPerformanceInfo()
local tPerfInfo=nil;

if type(Memory)=="table" then
if File.DoesExist( _SystemFolder.."\\psapi.dll" ) then
local structPerformanceInfo = Memory.CreateStructure("long, long, long, long, long, long, long, long, long, long,long, long, long, long");
Memory.SetStructureData(structPerformanceInfo, 1, 0, Memory.Size(structPerformanceInfo));
Application.SetLastError(0);

nDLL = DLL.CallFunction(_SystemFolder.."\\psapi.dll", "GetPerformanceInfo", structPerformanceInfo ..","..Memory.Size(structPerformanceInfo), DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
if Application.GetLastError() == 0 and String.ToNumber(nDLL) > 0 then
tPerfInfo={cb=Memory.GetStructureData(structPerfor manceInfo, 1, 0, ""),CommitTotal=Memory.GetStructureData(structPerfor manceInfo, 2, 0, "")*4,CommitLimit=Memory.GetStructureData(structPerf ormanceInfo, 3, 0, "")*4,CommitPeak=Memory.GetStructureData(structPerfo rmanceInfo, 4, 0, "")*4,PhysicalTotal=Memory.GetStructureData(structPe rformanceInfo, 5, 0, "")*4,PhysicalAvailable=Memory.GetStructureData(stru ctPerformanceInfo, 6, 0, "")*4,SystemCache=Memory.GetStructureData(structPerf ormanceInfo, 7, 0, "")*4,KernelTotal=Memory.GetStructureData(structPerf ormanceInfo, 8, 0, "")*4,KernelPaged=Memory.GetStructureData(structPerf ormanceInfo, 9, 0, "")*4,KernelNonpaged=Memory.GetStructureData(structP erformanceInfo, 10, 0, "")*4,PageSize=Memory.GetStructureData(structPerform anceInfo, 11, 0, ""),HandleCount=Memory.GetStructureData(structPerfor manceInfo, 12, 0, ""), ProcessCount=Memory.GetStructureData(structPerform anceInfo, 13, 0, ""),ThreadCount=Memory.GetStructureData(structPerfor manceInfo, 14, 0, "")};
end

Memory.FreeStructure(structPerformanceInfo); -- free all allocated memory of our structure
end; -- psapi.dll exists
end; -- memory plugin loaded

return tPerfInfo
end

(note; I left it as code so you could change it rather than use a plugin compiler -- if you see a plugin created; just use the raw code..)