Talk:Requests for comment/Better PHP profiling


Notes from #hhvm, 2-Jan-2013[edit]

[jdelong] we don't really do any sort of tail or sibling call optimizations for php code, so that's not there to turn off
[jdelong] but when you turn on the profiler things do execute a little more slowly---every function entry and exit will hit this "surpise flag" check
[jdelong] and go to a slower path to record what happened
[jdelong] one other thing worth mentioning is that if you want to do profiling of php in php, we have this function called fb_setprofile
[jdelong] which lets you set up a php function that should run on entry/exit of every other php function
[jdelong] I'm pretty sure several of the profiling tools at fb are just just built in php using that
[jdelong] ori: hmm, I'm not 100% sure xhprof is sampling in our implementation
[jdelong] I kinda suspect it still just uses the surprise flag mechanism

[jdelong] hphp/runtime/ext/ext_hotprofiler is most of it
[jdelong] oh it looks like it does support sampling or not

[jdelong] ah also I forgot about this: mikemag started an experimental profiler for looking for memoization opportunities

[scannell] ori: hey, i work on the memory profiler portion
[scannell] it's going to need to need some work to get it working in the github build because you have to disable jemalloc to get meaningful numbers
[scannell] actually, wait, nevermind
[scannell] i'm thinking of ASAN
[scannell] ori: it works, you need to compile with -DMEMORY_PROFILING and then set HHProfServer.Enabled = true
[scannell] pprof style output
[scannell] for all allocs of PHP primitives (object, array, resource, string, etc.)
[scannell] turning on the memory profiler will significantly slow things down so don't do that at the same time as xhprof (as we end up capturing a stack trace every time PHP code invokes the smart allocator / deallocator)
[scannell] for a lot of things fb_setprofile may be what you want though

xhprof at wikia[edit]

+1 for xhprof as far as Wikia is concerned. One nice feature of the current wfProfileIn/Out calls is that the data can be collected remotely via the UDP Profiler backend. We are doing some experiments with a similar collector backend for xhprof generated traces so that the data can be aggregated. Unfortunately that's not a built in feature of xhprof... Once those experiments have generated some useful information I'll try to add it here. Owyn (talk)

Owyn - Thanks! Any news? Sumana Harihareswara (talk) 00:21, 29 April 2014 (UTC)Reply[reply]

Working towards a better Profiler[edit]

Some work has begun on cleaning up Profiler under the umbrella of the librarization project. I (bd808) spent some time noodling with the xhprof API and came up with a wrapper class that makes working with the profiler a bit nicer than the raw functionality (Gerrit change 168930). Chad has been working on various cleanup patches to make it easier to see what Profiler is doing and get rid of unused cruft. Aaron is planning on taking a look at finding an alternate solution for a couple of edge cases that xhprof is not good at supporting (TransactionProfiler and Parser::braceSubstitution). We will try to dust off this RFC and get discussion on the bigger changes that we'd like to see happen. Ultimately we would like to remove direct wfProfileIn()/wfProfileOut() calls from the codebase and instead rely on interpreter integrated profiling tools like xhprof. --BDavis (WMF) (talk) 22:21, 6 November 2014 (UTC)Reply[reply]

Notes from 2014-11-12 RFC meeting[edit]

The idea seemed to be generally supported. Tim was in favor of a plan to remove wfProfileIn/wfProfileOut calls for full function profiling once xhprof works. Sub-function profiling is desired so we could either implement support for a hybrid report or look into upstreaming patches to add a workalike feature into XHProf upstream. This would require working with both HHVM and the PECL module which have separate codebases. --BDavis (WMF) (talk) 22:38, 12 November 2014 (UTC)Reply[reply]

I found that HHVM's XHProf implementation already provides xhprof_frame_begin & xhprof_frame_end functions which are meant for exactly our sub-function profiling purpose. I have opened a feature request with the PECL XHProf project to see if they would be interested in backporting this functionality. --BDavis (WMF) (talk) 21:36, 18 November 2014 (UTC)Reply[reply]