直观地分析PHP应用程序的内存使用情况的工具 [英] Tools to visually analyze memory usage of a PHP app

查看:111
本文介绍了直观地分析PHP应用程序的内存使用情况的工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何免费软件或商业软件可以促进PHP应用程序对内存使用情况的分析?我知道xdebug可以生成跟踪文件,该跟踪文件可以通过函数调用显示内存使用情况,但是如果没有图形工具,数据将难以解释.

Is there anything out there freeware or commercial that can facilitate analysis of memory usage by a PHP application? I know xdebug can produce trace files that shows memory usage by function call but without a graphical tool the data is hard to interpret.

理想情况下,我希望不仅可以查看总内存使用情况,而且还可以查看堆中有哪些对象以及类似于

Ideally I would like to be able to view not only total memory usage but also what objects are on the heap and who references them similar to Jprofiler.

推荐答案

您可能已经知道,Xdebug从2. *版本开始就放弃了内存分析支持.请在此处搜索已删除的功能"字符串: http://www.xdebug.org/updates.php

As you probably know, Xdebug dropped the memory profiling support since the 2.* version. Please search for the "removed functions" string here: http://www.xdebug.org/updates.php

已删除功能

删除了对内存配置文件的支持,因为它无法正常工作.

Removed support for Memory profiling as that didn't work properly.

所以我尝试了另一种工具,对我来说效果很好.

So I've tried another tool and it worked well for me.

https://github.com/arnaud-lb/php-memory-profiler

这是我在Ubuntu服务器上为启用它所做的事情:

This is what I've done on my Ubuntu server to enable it:

sudo apt-get install libjudy-dev libjudydebian1
sudo pecl install memprof
echo "extension=memprof.so" > /etc/php5/mods-available/memprof.ini
sudo php5enmod memprof
service apache2 restart

然后在我的代码中:

<?php

memprof_enable();

// do your stuff

memprof_dump_callgrind(fopen("/tmp/callgrind.out", "w"));

最后使用 KCachegrind

首先通过在此处下载最新的软件包来安装 Google gperftools : https://code.google.com/p/gperftools/

First of all install the Google gperftools by downloading the latest package here: https://code.google.com/p/gperftools/

然后一如既往:

sudo apt-get update
sudo apt-get install libunwind-dev -y
./configure
make
make install

现在输入您的代码:

memprof_enable();

// do your magic

memprof_dump_pprof(fopen("/tmp/profile.heap", "w"));

然后打开您的终端并启动:

Then open your terminal and launch:

pprof --web /tmp/profile.heap

pprof 将在您现有的浏览器会话中创建一个新窗口,如下所示:

pprof will create a new window in your existing browser session with something like shown below:

使用 Xhprof Xhgui ,您还可以分析cpu的使用情况,也可以仅分析内存使用情况(如果这是当前的问题). 这是一个非常完整的解决方案,它使您可以完全控制,并且日志可以写在mongo或文件系统中.

With Xhprof and Xhgui you can profile the cpu usage as well or just the memory usage if that's your issue at the moment. It's a very complete solutions, it gives you full control and the logs can be written both on mongo or in the filesystem.

有关更多详细信息,请在此处查看我的答案

For more details see my answer here.

Blackfire是由SensioLabs(Symfony2伙计们) https://blackfire.io/

Blackfire is a PHP profiler by SensioLabs, the Symfony2 guys https://blackfire.io/

如果您使用 puphpet 来设置您的虚拟机,您将很高兴知道它的支持;-)

If you use puphpet to set up your virtual machine you'll be happy to know it's supported ;-)

这篇关于直观地分析PHP应用程序的内存使用情况的工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆