55

PHP Profiling

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: PHP Profiling
Page 2: PHP Profiling
Page 3: PHP Profiling
Page 4: PHP Profiling
Page 5: PHP Profiling
Page 6: PHP Profiling
Page 7: PHP Profiling
Page 8: PHP Profiling
Page 9: PHP Profiling
Page 10: PHP Profiling
Page 11: PHP Profiling
Page 12: PHP Profiling
Page 13: PHP Profiling
Page 14: PHP Profiling
Page 15: PHP Profiling
Page 16: PHP Profiling

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

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

원시적이다. 이러

지맙시다

.

Page 17: PHP Profiling

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

Page 18: PHP Profiling

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

Page 19: PHP Profiling
Page 20: PHP Profiling
Page 21: PHP Profiling
Page 22: PHP Profiling
Page 23: PHP Profiling
Page 24: PHP Profiling
Page 25: PHP Profiling
Page 26: PHP Profiling

PHPXdebug

Page 27: PHP Profiling

WebGrind

Page 28: PHP Profiling

$ 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

Page 29: PHP Profiling

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

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

Page 30: PHP Profiling

// 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);}

Page 31: PHP Profiling
Page 32: PHP Profiling

<?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); }

Page 33: PHP Profiling
Page 34: PHP Profiling
Page 35: PHP Profiling
Page 36: PHP Profiling

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; }

Page 37: PHP Profiling

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();

Page 38: PHP Profiling

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; }

Page 39: PHP Profiling

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

Page 40: PHP Profiling

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; }

Page 41: PHP Profiling

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

Page 42: PHP Profiling

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

Page 43: PHP Profiling

43

Page 44: PHP Profiling

44

Page 45: PHP Profiling

45

Page 46: PHP Profiling

46

Page 47: PHP Profiling

47

Page 48: PHP Profiling

48

Page 49: PHP Profiling

49

Page 50: PHP Profiling

50

Page 51: PHP Profiling

51

Page 52: PHP Profiling

52

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

Page 53: PHP Profiling

53

Page 54: PHP Profiling

54

Page 55: PHP Profiling

55