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

Leave a Reply

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

*