BitOne / php-meminfo

PHP extension to get insight about memory usage
MIT License
1.08k stars 78 forks source link

Error with analyze dump memory #49

Closed Shkarbatov closed 6 years ago

Shkarbatov commented 6 years ago

Hi! Trying to make memory dump:

gc_collect_cycles();
meminfo_dump(fopen('/home/dmitriy/phpmem/my_dump_file.json', 'w'));`

Then run analyzer and receive an error:

$ analyzer/bin/analyzer summary my_dump_file.json

[Symfony\Component\Serializer\Exception\UnexpectedValueException]  
Control character error, possibly incorrectly encoded    
$ ls -al
-rw-rw-r--  1 dmitriy dmitriy 8093889 Ноя 21 15:30 my_dump_file.json

In memory dump I have next item:

    "0x7f31bcb13620" : {
        "type" : "array",
        "size" : "72",
        "is_root" : false
,
        "children" : {
            "1| ":"0x7f31be24dca0"
        }

    }

Why dump create this "1| ":"0x7f31be24dca0" ? This is not valid json.


Second question:

$ analyzer/bin/analyzer ref-path 0x7f254b257c20 my_dump_file100.json 

Found 2 paths
Path from 0x7f255ce562c0
0x7f254b257c20
      ^       
      |       
_entityManager
      |       
      |       
0x7f254b2d1d40
      ^       
      |       
runningCommand
      |       
      |       
0x7f255ce562c0

Path from 0x7f255ce562e0
0x7f254b257c20
      ^       
      |       
_entityManager
      |       
      |       
0x7f254b2d1d40
      ^       
      |       
runningCommand
      |       
      |       
0x7f255ce562c0
      ^       
      |       
 application  
      |       
      |       
0x7f255ce562e0

It is not, what I see here: https://github.com/BitOne/php-meminfo/blob/master/doc/hunting_down_memory_leaks.md#4-finding-references-to-the-leaked-object

How to understand with this output like you write in your example:

So the reason why our object is still in memory is because it's in an array, that is itself in another array that is in an final array. And the final array is directly linked to the variable declared in the frame and called myRootArray.

I think you need to add parameter -v in example:

$ bin/analyzer ref-path 0x7f94a1877068 /tmp/php_mem_dump.json

BitOne commented 6 years ago

Hello @Shkarbatov , I have been able to reproduce the problem.

"children" : {
            "1| ":"0x7f31be24dca0"
        }

may be invalid if the character after the | is a control character. It translates into a space in the issue, but it's certainly the reason (the pipe | is totally allowed as character though).

I have a test use case reproducing the issue and I will work on fixing it.

Thanks !

Shkarbatov commented 6 years ago

Yes, problem in controle character - it is tab character.

BitOne commented 6 years ago

Hey @Shkarbatov ,

I've committed a fix and released a 1.0.1 version.

If that's possible for you, can you check it again ?

Thank you!

Shkarbatov commented 6 years ago

Check it - fixed. Thanks!

BitOne commented 6 years ago

Thanks @Shkarbatov for your answer!