Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Process information
#1
is there a way to get "mem usage" from a process?

thanks.
#2
for Win2000/XP an later

Code:
Copy      Help
type PROCESS_MEMORY_COUNTERS cb PageFaultCount PeakWorkingSetSize WorkingSetSize QuotaPeakPagedPoolUsage QuotaPagedPoolUsage QuotaPeakNonPagedPoolUsage QuotaNonPagedPoolUsage PagefileUsage PeakPagefileUsage
dll psapi #GetProcessMemoryInfo hProcess PROCESS_MEMORY_COUNTERS*ppsmemCounters cb

int idpr hpr
idpr=GetProcessId("notepad") ;;if GetProcessId does not exist, use GetWindowThreadProcessId(win("Notepad") &idpr)
hpr=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ 0 idpr); if(!hpr) ret

PROCESS_MEMORY_COUNTERS pm
if(GetProcessMemoryInfo(hpr &pm sizeof(PROCESS_MEMORY_COUNTERS)))
,out "All memory = %i K, currently in RAM = %i K" pm.PagefileUsage/1024 pm.WorkingSetSize/1024

CloseHandle(hpr)
#3
NICE!!

i made a quick function out of it for quick use.

make this code a function and call it "process_info"

Function process_info
Code:
Copy      Help
;/
function# pid

;Returns process working set size in KB.
;Returns 0 if failed.

;pid - process ID.

;EXAMPLE
;int pid=ProcessNameToId("firefox")
;out process_info(pid)


__Handle hpr=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ 0 pid); if(!hpr) ret

PROCESS_MEMORY_COUNTERS pm
if(GetProcessMemoryInfo(hpr &pm sizeof(PROCESS_MEMORY_COUNTERS)))
,ret pm.WorkingSetSize/1024



Very nice work Gintaras!
#4
I am running this on a Win7 machine now and I don't think that it works with it.
I get vastly different numbers compared to what is showing in the Win Task Manager.

Can you confirm?
An old blog on QM coding and automation.

The Macro Hook
#5
This gets working set size. It is the same as in Task Manager, 'Working Set (Memory)' column. Tested on Windows 7 32-bit.

I replaced code of your function because it did not close process handle.

Macro Macro1569
Code:
Copy      Help
out
ARRAY(int) ap
ARRAY(str) an
EnumProcessesEx &ap &an 2
int i
for i 0 ap.len
,out "%-20s %i KB" an[i] process_info(ap[i])
#6
DOH! yep, my task manager is showing Private Working Set.
thanks.
and thanks for the fix.
An old blog on QM coding and automation.

The Macro Hook
#7
Dear Gintaras,

Let me first wish a Happy and Prosperous New Year 2014.

Could you please advise me whether there exists a way similar to GetProcessMemoryInfo to get the number of GDI Objects of a running task.

Many thanks, Best regards, Simos
#8
Macro Macro2190
Code:
Copy      Help
int pid
GetWindowThreadProcessId(win("" "Notepad") &pid)
;;or
;pid=ProcessNameToId("notepad") ;;slower, use with windowless processes
if(!pid) end "failed to get process id"

__Handle hp=OpenProcess(PROCESS_QUERY_X_INFORMATION 0 pid)
if(!hp) end _s.dllerror

out GetGuiResources(hp GR_GDIOBJECTS)
for current process
Macro Macro2191
Code:
Copy      Help
out GetGuiResources(GetCurrentProcess GR_GDIOBJECTS)
#9
Thanks again, Perfect ! Kind regards.


Forum Jump:


Users browsing this thread: 1 Guest(s)