EzDevInfo.com

xhprof

XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface. PECL :: Package :: xhprof

Profiling Code on Production

I'm toying around with the idea of implementing something that profiles code on the production server and wanted some best-practice advice. Obviously it's a bad idea to profile ALL requests because of the added overhead so I was looking into some techniques that will randomly invoke the profiler per request. Something like 1 profile per every 10,000 requests.

I know there is a way to achieve such a task with Facebook's XHProf Profiler but was hoping for a similar solution using xdebug.

So my questions are (assuming xdebug is the profiler):

  1. Is this kind of feature even advisable? I'd like to get some real world data from the production environment but not if it means destroying the user experience due to overhead.
  2. Does installing xdebug on production open the server up to attackers/exploiters in any way (assuming the debugger is not enabled)? Is there a boiler-plate config for this type of setup?
  3. What's the best way to trigger the profiler for an appropriate sample size?

Any other insight into the matter would be much appreciated.


Source: (StackOverflow)

xhprof doesn't work with php 5.5

I want to profile an app using xhprof at server with Ubuntu 13.10 and PHP 5.5 installed.

When I call xhprof_enable() it shows Segmentation fault

I've tried to install in different ways:

I'm compiling it using:

wget https://github.com/facebook/xhprof/archive/master.zip
unzip master.zip
cd xhprof-master/extension/
phpize
./configure
make
sudo make install

Anyway I get the same error.


Source: (StackOverflow)

Advertisements

Activate Xhprof only in slow pages

Is it possible to activate xhprof only after a -tot- of time after a page/url is called?

Normally I have pages that respond under 1 second. Sometimes they responde in 10 seconds (no, it's not the session on file). I want to activate xhprof after 1 second from the beginning of the request. (It's ok to lose first second of profiling by now)

If it was javascript, we have the setTimeout, but PHP is not threaded.

Any Idea?


Source: (StackOverflow)

Installing XHProf on Ubuntu Server

I have tried the following tutorials, as well as others:

http://akyl.net/how-install-xhprof-profiler-ubuntu

http://erichogue.ca/2011/03/linux/profiling-a-php-application/

I am continually getting the following error message(s):

running: make
/bin/bash /tmp/pear/install/pear-build-fieldnation1Iqjyy/xhprof-0.9.2/libtool --mode=compile cc  -I. -I/tmp/pear/install/xhprof/extension -DPHP_ATOM_INC -I/tmp/pear/install/pear-build-fieldnation1Iqjyy/xhprof-0.9.2/include -I/tmp/pear/install/pear-build-fieldnation1Iqjyy/xhprof-0.9.2/main -I/tmp/pear/install/xhprof/extension -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/install/xhprof/extension/xhprof.c -o xhprof.lo
libtool: compile:  cc -I. -I/tmp/pear/install/xhprof/extension -DPHP_ATOM_INC -I/tmp/pear/install/pear-build-fieldnation1Iqjyy/xhprof-0.9.2/include -I/tmp/pear/install/pear-build-fieldnation1Iqjyy/xhprof-0.9.2/main -I/tmp/pear/install/xhprof/extension -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/install/xhprof/extension/xhprof.c  -fPIC -DPIC -o .libs/xhprof.o
In file included from /usr/include/php5/main/php.h:33:0,
                 from /tmp/pear/install/xhprof/extension/xhprof.c:27:
/usr/include/php5/main/php_config.h:2396:0: warning: "_GNU_SOURCE" redefined [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:24:0: note: this is the location of the previous definition
/tmp/pear/install/xhprof/extension/xhprof.c:236:1: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/install/xhprof/extension/xhprof.c:240:28: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/install/xhprof/extension/xhprof.c: In function 'hp_get_function_name':
/tmp/pear/install/xhprof/extension/xhprof.c:898:10: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:909:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:911:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:930:34: error: 'znode_op' has no member named 'u'
/tmp/pear/install/xhprof/extension/xhprof.c:963:9: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'
/tmp/pear/install/xhprof/extension/xhprof.c: In function 'hp_execute_internal':
/tmp/pear/install/xhprof/extension/xhprof.c:1650:24: error: 'znode_op' has no member named 'u'
/tmp/pear/install/xhprof/extension/xhprof.c:1651:59: error: 'struct <anonymous>' has no member named 'return_reference'
/tmp/pear/install/xhprof/extension/xhprof.c:1652:25: error: 'znode_op' has no member named 'u'
/tmp/pear/install/xhprof/extension/xhprof.c: In function 'hp_compile_file':
/tmp/pear/install/xhprof/extension/xhprof.c:1683:3: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/install/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'
make: *** [xhprof.lo] Error 1
ERROR: `make' failed

Basically, 'make' is not able to run. How do I get past this?


Source: (StackOverflow)

how to configure XHProf for drupal 6 on windows?

With the help of Lorenzo Alberton tutorial, i get XHProf installed for drupal 6 on linux server. Now i need to get it installed on windows but i found that XHProf cant be installed on windows. Additionally, at drupal.org XHProf, is available for drupal 7 onwards. If anyone has installed XHProf for drupal 6 on windows then please share.


Source: (StackOverflow)

PHP extension (XHProf) installation problems with PHP 5.5.3

Recently I have upgraded my PHP on Ubuntu 10.04 to the lastest 5.5.3 version, and XHProf profiler stops working.

I have compliled last version of xhprof PHP extension (either from official pecl site or from facebook's github repo), and receive the following message when running php --version:

PHP Warning:  PHP Startup: xhprof: Unable to initialize module
Module compiled with build ID=API20121212,NTS,debug
PHP    compiled with build ID=API20121212,NTS
These options need to match

So, how to resolve this mismatch?

I have tried --disable-debug or --without-debug configure options configuring XHProf, but configure does not understand them.

It is also interesting that phpinfo shows the following values:

Zend Extension Build     - API220121212,NTS,debug 
PHP Extension Build      - API20121212,NTS,debug 
Debug Build              - yes 

That is my PHP configure command:

./configure --enable-opcache --prefix=/opt/php --with-apxs2=/usr/bin/apxs2 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pgsql=/usr --with-tidy=/usr --with-curl=/usr/bin --with-openssl --with-zlib-dir=/usr --with-xpm-dir=/usr --with-pdo-pgsql=/usr --with-pdo-mysql=mysqlnd --with-xsl=/usr --with-ldap --with-xmlrpc --with-iconv-dir=/usr --with-snmp=/usr --enable-exif --enable-calendar --with-bz2=/usr --with-mcrypt=/usr --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --enable-mbstring --enable-zip --with-pear --with-libdir=lib --with-config-file-path=/opt --enable-fpm --with-fpm-user=fpm --with-fpm-group=fpm --enable-debug


Source: (StackOverflow)

Tracking memory leaks in a large codebase

I have a relatively large PHP-codebase (thousands of lines) for an application built with CodeIgniter. To be able to trace preformance issues and to be able to generate statistics and such, the developement-servers run Xhprof. This works fine, provided that the script actually comes to the logging part.

However, I've now come at a situation where the script just times out. On the developement-servers, it just gives a timeout ("Server not found") error, and sometimes even crashes the Apache process. No Xhprof file is generated, the CodeIgniter logging system generates nothing. Error reporting IS enabeled.

On a live enviroment (well, mirror of the live-server), the application actually generates an error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 261900 bytes) in /home/www/application/system/database/drivers/mysql/mysql_driver.php on line 493

This, and having a clue on how to reproduce the error, gives me somewhat of a hunch where to start haunting for a solution. But it's a time consuming job to do.

I'm looking for a way to be able to trace WHERE the actual "memory leak" is happening. Instead of manually debugging line after line. Any suggestions are greatly appreciated.

UPDATE : THE LOW MEMORY OF THE SERVER IS NOT THE PROBLEM. On a developement-server with more memory, the same problem occurs. The problem was an infinite loop, allocating more memory then my server could handle. The question remains: how can these errors be tracked down quickly?


Source: (StackOverflow)

xhprof on WampServer 2.2

I am trying to get XHProf working on my WampServer.

I have downloaded the dll from: http://dev.freshsite.pl/php-extensions/xhprof/file/details/xhprof-0103-for-php-53-vc9.html and renamed to xhprof.dll in C:\wamp\bin\php\php5.3.9\ext (Which is the dir listed for extensions in phpinfo())

Php.ini path from phpinfo(): C:\wamp\bin\apache\Apache2.2.21\bin\php.ini

Extensions listed in that file:

 extension=php_curl.dll
 extension=xhprof.dll
 ;extension=php_dba.dll
 extension=php_mbstring.dll
 ;extension=php_exif.dll
 ;extension=php_fileinfo.dll
 extension=php_gd2.dll
 ;extension=php_gettext.dll
 ;extension=php_gmp.dll
 ;extension=php_intl.dll
 ;extension=php_imap.dll
 ;extension=php_interbase.dll
 ;extension=php_ldap.dll
 ;extension=php_ming.dll
 ;extension=php_mssql.dll
 extension=php_mysql.dll
 extension=php_mysqli.dll
 ;extension=php_oci8.dll
 ;extension=php_oci8_11g.dll 
 ;extension=php_openssl.dll
 ;extension=php_pdo_firebird.dll
 ;extension=php_pdo_mssql.dll
 extension=php_pdo_mysql.dll
 ;extension=php_pdo_oci.dll
 ;extension=php_pdo_odbc.dll
 ;extension=php_pdo_pgsql.dll
 extension=php_pdo_sqlite.dll
 ;extension=php_pgsql.dll
 ;extension=php_phar.dll
 ;extension=php_pspell.dll
 ;extension=php_shmop.dll
 ;extension=php_snmp.dll
 ;extension=php_soap.dll
 ;extension=php_sockets.dll
 ;extension=php_sqlite.dll
 ;extension=php_sqlite3.dll
 ;extension=php_sybase_ct.dll
 ;extension=php_tidy.dll
 ;extension=php_xmlrpc.dll
 ;extension=php_xsl.dll
 ;extension=php_zip.dll

But when I restart WampServer and the services associated with it, no XHProf information appears in phpinfo()

I am looking for a way to fix this, or a further way to investigate why this extension isnt loading

Thanks


Source: (StackOverflow)

Documentation of xhprof php profiler needed

The last days I was trying to install and run the xhprof. I finally made it and I think that it brings up very interesting information. I also installed graphviz and I can generate nice graphs, but I would like to find a documentation explaining what the colors in the graphs mean? What does exactly mean each column of the profiler report and how is it calculated.

I was trying to find something the whole day, but unfortunately the only information that I found were usage documentation.

Does any of you have such documentation or know a link? This link seems to be broken...


Source: (StackOverflow)

Error when using XHProf and XHGui

I have installed and configured XHGui as per the instructions here:

http://www.sitepoint.com/the-need-for-speed-profiling-with-xhprof-and-xhgui/

However, when I try to profile a page I see an error inserting into the details table (have truncated this as there is a large string of binary/compressed data):

Failed to insert: INSERT INTO `details` (`id`, `url`, `c_url`, `timestamp`, `server name`, `perfdata`, `type`, `cookie`, `post`, `get`, `pmu`, `wt`, `cpu`, `server_id`, `aggregateCalls_include`) VALUES('5278f06a19b9d', '/whats-on/?', '/whats-on/?', FROM_UNIXTIME('1383657576'), 'local.site2', 'x^���r$Iv%\n�K?����v����/?���������-��-�����~��j�\\/�g��>��X����O���~���o��mv���������������r9�p~�=��_��>�N_���jI�/�Wt�bqX�������Sy��S��K�u��:?g��K�6��p�����ӇOw�_>ষ�˄;.|�%��X���;n�>�����������-A\0ܞ/��\n\Z����������;C��om?\r;|a %5\0^�p��+z��A���rk��×�a��L\'OFю@X8�\"��7�\r��ah=���J�\'\n��Q���?�0�?��b\ZN�����rzz�����ߝ�O�Al=7�

I believe zlib compression is being used and that my PHP install was compiled with zlib support:

'./configure' '--prefix=/usr/local/php5' '--with-apxs2=/usr/sbin/apxs' '--with-config-file-scan-dir=/usr/local/php5/php.d' '--with-openssl=/usr' '--with-zlib=/usr' '--with-zlib-dir=/usr' '--with-gd' '--with-ldap' '--with-xmlrpc' '--enable-exif' '--enable-soap' '--enable-sqlite-utf8' '--enable-wddx' '--enable-ftp' '--enable-sockets' '--with-bz2=/usr' '--enable-zip' '--enable-shmop' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-mbstring' '--enable-bcmath' '--enable-calendar' '--with-iodbc' '--with-mhash' '--enable-fpm' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-pcntl' '--enable-dtrace' '--with-icu-dir=/usr/local/php5' '--with-mssql=shared,/usr/local/php5' '--with-pdo-dblib=shared,/usr/local/php5' '--with-libxml-dir=shared,/usr/local/php5' '--with-xsl=shared,/usr/local/php5' '--with-imap=../imap-2007f' '--with-kerberos=/usr' '--with-imap-ssl=/usr' '--with-gettext=/usr/local/php5' '--with-curl=shared,/usr/local/php5' '--with-png-dir=/usr/local/php5' '--with-jpeg-dir=/usr/local/php5' '--enable-gd-native-ttf' '--with-freetype-dir=/usr/local/php5' '--with-pgsql=shared,/usr/local/php5' '--with-pdo-pgsql=shared,/usr/local/php5' '--with-mcrypt=shared,/usr/local/php5' '--with-tidy=/usr/local/php5' '--with-gmp=shared,/usr/local/php5' '--with-readline=shared,/usr/local/php5'

Anyone seen this before or know what is going on? Its running on localhost (Mountain Lion with Liip OSX PHP - PHP 5.4

UPDATE

I increased the server_id field length and ran the profile again. Now getting:

Incorrect integer value: '' for column 'pmu' at row 1 as a result of this query:

INSERT INTO `details` (`id`, `url`, `c_url`, `timestamp`, `server name`, `perfdata`, `type`, `cookie`, `post`, `get`, `pmu`, `wt`, `cpu`, `server_id`, `aggregateCalls_include`) VALUES('5279085839571', '/whats-on/?', '/whats-on/?', FROM_UNIXTIME('1383663629'), 'local.mysitename', 'x^��\0\0�\0�', '1', 'a:1:{s:8:\"_profile\";s:1:\"1\";}', 'a:0:{}', 'a:0:{}', '', '', '', 'localhost', '') 

SHOW CREATE TABLE:

CREATE TABLE `details` (
  `id` char(17) NOT NULL,
  `url` varchar(255) DEFAULT NULL,
  `c_url` varchar(255) DEFAULT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `server name` varchar(64) DEFAULT NULL,
  `perfdata` mediumblob,
  `type` tinyint(4) DEFAULT NULL,
  `cookie` blob,
  `post` blob,
  `get` blob,
  `pmu` int(11) unsigned DEFAULT NULL,
  `wt` int(11) unsigned DEFAULT NULL,
  `cpu` int(11) unsigned DEFAULT NULL,
  `server_id` char(3) NOT NULL DEFAULT 't11',
  `aggregateCalls_include` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `url` (`url`),
  KEY `c_url` (`c_url`),
  KEY `cpu` (`cpu`),
  KEY `wt` (`wt`),
  KEY `pmu` (`pmu`),
  KEY `timestamp` (`timestamp`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Source: (StackOverflow)

xhprof chart description

For profiling, I have started to use XHprof. Nice tool! But, one question I can't answer by myself relates to chart content. Is there anyone who knows what color box and width of arrows on XHProf generated charts mean?

UPDATED It was not last question, here is couple new:

  • Why on chart could be two or more red squares but only one of it will be connected by thick arrow with yellow squares ?
  • What does it mean load:: in "Function name" column (on table mode view) ? is it means that PHP spent (cpu, mem etc) for loading that file ? Spent CPU time and Memory usage different from file to file, is it depends from filesize ? or content of file ? or both ? or something else ?
  • What can you say (without detailes) when you'll see such charts ?

https://dl.dropbox.com/u/7017985/Screenshots/h4kq.png https://dl.dropbox.com/u/7017985/Screenshots/r1bc.png

is it possible to figure out anything without details, just looking on these charts ?


Source: (StackOverflow)

Showing function arguments in xhprof

in xhprof I can see only function names and their execution time,...Is there a way to know which arguments are passed to them?


Source: (StackOverflow)

PHP is occasionally saturating my production web server CPU for 10 minutes - How can I examine the cause when the server is in this state?

My Apache PHP servers sometimes appear to become CPU bound for around 10 minutes and then go back to being normal. I've looked at these hosts in perf (system profiler) and it's all in PHP (5.6.11).

We need to be able to profile the actual PHP code when this happens to see what is going on. Optimally we would be able to have a profiler installed at all times, and enable it when we catch a box in this condition.

What is a good strategy for examining a CPU saturated PHP web server in production to understand what's going on?


Source: (StackOverflow)

How to use xhgui with MAMP for wordpress?

I am quite new to apache and PHP. I currently have a wordpress running locally (MacOS) with MAMP.

I use xhgui (https://github.com/perftools/xhgui) which works fine. For instance, it profiles itself when I put auto_prepend_file = "/path/to/xhgui/external/header.php" into the global php.ini.

But mamp seems to use its own php.ini (as indicated by phpinfo). So I added the same line there. Still, xhgui does not profile it.

What am I doing wrong?

PS: I am running with "php -S 0:8080 -t webroot/" and not through a vhost via mamp, since I could not get it to work. Can this cause the problem?

Edit: my vhost

<VirtualHost *:8888>
    php_admin_value auto_prepend_file "/Users/me/Desktop/xhgui/external/header.php"
    DocumentRoot "/Users/me/Documents/path/to/wordpress"
    ServerName localhost
</VirtualHost>

Source: (StackOverflow)

how install xhprof for php 5.6 on windows

How to install the extension Xhprof on Windows for php-5.6? I found only this link: http://windows.php.net/downloads/pecl/releases/xhprof/0.10.6/


Source: (StackOverflow)