multithreading - Can I measure actual memory usage of a thread? -
if yes, apreciate example in delphi.
i tried using tmemorymanagerstate , getprocessmemoryinfo
it looks able track memory scalemm (https://code.google.com/p/scalemm/) allocates memory thread. out of box doesn't have need there places can add it.
if @ code, can either walk memory lists when need amount of memory allocated or hook tthreadmemmanager.getmem, tthreadmemmanager.freemem , tthreadmemmanager.freememfromotherthread calls. code in scalemm2.pas file. should pretty easy add memcount tthreadmemmanager there 1 per thread. other alternative @ code in tmediumthreadmanager.releaseallfreemem see how walks list. similar , list of allocated ram @ point in time.
be bit careful of things block sizes , fragmentation mean misleading results.
here of changes scalemm2 return memory usage each thread:
i added variable called totalallocated tthreadmemmanager:
fsmallmemmanager : tsmallmemthreadmanager; fmediummemmanager: tmediumthreadmanager; flargememmanager : tlargememthreadmanager; ftotalallocated: int64; protected i added following 2 lines bottom of freemem:
{$ifdef scalemm_debug} checkmem(nil); {$endif} ftotalallocated := ftotalallocated + pm.size; end; and getmem:
{$ifdef scalemm_debug} checkmem(nil); {$endif} ftotalallocated := ftotalallocated + asize; end; i created global list called fthreadmanagerlist:
fthreadmanagerlist: tlist<pthreadmemmanager> and @ start of threads wanted check added following code:
var threadmanager: pthreadmemmanager; begin threadmanager := getthreadmemmanager; synchronize( procedure begin fthreadmanagerlist.add(threadmanager); end); after that, getting memory threads simple this:
for := 0 fthreadmanagerlist.count - 1 begin listbox1.items.add(inttostr(fthreadmanagerlist[i].fthreadid)+' : '+inttostr(fthreadmanagerlist[i].ftotalallocated)); end; i didn't cross thread allocations, need bit of research , see how work. didn't race conditions don't think problem either unless 1 of threads exits. should give start with.
Comments
Post a Comment