[devzone tuterial link](https://devzone.zend.com/1139/profiling-php-applications-with-xdebug/) xdebug开启是在php.ini中。文章前段详细介绍了xdebug的相关设置,不过重点想看后面的log分析,所以先跳过。 ## Analyzing xdebug profiling logs xdebug’s profiling logs are in a Cachegrind compatible format. PHP利用了valgrind的套件作为分析器profiler,所以生成的文件格式也是Cachegrind格式,not really human-readable。目前为止能分析的工具有 KCachegrind( for Unix),然后是WinCachegrind(for windows)。 首先是WinCachegrind,在profile->Hide Fast Function && Profiler -> Hide Library Functions 这里可以隐藏执行较快和PHP内建的函数。 发现Symfony\Component\DependencyInjection\Container->get 这里耗时1120ms,calls290。 然后去vendor下看了这个文件,是依赖注入容器,管理服务的接口。 ```php /** * Container is a dependency injection container. * * It gives access to object instances (services). * * Services and parameters are simple key/pair stores. * * Parameter and service keys are case insensitive. ``` get()就是获取服务的方法了,call那么多次也能理解,不,就是call太多次了.... 然后看了下调用的来源,占用最多的方法依次为 - 156ms Doctrine\ManagerRegistry->getService() - 140ms Controller->render() - 125ms appProdDebugProjectContainer->getTemplatingService() - 78ms EmailSenderListener->onTerminate linux、mac这里是用KCachegrind。