adsr / phpspy

low-overhead sampling profiler for PHP 7+
MIT License
1.42k stars 66 forks source link

Memory option "-m" fails with popen_read_line: No stdout [...] get_symbol_offset: Failed #68

Closed paslandau closed 5 years ago

paslandau commented 5 years ago

Hey,

I'm trying to use the -m flag on the following test script:

<?php

$i = 0;
while (true) {
    $i++;
    file_put_contents("/tmp/foo.txt", "hello$i\n", FILE_APPEND);
    sleep(1);
}

running as a background process but I get the following error:

popen_read_line: No stdout; cmd=objdump -Tt /usr/bin/php7.3 | awk '/ alloc_globals$/{print $1; exit}'
get_symbol_offset: Failed

Full steps (running as root):

# php /var/www/current/test.php &
[1] 311
# ~/phpspy/phpspy -p 311 -m
popen_read_line: No stdout; cmd=objdump -Tt /usr/bin/php7.3 | awk '/ alloc_globals$/{print $1; exit}'
get_symbol_offset: Failed
# ps aux | grep test.php
root       311  0.0  0.6 331260 27604 pts/1    S    10:18   0:00 php /var/www/current/test.php
root       328  0.0  0.0  14512  1076 pts/1    S+   10:19   0:00 grep --color=auto test.php

Using https://github.com/phusion/baseimage-docker to test

$ docker build -t my-phpspy -<<'EOF'
FROM phusion/baseimage:latest

RUN apt-get update -yqq && apt-get install -yqq software-properties-common && \
    add-apt-repository -y ppa:ondrej/php \
;

RUN apt-get update -yqq && apt-get install -yqq \
    git \
    build-essential \
    python \
    php7.3-cli \
;

RUN cd ~ \
 && git clone --recursive https://github.com/adsr/phpspy.git \
 && cd phpspy \
 && make \
;
EOF

$ docker run -d my-phpspy
adsr commented 5 years ago

Hi @paslandau. The --memory-usage option needs to know where the alloc_globals symbol is. This symbol is not exposed via ZEND_API in php-src so it will only be there if your PHP binary was built with debug symbols. Maybe the ppa you are using has a version with debug symbols? If not you can compile PHP from source. I'll add this to the docs.

alok87 commented 1 year ago

Any other alternative than rebuilding php?

xtrime-ru commented 7 months ago

Hi!

We using phpspy with pyroscope and all works amazing. But now we want to trace memory consumption for further optimisation hints. And same issue appeared.

I installed additional debug symbols packages but it does not solved the issue.

https://github.com/oerdnj/deb.sury.org/wiki/Debugging-Symbols:

apt install php8.2-fpm-dbgsym php8.2-cli-dbgsym php8.2-common-dbgsym 

Also there is no official docker images with debug symbols: https://github.com/docker-library/php/issues/879

Maybe its worth implement another less complicated way of collecting memory stats, like cat /proc/%PID%/statm ?