Tideways and Xhgui using DevDesktop and Docker

THIS POST IS UNFINISHED. Use at your own risk. I needed to share with a colleague, so I’m just getting it out into the world. Your Mileage May Vary!

I’ve been working on some large Drupal 8 migrations and have been wanting to profile them for some time due to a few migrations taking far more time than I expected. Acquia DevDesktop, which I happen to be using for this site, offers xhprof in the older PHP environments, but I wanted to get something setup in PHP 7.

For PHP 7 the recommendation is to use Tideways; it’s a modern fork of xhprof. After collecting (tracing/profiling) the data with Tideways you need a way to analyze the data. I used a Docker environment to get Xhgui running. Here’s what a few xhgui screens look like. The best part is that nearly everything is clickable so you can drill down to figure out what’s slow, and why!

Awesome, right!?

Getting this all going wasn’t a simple process, so hopefully this provides some useful info for you.

DISCLAIMER: I’m manually profiling specific function calls and then pulling that data into Xhgui with a command line command; it doesn’t show up in Xhgui automatically. If I end up needing automatic Xhgui integration I’ll post an update.

Step 1: Configure Site in DevDesktop

Configure your site however you normally do, but choose 7.0.14 as the PHP version.

Step 2: Install Tideways extension for DevDesktop PHP 7

Step 3: Configure Tideways

Add to the bottom of /Applications/DevDesktop/php7_0/bin/php.ini

Step 4: Reboot apache/mysql

Stop and Start via the DevDesktop control panel.

 Step 6: Profile something!

My recommendation is to write a simple function that you can call via Drush to test the setup. Here’s an example:

After that’s in place and the caches are cleared, just execute with drush:

If things went well you should see a new file like /tmp/xhprof/mysite_2017-09-13_11-34-18.xhprof  and the should contain lots of data!

If you don’t get a file you’ll have to dig into the configuration.

If you executed the function call with drush, make sure Drush is using the same PHP binary and configuration as your site. php --info | grep -i tideways  will show if tideways is available to Drush.

If your site doesn’t know what “tideways_enable()” is you’ll have to figure out why the extension didn’t load. phpinfo() should show a bunch of tideways variables.

Step 7: Setup xhgui Docker instance

If you don’t have profile data (JSON) in an .xhprof file, please go back… you need data that you can feed to xhgui before you can play with xhgui.

Prepare the Image Code

I cloned xhgui-docker into ~/docker/images/xhgui-docker and had to make a few changes to get it to build correctly.

Here’s the diff of the changes I made:

Build the Image

Step 8: Setup Docker Container

Once that is up and running you should be able to visit 127.0.0.1:8081 in your browser. You will hopefully see the Xhgui application.

Step 9: Import the Data Into Xhgui’s Mongo DB

Method 1

Method 2

Method 3 (PREFERRED)

If you’re using Fish you can drop these scripts into your ~/.config/fish/functions directory:

xhgui_wipe.fish (wipes out all runs in the xhgui database)

xhgui_import_latest.fish (import latest file from /tmp/xhprof/)

xhgui_import.fish [filename] (import specific xhprof file)

 


Other Tips

Manually Clearing MongoDB Results

 

Tagged with: , ,
Posted in Development
One comment on “Tideways and Xhgui using DevDesktop and Docker
  1. Chris Porter says:

    This tutorial was fantastic! Thanks for publishing it!

    A few notes from my experience with this:
    In step 2:
    1) the configure command may not need the -C option. (not everyone is using i386 architecture, and not everyone has the same complier – so it’s better to let the configure command resolve this)
    2) the –with-php-config option *saved my life* I had been struggling to figure out why compiling wasn’t working right. THANKS
    3) the tideways project has renamed the extension to be tideways_xhprof, rather than just tideways. so after “make install” the file that is put in ext/ as tideways_xhprof.so

    in step 3:
    1) the php.ini file for devdesktop already refrences the path to ext, so just the name of the extension is all that’s needed, rather than the full path. (this also might confuse people who installed devdesktop to a directory other than /Applications/DevDesktop
    2) the extension name is now tideways_xhprof.so
    3) i’m not positive, but i’d guess that the configuration options are now also tideways_xhprof.xyz (this will need testing)

    Step 5) There is no step 5!?

    in step 6:
    1) the function names and flags to check for and use are now ‘tideways_xhprof_enable’

    in step 7:
    1) to “prepare the image code”. you can’t just do a straight up git clone. the project contains a git submodule, so a git clone –recursive is required. If you got burned by this, just run a “git submodule init;git submodule update” to get the code that was left out. Your docker build will fail w/o this.

    2) I had a lot of trouble getting the image to build. this had to do with a few things:
    a) GNUPG, GNUPG2 or GNUPG3 are required now in order to install the key certificate.
    b) mongo requires several prerequisites that can’t be found. this is because the repo that is added goes directly to the backport of the mongo library specifically. so none of the backported dependencies can be installed. I added: “deb http://ftp.debian.org/debian jessie-backports main” as a location and that kickstarted everything into working.
    c) the prepared code from earlier requires composer install to happen. that composer file requires mongo *on the machine that composer is running on*. so you either need exactly the same mongo installed on osx, or you need to download and run composer on the docker instance. I chose the later to ensure compatibility between systems.

    After that, the image builds just fine.

    Again, thanks for this tutorial, it was super helpful! hopefully these notes help you get it finalized!

Leave a Reply

Your email address will not be published. Required fields are marked *

*