2017 © Pedro Peláez
 

library profiler

PHP profiler

image

minond/profiler

PHP profiler

  • Friday, January 31, 2014
  • by minond
  • Repository
  • 1 Watchers
  • 2 Stars
  • 398 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Profiler

Important note

It is important to note this is a very simple profiler and should only be used to get an idea of a script's performance., (*1)

Profiler

Creating new profilers:, (*2)

use util\profile\Profiler;
use util\profile\Snapshot;

$profiler = new Profiler('AcmeAnvils');

Starting up and shutting down a profiler:, (*3)

$profiler->start();
$profiler->stop();

Listening to profiler events:, (*4)

// triggered by calling Profiler::start
$profiler->on('start', function(Snapshot $snapshot) {
  youroutput('profiling: %s', $snapshot->name);
});

// triggered on every PHP tick
$profiler->on('tick', function(Snapshot $snapshot) {
  youroutput('.');
});

// triggered by calling Profiler::stop
// you'll at least want to register to this event,
// otherwise the profiling data it worthless
$profiler->on('stop', function(Snapshot $snapshot) {
  youroutput('done profiling: %s', $snapshot->name);
  print_r($snapshot);
});

It is not necessary to call the stop method on a profiler, as it will register a shutdown function that will trigger a call to stop., (*5)

Profiling

Sample of profiling code:, (*6)

use util\profile\Profiler;
use util\profile\Snapshot;

$profiler = new Profiler('AcmeAnvils');
$profiler->start();
$profiler->on('stop', function(Snapshot $snapshot) {
  print_r($snapshot);
});

// code you want to profile
// ...

$profiler->stop();

Snapshot

Sample Snapshot object:, (*7)

object(util\profile\Snapshot)[33]
  public 'name' => string 'AcmeAnvils' (length=10)
  public 'mode' => int 2
  public 'maxmemory' => int 1135472
  public 'avgmemory' => float 1128570.4
  public 'currentmemory' => int 1128568
  public 'currenttime' => float 1368675239.0269
  public 'starttime' => float 1368675239.0263
  public 'startmemory' => int 1122604
  public 'endtime' => float 1368675239.0269
  public 'endmemory' => int 1128520
  public 'runtime' => float 0.00060391426086426
  public 'trace' =>
    array (size=5)
      0 =>
        array (size=7)
          'file' => string 'file.php' (length=53)
          'line' => int 10
          'function' => string 'function_name' (length=14)
          'class' => null
          'type' => null
          'memory' => int 1126948
          'time' => float 1368675239.0264

Reports

Reports are used to output Snapshot objects in a human/environment friendly format:, (*8)

use util\profile\reports\Chart;

$chart = new Chart;
$chart->prepare($snapshot);
$chart->configure(['chart_type' => 'LineChart']);
echo $chart->output();

Installation

Install via composer: "minond/profiler": "dev-master", (*9)

The Versions

31/01 2014

dev-master

9999999-dev

PHP profiler

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Marcos Minond