PHP 메모리 프로파일 링
PHP 페이지의 메모리 사용량을 프로파일 링하는 좋은 방법은 무엇입니까? 예를 들어, 내 데이터가 사용중인 메모리 양 및 / 또는 가장 많은 메모리를 할당하는 함수 호출을 확인합니다.
xdebug는 프로파일 링 기능에서 메모리 정보를 제공하지 않는 것 같습니다.
xdebug 는 추적 기능에서이를 제공합니다. 이것은 모든 단일 함수 호출에 대한 메모리 델타를 보여주기 때문에 엄청난 양의 데이터가 압도적이라는 점을 제외하고는 내가 원하는 것과 매우 비슷합니다. GUI 도구를 사용하여 특정 깊이 이하로 호출을 숨길 수 있다면 내 문제를 해결할 수 있습니다.
다른 건 없나요?
Xdebug 는 Qcachegrind 또는 유사한 도구에서 사용할 수있는 2.6 (2018-01-29) 에서 메모리 추적을 다시 구현했습니다 . 그냥 메모리 옵션을 선택해야합니다 :)
문서에서 :
Xdebug 2.6 이후로 프로파일 러는 사용중인 메모리 양과 메모리 사용량을 증가시킨 Gnd 메소드에 대한 정보도 수집합니다.
나는 파일 형식에 익숙하지 않지만 Qcachegrind가 몇 가지 메모리 문제를 추적하는 데 큰 도움이되었습니다.
아시다시피 Xdebug는 2. * 버전부터 메모리 프로파일 링 지원을 중단했습니다. 여기에서 "제거 된 기능"문자열을 검색하십시오 : http://www.xdebug.org/updates.php
제거 된 기능
제대로 작동하지 않았기 때문에 메모리 프로파일 링에 대한 지원을 제거했습니다.
그래서 다른 도구를 사용해 보았는데 잘 작동했습니다.
https://github.com/arnaud-lb/php-memory-profiler
이 기능을 활성화하기 위해 Ubuntu 서버에서 수행 한 작업입니다.
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로callgrind.out
파일을 엽니 다.
Google gperftools 사용 (권장!)
먼저 https://code.google.com/p/gperftools/ 에서 최신 패키지를 다운로드하여 Google 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"));
그런 다음 터미널을 열고 실행하십시오.
pprof --web /tmp/profile.heap
pprof 는 아래와 같이 기존 브라우저 세션에 새 창을 만듭니다.
Xhprof + Xhgui (내 의견으로는 CPU와 메모리를 모두 프로파일 링하는 것이 최고)
로 Xhprof 및 Xhgui 그 문제 순간에 있다면 당신은뿐만 아니라하거나 메모리 사용량 CPU 사용량을 프로파일 링 할 수 있습니다. 매우 완벽한 솔루션이며 완전한 제어권을 제공하며 로그는 mongo 또는 파일 시스템 모두에서 작성할 수 있습니다.
자세한 내용 은 여기 내 대답을 참조하십시오 .
검은 화재
Blackfire is a PHP profiler by SensioLabs, the Symfony2 guys https://blackfire.io/
If you use puphpet to set up your virtual machine you'll be happy to know it's supported ;-)
Well, this may not be exactly what you're looking for, but PHP does have a couple of functions built-in that will output memory usage. If you just wanted to see how much memory a function call is using, you could use memory_get_peak_usage() before and after a call, and take the difference.
You use the same technique around your data using the very similar memory_get_usage().
Pretty unsophisticated approach, but it's a quick way to check out a piece of code. I agree that xdebug mem deltas can be too verbose to be useful sometimes, so I often just use it to narrow down to a section of code, then dump out specific memory usage for small pieces manually.
http://geek.michaelgrace.org/2012/04/tracing-php-memory-usage-using-xdebug-and-mamp-on-mac/
I'm on a Mac so if you're on Windows you'll have to test this, but this works for me.
I modified my tracefile-analyzer.php file and added the path to the PHP binary at the top so that you could call it in terminal as a normal unix script.
#!/Applications/MAMP/bin/php5.3/bin/php
<?php
if ( $argc <= 1 || $argc > 4 )
{
Don't forget to chmod this file to 755.
메모리 프로필 파일 (* .xt)을 생성 할 때마다 자동으로 스크립트를 호출하는 루비 감시자 스크립트를 쉽게 생성 할 수 있습니다. 이렇게하면 명령을 반복해서 실행하지 않고도 계속해서 테스트하고 개선 사항을 확인할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/880458/php-memory-profiling
'program tip' 카테고리의 다른 글
65 개 요소로 구성된 배열을 선언하는 것보다 1000 배 빠른 64 개 요소로 여러 배열을 선언합니다. (0) | 2020.09.04 |
---|---|
C # 멤버 변수 초기화; (0) | 2020.09.04 |
클래스 다이어그램을 만들기위한 도구 (0) | 2020.09.04 |
사용하지 않는 함수 매개 변수 값을 void로 캐스팅하는 이유는 무엇입니까? (0) | 2020.09.04 |
왜 목록 (0) | 2020.09.04 |