Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Added xhgui service. #128

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

penyaskito
Copy link
Member

@penyaskito penyaskito commented May 1, 2021

The New Solution/Problem/Issue/Bug:

xhprof+XHGui is useful for profiling applications.

How this PR Solves The Problem:

With the code provided + following the instructions, it's easy to include xhprof in your application for profiling an application.
It provides the instructions for installing xhprof, provides a container for xhprof app itself and for the required xhprof mongodb application who stores the data.
Provided instructions for Drupal 8+, WordPress, Bedrock and general php apps.

Manual Testing Instructions:

Follow the README.md (https://github.com/penyaskito/ddev-contrib/tree/xhgui-service/docker-compose-services/xhgui) with a new app, e.g. for WordPress:

wget https://wordpress.org/latest.tar.gz
tar -xvf latest.tar.gz
mv wordpress xhguitest
cd xhguitest
ddev config
vim .ddev/config.yaml
*** EDIT config as instructed in the README.md ***
cp -r ~/Projects/ddev-contrib/docker-compose-services/xhgui/xhgui-mongo .ddev
cp -r ~/Projects/ddev-contrib/docker-compose-services/xhgui/xhgui .ddev
cp ~/Projects/ddev-contrib/docker-compose-services/xhgui/docker-compose.xhgui.yml .ddev
cp ~/Projects/ddev-contrib/docker-compose-services/xhgui/examples/* .
wget https://github.com/perftools/php-profiler/archive/refs/tags/0.18.0.tar.gz
tar -xvf 0.18.0.tar.gz
vim wp-config-ddev.php
*** EDIT config as instructed in the README.md ***
ddev start
vim wp-config-ddev.php
*** EDIT config as instructed in the README.md ***
*** Open https://xhguitest.ddev.site in your browser. *** 
*** Open http://xhguitest.ddev.site:8282 in your browser. ***

Related Issue Link(s):

None known.

@LionsAd
Copy link

LionsAd commented May 28, 2021

I think this is a great addition for ddev-contrib. I followed the recipe and it works! For core ddev I think we need something more streamlined (e.g. no mongo and no other deps), but this certainly is nicely usable.

Copy link

@LionsAd LionsAd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to be merged - RTBC / RTBM :) 👍

@rfay
Copy link
Member

rfay commented Jun 16, 2021

After ddev/ddev#2983 goes in (preferably after it's in a release) we can revisit this since there's a lot added there now.

@rfay
Copy link
Member

rfay commented Aug 14, 2021

What do you think about this now @penyaskito ?

@glingener
Copy link

Thanks for all the effort.

For anyone who wants to use this with xhprof of ddev v1.17.7.

ddev ssh
vi /usr/local/bin/xhprof_prepend.php 

comment out these lines

    xhprof_enable();
    register_shutdown_function('xhprof_completion');

and save.

Otherwise the shutdown function xhprof_completion will first call xhprof_disable() and afterwards the profiler for xhgui which would get null as return.

Commenting out the above lines will disable the logging for mysite.ddev.site/xhprof. And the change will be flushed after restarting ddev (there is probably a more consistent solution, but I'm not so used to ddev yet).

@rfay
Copy link
Member

rfay commented Aug 31, 2021

In current prereleases of v1.18, the xhprof_prepend.php is actually in .ddev/xhprof/xhprof_prepend.php, so you can remove the #ddev-generated from that file and change it to your heart's delight. It will be there even after a restart. Anyway, I would love it if you'd try out latest release which is a bit different from what you've been experimenting with.

@glingener
Copy link

Thank your @rfay. I've installed v1.18 and it works great.

I followed this guide (without the need of adding webimage_extra_packages: [php7.4-xhprof] to the .ddev/config.yaml).

Than I adjusted the .ddev/xhprof/xhprof_prepend.php

  • Removed the #ddev-generated to keep my changes
  • And I put the xhprof enable logic into a function
    function xhprof_log() {
      if (extension_loaded('xhprof') && strpos($uri, '/xhprof') === false) {
        // If this is too much information, just use xhprof_enable(), which shows CPU only
        xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
        register_shutdown_function('xhprof_completion');
      }
    }

And adjusted the logic, provided by this guide, to run xhgui from

require_once __DIR__ . '/php-profiler-0.18.0/autoload.php';
require_once __DIR__ . '/xhgui.collector.php';

to

function xhgui_log() {
	if ( extension_loaded('xhprof') ) {
		require_once __DIR__ . '/php-profiler-0.18.0/autoload.php';
		require_once __DIR__ . '/xhgui.collector.php';
	}
}

// DECIDE BETWEEN ("ddev xhprof on" is required for both, otherwise nothing happens.)
// xhprof_log(); // https://my.ddev.site/xhprof/
xhgui_log(); 	 // http://my.ddev.site:8282/

in wp-config-ddev.php (using Wordpress).

That allows me to switch between both ways quickly and I can keep xhgui_log() present there as it does not run before running ddev xhprof on.

There's probably a nicer solution by adding some custom command ddev xhgui on but it's fine for me this way.

@penyaskito
Copy link
Member Author

Sorry I didn't get to this yet @rfay. I'll look at this ASAP and will take @glingener suggestions into account. Ideally we should be able to read the already generated reports with xhprof from xhgui, so no changes should be necessary. Modern xhgui only supports mongo as data storage, so might need another container for importing the files there via crontab or something like that.

@rfay
Copy link
Member

rfay commented Sep 1, 2021

@glingener you won't want to be altering wp-config-ddev.php I don't think - I imagine you'll want to find a place to make changes before or after that, as that file is #ddev-generated, right? Congrats on getting what you like running.

It's possible to add more into the default xhprof_prepend.php as well - as you see there's already an example there to add a link to the bottom of page. Probably works in WP.

@glingener
Copy link

It's #ddev-generated, but so far I saw no reason not removing that for the wp-config-ddev.php.

But I like your approach better and moved all the files for xhgui (incl. the profiler) to the .ddev dir and just load it via the xhprof_prepend.php as you said. Now my wordpress root is clean again. Thank you.

@rfay
Copy link
Member

rfay commented Oct 25, 2021

I'm fine with going forward with this if anybody has the energy to maintain it, but I think the existing ddev xhprof command without extra config probably took the wind out of it. Closing now, but happy to reopen and pursue it.

@rfay rfay closed this Oct 25, 2021
@rfay
Copy link
Member

rfay commented Mar 29, 2023

I think it might be time to resurrect this.

@rfay rfay reopened this Mar 29, 2023
@tyler36
Copy link
Collaborator

tyler36 commented Mar 29, 2023

I noticed this has been coming up alot recently.
I started an outline of the an addon but have yet to connect the service to a (Drupal) framework.

https://github.com/tyler36/ddev-xhgui

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants