perftools / xhgui

Web interface for XHProf profiling data can store data in MongoDB or PDO database
1.65k stars 341 forks source link

docker: Cannot import `.xhprof` files - PHP Fatal error: require(): Failed opening required xhgui/external/../vendor/autoload.php' #478

Closed maltfield closed 2 years ago

maltfield commented 2 years ago

Attempting to import an .xhprof file into the mongodb fails on fresh install with the following error

root@disp9981:/home/user/xhgui# php external/import.php -f /home/user/some.xhprof
PHP Warning:  require(/home/user/xhgui/external/../vendor/autoload.php): failed to open stream: No such file or directory in /home/user/xhgui/external/import.php on line 5
PHP Fatal error:  require(): Failed opening required '/home/user/xhgui/external/../vendor/autoload.php' (include_path='.:/usr/share/php') in /home/user/xhgui/external/import.php on line 5
root@disp9981:/home/user/xhgui# 

In fact, there is no vendor directory at all. What is it trying to require()?

root@disp9981:/home/user/xhgui# ls -lah
total 144K
drwxr-xr-x 12 user user 4.0K May 26 16:23 .
drwx------ 17 user user 4.0K May 26 18:30 ..
drwxr-xr-x  2 user user 4.0K May 26 13:49 cache
-rw-r--r--  1 user user 1.4K May 26 13:49 composer.json
-rw-r--r--  1 user user  33K May 26 13:49 composer.lock
drwxr-xr-x  2 user user 4.0K May 26 13:49 config
-rwxr-xr-x  1 user user  874 May 26 13:49 docker-build-release.sh
-rw-r--r--  1 user user  776 May 26 13:49 docker-compose.yml
-rw-r--r--  1 user user 3.5K May 26 13:49 Dockerfile
-rw-r--r--  1 user user  194 May 26 13:49 .dockerignore
drwxr-xr-x  2 user user 4.0K May 26 13:49 external
drwxr-xr-x  8 user user 4.0K May 26 18:25 .git
drwxr-xr-x  3 user user 4.0K May 26 13:49 .github
-rw-r--r--  1 user user  103 May 26 13:49 .gitignore
-rw-r--r--  1 user user 2.5K May 26 13:49 install.php
drwxr-xr-x  2 user user 4.0K May 26 13:49 mongo.init.d
-rw-r--r--  1 user user  553 May 26 13:49 nginx.conf
-rw-r--r--  1 user user  266 May 26 13:49 .php_cs
-rw-r--r--  1 user user  572 May 26 13:49 phpunit.xml
-rw-r--r--  1 user user  12K May 26 13:49 README.md
-rw-r--r--  1 user user   62 May 26 13:49 .scrutinizer.yml
drwxr-xr-x 10 user user 4.0K May 26 13:49 src
-rw-r--r--  1 user user  325 May 26 13:49 .stickler.yml
drwxr-xr-x  8 user user 4.0K May 26 13:49 templates
drwxr-xr-x  9 user user 4.0K May 26 13:49 tests
drwxr-xr-x  6 user user 4.0K May 26 13:49 webroot
root@disp9981:/home/user/xhgui# 

Problem

There is no vendor/autoload.php file present after doing the Docker install (and not even a vendor directory). This causes attempts to import .xhprof files to fail.

Moreover, /external/import.php is not available from the web server, and it's entirely unclear/undocumented as to how a user is supposed to import .xhprof files into xhgui, as pointed out in this other ticket:

Expected Solution

  1. I should be able to run php external/import.php -f /path/to/some.xhprof and it successfully imports the file into xhgui
  2. I should be able to access http://localhost:8142/external/import.php in my browser after installing via Docker
  3. It should be clearly documented how I can import a .xhprof file into XHGui after a fresh Docker install

Steps to Reproduce

This bug can be reproduced by executing the following commands on a Debian 11 system:

sudo su -
sudo apt-get install docker.io docker-compose php
git clone https://github.com/perftools/xhgui.git
cd xhgui
git reset --hard 3fb75686aeddb732833982346aaff294ecaaf1ef
docker-compose up -d

Then, copy some.xhprof file to /home/user/ and run

php external/import.php -f /home/user/some.xhprof

Context

I'm running this on an AppVM in QubesOS running Debian 11.

root@disp9981:/home/user/xhgui# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 11 (bullseye)
Release:    11
Codename:   bullseye
root@disp9981:/home/user/xhgui# 

I've checked-out this repo on branch 0.21.x

root@disp9981:/home/user/xhgui# git remote show origin
* remote origin
  Fetch URL: https://github.com/perftools/xhgui.git
  Push  URL: https://github.com/perftools/xhgui.git
  HEAD branch: 0.21.x
  Remote branches:
    0.18.x                               tracked
    0.19.x                               tracked
    0.20.x                               tracked
    0.20.x-merge-up-into-0.21.x_zOVpPi2h tracked
    0.21.x                               tracked
  Local branch configured for 'git pull':
    0.21.x merges with remote 0.21.x
  Local ref configured for 'git push':
    0.21.x pushes to 0.21.x (up to date)
root@disp9981:/home/user/xhgui#

root@disp9981:/home/user/xhgui# git rev-parse HEAD
3fb75686aeddb732833982346aaff294ecaaf1ef
root@disp9981:/home/user/xhgui# 
glensc commented 2 years ago

the cli command needs to be run inside the container:

php external/import.php -f /home/user/some.xhprof

but for that to work you need also add extra bind-type volumes to container, so the file is accessible inside the container.


the instructions there are old, pre-docker, that assumed you had local installation.

I guess the infrastructure should be re-worked to add cli script to https://github.com/perftools/php-profiler, that could use /run/import endpoint to submit the .jsonl files.

maltfield commented 2 years ago

but for that to work you need also add extra bind-type volumes to container, so the file is accessible inside the container.

Sorry, would you mind expounding on this a bit here in the ticket? For the following command to not throw errors, what exactly should I do?

php external/import.php -f /home/user/some.xhprof

I need to add some lines to a docker file? Which file? Exactly what lines do I need to add so that the container has access to the dependencies it needs to run the above script??

glensc commented 2 years ago
  1. you need to run the command inside the container, so docker-compose exec xhgui sh
  2. in the container, you need to have access to the .jsonl file saved by php-profiler, so you need to add a volume, edit docker-compose.yml and add it, or as config is already in volume, put the file to config dir, and then adjust the import command accordingly.

but really, as I said already, the import script should be probably moved to https://github.com/perftools/php-profiler project

glensc commented 2 years ago

the import cli program was added to this repo:

if something unclear or broken, open issue there. or just submit pull request.

currently on main branch only.

glensc commented 2 years ago

and documentation update (in this repo):

maltfield commented 2 years ago

@glensc first, I do really appreciate your efforts on addressing this issue, especially so fast!

Unfortunately, I think it's now even more unclear to the user how the heck to import .xhprof files into XHGui.

If a distinct tool is needed, then I think the documentation should list exact commands needed to:

  1. install the other tool
  2. import a .xhprof file into the other tool
  3. export the .jsonl file from the other tool
  4. import the .jsonl file from the other tool and import it into xhgui

If I'm still totally confused about how to do this, it's probably because the new ignorant user (me) is not able to find any clear documentation on how to do these things...

glensc commented 2 years ago

it is not possible to import .xhprof (I still don't know what does it even contain), as it lacks request information needed by xhgui.

I answered that here:

the only supported way to profile is this library:

that is probably why you can't find any documentation for custom use-cases.

you may try to use classes from perftools/php-profiler to build jsonl files from xprof files, emulating missing metadata, and submit your files yourself. you need some coding expertise to do that. the newly added cli script to run import may be of a good help.