Memory usage of a running script. 2 methods, 2 different results
| From: | Hans Rakers | Date: | Mon, 27 May 2002 00:13:09 +0000 |
| Subject: | Memory usage of a running script. 2 methods, 2 different results | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-84494@lists.php.net to get a copy of this message | ||
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