응용개발

PHP PEAR extension 을 이용한 DB Time 추적

by 웁쓰 posted Jul 01, 2009

홈페이지 http://pear.php.net/package/Benchmark
PEAR란?
PHP Extension and Application Repository를 뜻한다.

설치된 PEAR 목록
[test@d85009 bin]$ ./pear list
Installed packages, channel pear.php.net:
=========================================
Package          Version State
Archive_Tar      1.3.2   stable
Benchmark        1.2.7   stable
Cache_Lite       1.7.7   stable
Console_Getopt   1.2.3   stable
PEAR             1.7.2   stable
Structures_Graph 1.0.2   stable
apd              1.0.1   stable

Benchmark 인스톨
[test@d85009 bin]$pear install Benchmark
Benchmark 업그래이드
[test@d85009 bin]$pear upgrade Benchmark

예제코드) require_once 'Benchmark/Timer.php'; $timer = new Benchmark_Timer(); $timer->start(); // connect to the server $db->connect(); $timer->setMarker('connection'); $sql = "SELECT COUNT(*) cnt FROM bbs where module_srl = 60 " ; // feed it the sql directly. it will return all records $all_rows = $db->fetch_all_array($sql); foreach($all_rows as $key=>$val){ $row_cnt = $val[cnt]; } $timer->setMarker('sql1-execute-fetch'); $db->close(); $timer->stop(); $timer->display(); // to output html formated
time index ex time %
Start 1246342988.69640600 - 0.00%
connection 1246342988.69703800 0.000632 3.45%
sql1execute-fetch 1246342988.71429800 0.017260 94.26%
Stop 1246342988.71471800 0.000420 2.29%
total - 0.018312 100.00%

Articles

1 2 3