arnaud-lb / php-memory-profiler

Memory profiler for PHP. Helps finding memory leaks in PHP scripts.
MIT License
858 stars 51 forks source link

Labels are incorrect or lack units #94

Closed samlitowitz closed 7 months ago

samlitowitz commented 1 year ago

Description

The callgrind label MemorySize lacks units (it's bytes), and the BlockSize label is the call count. Having accurate labels makes it easier to analyze the result because one does not have to guess at units or view the source code to find out.

The following code:

<?php
function eat()
{
        return str_repeat('X', 3 * 1024 * 1024);
}

class Eater
{
        public static function eat()
        {
                return eat() . str_repeat('X', 5 * 1024 * 1024);
        }
}

$a = eat();
$b = Eater::eat();

memprof_dump_callgrind(STDOUT);

Resulted in this output:

version: 1
cmd: unknown
positions: line
events: MemorySize BlocksCount

fl=/todo.php
fn=str_repeat
1 3145760 1

fl=/todo.php
fn=eat
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 3145760 1

fl=/todo.php
fn=str_repeat
1 0 0

fl=/todo.php
fn=eat
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 0 0

fl=/todo.php
fn=str_repeat
1 0 0

fl=/todo.php
fn=Eater::eat
1 8388640 1
cfl=/todo.php
cfn=eat
calls=1 1
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 0 0

fl=/todo.php
fn=memprof_dump_callgrind
1 0 0

fl=/todo.php
fn=main /app/temp.php
1 0 0
cfl=/todo.php
cfn=eat
calls=1 1
1 3145760 1
cfl=/todo.php
cfn=Eater::eat
calls=1 1
1 8388640 1
cfl=/todo.php
cfn=memprof_dump_callgrind
calls=1 1
1 0 0

fl=/todo.php
fn=root
1 49883 95
cfl=/todo.php
cfn=main /app/temp.php
calls=1 1
1 11534400 2

total: 11584283 97

But I expected this output instead:

version: 1
cmd: unknown
positions: line
events: Memory_Size_(bytes) Call_Count

fl=/todo.php
fn=str_repeat
1 3145760 1

fl=/todo.php
fn=eat
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 3145760 1

fl=/todo.php
fn=str_repeat
1 0 0

fl=/todo.php
fn=eat
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 0 0

fl=/todo.php
fn=str_repeat
1 0 0

fl=/todo.php
fn=Eater::eat
1 8388640 1
cfl=/todo.php
cfn=eat
calls=1 1
1 0 0
cfl=/todo.php
cfn=str_repeat
calls=1 1
1 0 0

fl=/todo.php
fn=memprof_dump_callgrind
1 0 0

fl=/todo.php
fn=main /app/temp.php
1 0 0
cfl=/todo.php
cfn=eat
calls=1 1
1 3145760 1
cfl=/todo.php
cfn=Eater::eat
calls=1 1
1 8388640 1
cfl=/todo.php
cfn=memprof_dump_callgrind
calls=1 1
1 0 0

fl=/todo.php
fn=root
1 49883 95
cfl=/todo.php
cfn=main /app/temp.php
calls=1 1
1 11534400 2

total: 11584283 97

php-memprof Version

php-memprof 3.0.1

PHP Version

PHP 8.0.1

Operating System

Ubuntu 20.04

mrthebob commented 7 months ago

To add to the above - the Location is showing up as "todo.php" (fl=/todo.php).

arnaud-lb commented 7 months ago

Closing this issue has it's fixed by https://github.com/arnaud-lb/php-memory-profiler/pull/95.

@mrthebob indeed :) I would accept contributions around exposing the right location