Hello all,
I've been working on a small extension that can tell me the memory usage of
a script in run-time. I've discovered two methods of doing so (when PHP is
compiled with debugging and memory limit). One is by reading the
AG(allocated_memory) and/or AG(allocated_memory_peak) global var, the other
is a construction like this (partially taken from the pdf extension as i
recall):
int allocated_memory = 0;
int allocated_pmemory = 0;
int allocated_memory_total = 0;
zend_mem_header *zmh, *zpmh;
zmh = AG(head);
while(zmh != NULL) {
allocated_memory += zmh->size;
zmh = zmh->pNext;
}
zpmh = AG(phead);
while(zpmh != NULL) {
allocated_pmemory += zpmh->size;
zpmh = zpmh->pNext;
}
allocated_memory_total = allocated_memory + allocated_pmemory;
Strange thing is, i get different results with these two methods. Running a
test script that outputs results of both methods gives me the following:
1st method: Current memory usage: 545331 Peak memory usage: 545331
2nd method: Memory: regular(68423) persistent(0) total(68423)
Now i wonder which method is right, and where the difference in results
comes from. Or am i doing this all wrong? Can someone please shed some
light on this?
System is Linux-2.4.18, Apache_1.3.24, php-4.2.1, php built as an Apache
module with debugging and memory limit.
Thanks in advance.
With kind regards,
Hans Rakers
Parse BV, the Netherlands
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php