Jump to content

Viewing xhprof data

swarm xhprof

  • Please log in to reply
2 replies to this topic

#1 Bruce Mc

Bruce Mc

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts
  • LocationSeattle Area

Posted 27 February 2014 - 09:37 PM


I'm in the process of setting up a 2014.1 OVA instance of Swarm for evaluation. After a number of hoops have been jumped through, I have the xhprof extension installed and profiling data is being collected in data/xhprof.

Since there is support for collecting this data built into Swarm, I'm going with the idea that configuring the OVA for viewing this data has been done before. If so, could instructions for this configuration be provided?


Bruce McPeek

#2 P4PetrH


    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 28 February 2014 - 12:36 AM

Hi Bruce,

below is brief description for my setup, I am using the default UI tool that comes with the xhprof. Note I am using Ubuntu, so it might be slightly different on other platforms. I also assume that you have installed xhprof (my version is 0.9.4 that should be the latest at this moment).

1. Setup virtual host to view xhprof data and graphs in your browser:
- add hostname to your hosts config file (/etc/hosts), I chose 'xhprof'
- add Apache virtual host script in enabled-sites (usually /etc/apache2/sites-enabled in Ubuntu), below is an example:

<VirtualHost *:80>
  ServerName xhprof
  DocumentRoot /usr/share/php/xhprof_html
  <Directory /usr/share/php/xhprof_html>
	AllowOverride All
	Order allow,deny
	Allow from all
  ErrorLog ${APACHE_LOG_DIR}/xhprof-error.log

Replace 'ServerName xhprof' if you chose a different host name and '/usr/share/php/xhprof_html' if your xhprof was installed into a different directory.

2. Tell xhprof where to find the output data files (Swarm will output the xhprof files under '<SWARM_ROOT>/data/xhprof').
There are several ways how to do this, the easiest one is probably to add the following line into the xhprof.ini file (in my system, its located under /etc/php5/conf.d/20-xhprof.ini):


replace <SWARM_ROOT> depending on your Swarm installation.

I was looking into the code if there are other ways to pass the output_dir, so I could for example set it in the .htaccess file. The XHProfRuns_Default class (for storing/retrieving xhprof data - they call it runs) accepts optional 'dir' parameter in the constructor. However as the default /usr/share/php/xhprof_html/index.php calls the constructor without params, you would have to create your own index.php.

3. By default, Swarm will create xhprof file only when the response takes more than 3 seconds. To start experimenting, I recommend to set it to 0, xhprof will be then generated for every request. To do it, add (or merge) following lines in your Swarm config.php:

  'xhprof' => array(
	'slow_time' => 0,

Don't forget to set it back when you are done testing otherwise the xhprof/ directory will be flooded quickly (unless you don't care).

4. I remember I had to install some package required to view the full callgraph, I believe it was 'xdot', but not 100% sure. I will come to that later.

5. Restart Apache and open some page in Swarm (you can check the <SWARM_ROOT>/data/xhprof dir, it should contain xhprof file, something similar to 'xxxxxxxxx.swarm.xhprof'), if it doesn't the chances are you did something wrong.

6. Open http://xhprof/ (replace xhprof if you chose different host). If you configured everything correct, you should see a simple html page, click on the xxxxxxxxx.swarm.xhprof link under 'Existing Runs:' and then below the 'Overall Summary' box on the next page click on [View Full Callgraph]. If you are missing the package I was talking about in section 4., you will get an error here, but you should be able to recover the required package name from the error message.

From some reason, when I installed xhprof via PECL, the public_html is missing css and javascript files (or at least its my experience). You can download them from https://github.com/facebook/xhprof if you wish.

#3 Bruce Mc

Bruce Mc

    Advanced Member

  • Members
  • PipPipPip
  • 84 posts
  • LocationSeattle Area

Posted 28 February 2014 - 08:03 PM

Thank you,

Your instructions worked well. The package that needed to be installed was indeed xdot.

For future readers, on the OVA i'm using,
  • DocumentRoot ......... /opt/php54/lib/php/xhprof_html
  • xhprof.ini ........... /opt/php54/etc/php.ini.d/xhprof.ini
  • xhprof.output_dir .... /opt/swarm/data/xhprof

Bruce McPeek

Also tagged with one or more of these keywords: swarm, xhprof

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users