xhprof icon indicating copy to clipboard operation
xhprof copied to clipboard

Add support for HHVM compatible xhprof_frame_begin & xhprof_frame_end

Open bd808 opened this issue 9 years ago • 1 comments

The HHVM implementation of XHProf includes two handy functions and a wrapper class to allow sub-function profiling:

  • xhprof_frame_begin : Starts an artificial frame. Together with xhprof_frame_end(), this times one block of code execution as if it were a function call, allowing people to define arbitrary function boundaries. Prefer to use XhprofFrame classobjects instead of calling this function directly.
  • xhprof_frame_end : Ends an artificial frame that xhprof_frame_begin() started. One has to make sure there are no exceptions in between these two calls, as otherwise, it may report incorrect timings. Also, xhprof_frame_begin() and xhprof_frame_end() have to be paired up really well, so not to interfere with regular function's profiling, unless that's the intention. Prefer to use XhprofFrame classobjects instead of calling this function directly.
  • XhprofFrame : Wrapper object that calls xhprof_frame_begin in its constructor and xhprof_frame_end in its destructor.
class XhprofFrame {
  public function __construct($name) {
    xhprof_frame_begin($name);
  }
  public function __destruct() {
    xhprof_frame_end();
  }
}

bd808 avatar Nov 18 '14 21:11 bd808

It looks to me like the implementation of these functions would be relatively straight forward wrappers around the BEGIN_PROFILING/END_PROFILING macros.

Having this support in the XHProf pecl extension would be very nice for libraries that are concerned about sub-function profiling and attempting to be compatible with both the PHP5 and HHVM interpreters.

bd808 avatar Nov 18 '14 21:11 bd808