Location: PHPKode > scripts > profiler > profiler/manual.html
<html>
<head>
    <title>Profiler Manual</title>
<LINK REL=STYLESHEET TYPE=text/css HREF=/profiler/basestyle.css>
</head>
<body>
<h1>Profiler Manual</h1>

This profiler is intended to be used to identify areas of code that could be optimised
in order to improve overall performance of an application.  Typically I identify the
areas of concern in an application and place profile timers around those sections and
focuss down to add timers around the areas that are taking the most time and look for
ways to optimise those particular areas.  The items with the highest percentage time spent
are usually the ones that can give the biggest improvements.

<h2>Features</h2>
    Perform profiling to provide the following information
    <li>Count the number of times a section of code is executed
    <li>Calculate the total ammount of time spent executing a section of code
    <li>Permit multiple timers to be set
    <li>Allow nested timers to such that the parent timers are suspended whilst a child section of code is running.
    <li>Output a report at the end of execution to show the percentage of time spent on an operation,
    <li>the number of times the section was run, the overall time spent on the section.

<h2>Usage</h2>

    <code>include_once( 'profiler.inc');</code>
<br />
    <code>$prof = new Profiler( profile_flag, trace_flag );</code>
<br /><br />
    <li>Profile_flag = true enables output of the statistical information
    <li>trace_flag = true enables output of the trace information
<br /><br />
    <code>$prof->startTimer( "timer_name", "Description" );</code>
<br /><br />
    <li>timer_name is a simple string to name the timer
    <li>description is an optional string to describe the purpose of the timer in more detail
<br /><br />
    <code>$prof->stopTimer( "timer_name" );</code>
<br /><br />
    <code>$prof->printTimers( flag );</code>
<br /><br />
    <li>Output the final report of the processing operation being run.  Normally this would be called
    as one of the last statements on a page.
    <li>If flag=true is set then the output will be forced even if the profile_flag was set false when the profiler was initialised
<br /><br />
<h2>Warning:</h2>
    If a profile timer is started in a function, it must be stopped prior to exiting that
    function in order to ensure integrity of the output information.

<h2>Example Usage</h2>
<pre>
        include_once('profiler.inc');
        $prof = new Profiler( true ); // Output the profile information but no trace

        $prof->startTimer( "initialise" );
        initialise_routine();
        $prof->stopTimer( "initialise" );

        $prof->startTimer( "main_loop" );

        while( $record=get_record() ){
            print_record( $record );
        }

        $prof->stopTimer( "main_loop" );

        $prof->printTimers( true );


        function get_record()
        {
            global $prof;

            $prof->startTimer( "get_record" );
            // Routine to get the record information
            $prof->stopTimer( "get_record" );
        }

        function print_record( $record )
        {
            global $prof;
            // print header information

            $prof->startTimer( "main_print_record" );
            // main print processing
            $prof->stopTimer( "main_print_record" );
        }
        </pre>


<h3>Feedback</h3>
If you make any improvements to the code, or just find it useful in helping you optimise
the performance of your applications I would appreciate you dropping a note.
<br>
<br>
&copy; Copyright 2002 <a href=mailto:hide@address.com>Carl Taylor</a>
</body>
</html>
Return current item: profiler