How the PHP Profiler performs time profiling
masterThe profiler uses a mechanism to collect performance data with low overhead:
- Interrupt Mechanism: The profiler sets the Zend VM interrupt flag approximately every 10ms. The Zend Engine handles this interrupt at the next safe point (e.g., after an internal function like
curl_execis popped off the stack). - Internal Hooks: It installs a
zend_execute_internalhook to ensure the profiler can see internal functions without clearing the interrupt, allowing other extensions to continue processing interrupts normally. - Data Collection: When the interrupt handler runs, it collects both wall-time and cpu-time since the last run.
Note on CPU-time: Because of the collection method, cpu-time is biased towards functions performing I/O. This approach is chosen to keep the overhead on the process extremely low.