PHP Profiling

Preview:

DESCRIPTION

PHP Profiling tool - Xdebug, XHProf in Korean XE Cont + PHPFest 2014 track1 session2 XE Developer Group

Citation preview

$start = microtime(); // 측정하려는 코드$end = microtime(); $duration = $end - $start;

$startMem = memory_get_usage(); // 측정하려는 코드$endMem = memory_get_usage(); $memoryUsage = $end - $start;

원시적이다. 이러

지맙시다

.

개발자의����������� ������������������  숙명,����������� ������������������  툴����������� ������������������  익히기!!

개발자의����������� ������������������  숙명,����������� ������������������  툴����������� ������������������  익히기!!

PHPXdebug

WebGrind

$ pecl install xdebug $ vi php.ini

zend_extension = xdebug.soxdebug.profiler_enabled = 0 # 상시 프로파일링 설정xdebug.profiler_append = 1 # 측정데이터 누적 설정xdebug.profiler_enable_trigger = 1 # XDEBUG_PROFILE 사용설정xdebug.profiler_output_dir = /tmp/xdebug # 파일 저장 경로

https://code.google.com/p/webgrind/wiki/Installation

$ pecl install channel://pecl.php.net/xhprof-0.9.4$ vi php.ini

extension = xhprof.soxhprof.output_dir = /tmp/xhprof

// headerif (extension_loaded('xhprof')) { include_once 'php/xhprof_lib/utils/xhprof_lib.php'; include_once 'php/xhprof_lib/utils/xhprof_runs.php'; xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); }

// footerif (extension_loaded('xhprof')) { $profiler_namespace = 'profiler'; $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id =

$xhprof_runs->save_run($xhprof_data,$profiler_namespace);}

<?PHP

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->string; }

<?PHP

function repeat($obj) { $obj->string = str_repeat($obj->string, 15000); } function free($obj) { unset($obj->string); }

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

$start = microtime();

$end = microtime();

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

$start = memory_get_usage();

$end = memory_get_usage();

$start

$end

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

$start = memory_get_peak_usage();

$end = memory_get_peak_usage();

$start

$end

function test() { $obj = new stdClass(); $obj->string = 'Hello'; repeat($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } free($obj); for($i=3000; $i>1; $i--) { $obj->string .= 'Hello'; } echo $obj->s; }

$start

$end

43

44

45

46

47

48

49

50

51

52

라이브 서버, 항상 XE 최신버전

53

54

55

Recommended