Profile XSLT transformations within PHP
Ever wanted to know where your XSLT transformations spend most of their time? Look no further than this patch to the PHP XSL extension. It uses the built in profiler of libxslt to get the information which template was called how many times and how much time was spent in them. It may help in improving the speed of your XSLT transformations, like a PHP debugger can help in profiling your PHP scripts.
The profiling information is written into a file, which you can enable the following way:
$proc = new xsltprocessor(); $proc->importStylesheet($xsld); $proc->setProfiling("/tmp/xslt-profiling.txt"); print $proc->transformToXml($dom);
And then read the file with any text-editor. I will commit the patch to the PHP CVS repository, but as PHP is now in a release phase, this has to wait until later. If I'm allowed at all to put this new feature into the PHP_5_2 branch, but HEAD shouldn't be a problem.
Our experience also showed, that the import of the stylesheets (->importStylesheet() above) can also be a performancekiller, as much as the actual transformation, especially if you have a lot of xsl:import or xsl:include in your code. You can profile the time taken for the whole importStylesheet call with any php profiler (or just with microtime()), but if you want to know, how much each stylesheet took, there's no easy way. Therefore I wrote a little quick&dirty patch to libxslt itself, which writes some profiling information collected during the import phase directly into the hardcoded /tmp/xsltbench.txt. I just wrote that patch for me, so don't expect it to be really self-explanatory (or tested), but it may nevertheless help some of you in finding bottlenecks.
Add a comment
Your email adress will never be published. Comment spam will be deleted!