Connecting Tech Pros Worldwide Help | Site Map

PHP profiler

Mladen Gogala
Guest
 
Posts: n/a
#1: Dec 17 '05
I'm looking for a GPL licensed PHP profiler. The best thing around,
except the commercial goodies from NuSphere, seems to be Carl Taylor's
toolkit at http://www.adepteo.net/profiler/index.php
Any experiences? Does anybody here uses profiler to see where the
application time is spent and which components need fine tuning?

--
http://www.mgogala.com

Chung Leong
Guest
 
Posts: n/a
#2: Dec 18 '05

re: PHP profiler


Here is a simple profiler I wrote. It uses a tick function to measure
the time expired between each PHP operation and debug_back_trace() to
find out where it occurs. Kinda neat as you don't have to make much
modification. Just include it at the beginning of the script, then at
the end, call __profile__('get') to obtain the profile data--an
associative array of percentages keyed by function names.

profiler.php:
<?php

function __profiler__($cmd = false) {
static $log, $last_time, $total;
list($usec, $sec) = explode(" ", microtime());
$now = (float) $usec + (float) $sec;
if($cmd) {
if($cmd == 'get') {
unregister_tick_function('__profile__');
foreach($log as $function => $time) {
if($function != '__profile__') {
$by_function[$function] = round($time / $total * 100, 2);
}
}
arsort($by_function);
return $by_function;
}
else if($cmd == 'init') {
$last_time = $now;
return;
}
}
$delta = $now - $last_time;
$last_time = $now;
$trace = debug_backtrace();
$caller = $trace[1]['function'];
@$log[$caller] += $delta;
$total += $delta;
}

__profiler__('init');
register_tick_function('__profiler__');
declare(ticks=1);

?>

Chung Leong
Guest
 
Posts: n/a
#3: Dec 18 '05

re: PHP profiler


Forgot to mention that as tick functions don't work in a threaded
environment, you'll need to set up PHP as CGI if you're on Windows.

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#4: Dec 20 '05

re: PHP profiler


Mladen Gogala wrote:[color=blue]
> I'm looking for a GPL licensed PHP profiler. The best thing around,
> except the commercial goodies from NuSphere, seems to be Carl Taylor's
> toolkit at http://www.adepteo.net/profiler/index.php
> Any experiences? Does anybody here uses profiler to see where the
> application time is spent and which components need fine tuning?[/color]

Never tried. But, I use APD <http://in.php.net/apd>. It's neat, but
lacks GUI. We use our own GUI (can't give, sorry).

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#5: Dec 20 '05

re: PHP profiler


Chung Leong wrote:[color=blue]
> Here is a simple profiler I wrote.[/color]
<snip>

Hard core programmers like you'll always write codes and would
restrain to use other tools:( But, I would suggest you to try APD
<http://in.php.net/apd> and see the difference.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Mladen Gogala
Guest
 
Posts: n/a
#6: Dec 20 '05

re: PHP profiler


On Mon, 19 Dec 2005 20:51:10 -0800, R. Rajesh Jeba Anbiah wrote:
[color=blue]
> Never tried. But, I use APD <http://in.php.net/apd>. It's neat, but
> lacks GUI. We use our own GUI (can't give, sorry).[/color]

APD is a debugger, not a profiler. Thanks.

--
http://www.mgogala.com

Andy Hassall
Guest
 
Posts: n/a
#7: Dec 20 '05

re: PHP profiler


On Tue, 20 Dec 2005 15:55:50 GMT, Mladen Gogala <gogala@sbcglobal.net> wrote:
[color=blue]
>On Mon, 19 Dec 2005 20:51:10 -0800, R. Rajesh Jeba Anbiah wrote:
>[color=green]
>> Never tried. But, I use APD <http://in.php.net/apd>. It's neat, but
>> lacks GUI. We use our own GUI (can't give, sorry).[/color]
>
>APD is a debugger, not a profiler. Thanks.[/color]

"APD is the Advanced PHP Debugger. It was written to provide profiling and
debugging capabilities for PHP code"

And it goes on with an example of profiling later on the page.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Closed Thread


Similar PHP bytes