In software engineering, profiling is the process of analyzing performance attributes of an application during runtime. A profiler is a tool that monitors a program and captures information like how often functions and methods are called, how long each takes to execute, how much memory is consumed during various processes, etc.
Introduction to XHProf and XHGui
XHProf is a hierarchical profiler for PHPPHP PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. https://www.php.net/manual/en/preface.php., designed to be lightweight so it could be used to collect performance data in production environments. This design makes it well suited for measuring the performance of an application with minimal observability costs, i.e., side effects that skew the performance metrics it collects. XHProf was originally released by Facebook in 2009. It has been forked several times since, in order to add support for PHP 7+ and PHP 8+. The current version of XHProf included in the PECL repository is located at https://github.com/longxinH/xhprof and is what we recommend throughout the rest of this tutorial.
XHGui is a graphical user interface for displaying and interpreting profiling data collected by an XHProf compatible profiler. It stores profiling data in either a MongoDB or PDO database. The graphical user interface allows you to compare the memory and time consumption of separate profiling runs or review an individual run to explore performance statistics about each function run during an individual request, including the following:
- Call frequency – the number of times a function was called during execution
- Self wall time – the amount of time spent executing the function, excluding calls to child functions.
- Inclusive wall time – the amount of time spent executing the function including child functions
- Self memory usage – the total memory consumption of the function excluding child functions
- Inclusive memory usage – the total memory consumption of the function including child functions