Previous Class
Solar_Controller_Page

Solar_Debug_Timer
Overview

Next Page
Constants

Solar_Debug_Timer

Tracks code execution times.

This class allows you to profile the execution time of your script: you start the timer, set marks within your script, then stop the timer and display the profile.

In the following example, we'll sleep() for random periods under a second, then mark the timer profile.

<?php
require_once 'Solar.php';
Solar::start();

// create a timer and start it
$timer = Solar::factory('Solar_Debug_Timer');
$timer->start();

// loop and pause for a random period under 1 second,
// then make a profile mark
for ($i = 0; $i < 5; $i++) {
    time_nanosleep(0, rand(1,999999999));
    $timer->mark("iteration_$i");
}

// stop the timer and display the profile
$timer->stop();
$timer->display();
?>

The resulting profile might look something like this:

name        : diff     : total   
__start     : 0.000000 : 0.000000
iteration_0 : 0.376908 : 0.376908
iteration_1 : 0.395037 : 0.771945
iteration_2 : 0.607002 : 1.378947
iteration_3 : 0.202960 : 1.581907
iteration_4 : 0.232987 : 1.814894
__stop      : 0.000056 : 1.814950

In the above profile, the "name" is the mark name, the "diff" is the difference (in seconds) from the previous mark, and the "total" is a running total (in seconds) for the execution time. Note that the "diff" for the __start mark is zero, as there is no previous mark to get a difference from.

Catalog

This class is part of the Solar_Debug package.

Inheritance:

Constants

None.

Public Properties

The Solar_Debug_Timer class has no public properties; try the list of all properties.

Public Methods

These are all the public methods in the Solar_Debug_Timer class.

You can also view the list of all public, protected, and private methods.

__construct()
Constructor.
__destruct()
Destructor.
apiVersion()
Reports the API version for this class.
display()
Displays formatted output of the current profile.
dump()
Convenience method for getting a dump the whole object, or one of its properties, or an external variable.
fetch()
Fetches the current profile formatted as a table.
locale()
Looks up class-specific locale strings based on a key.
mark()
Marks the time.
profile()
Returns profiling information as an array.
start()
Resets the profile and marks a new starting time.
stop()
Stops the timer.