Welcome Guest, Not a member yet? Register   Sign In
Profiler/Benchmark can the marks be additive? [SOLVED]
#1

[eluser]Raymond Steigerwalt[/eluser]
I am interfacing with an external database system over odbc. I am doing multiple requests, some in a loop calling the same function.

The total time for load is ~7 seconds. When I add marks to my methods, it seems as if a mark shares the same name it is overridden. Is there a way for the marks to be additive so if I call the same method 20 times all 20 times are added together in the profiler output?

Sorry if this question has been answered, I was not able to find anything on documentation/google/forum search. I'd like to know if anyone had similar requirements or have discovered a way to do this before I start to modify the benchmark/profiler classes.

Thanks!
Raymond
#2

[eluser]WanWizard[/eluser]
Here you go:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExiteCMS
*
* An open source application development framework for PHP 4.3.2 or newer
* ExiteCMS is based on CodeIgniter, Copyright (c) Ellislab Inc.
*
* @package        ExiteCMS
* @author        WanWizard
* @copyright    Copyright (c) 2009, ExiteCMS.org
* @license        http://www.exitecms.org/license.php
* @link        http://www.exitecms.org
* @since        Version 8.0
* @filesource
*/

// ---------------------------------------------------------------------

class MY_Benchmark extends CI_Benchmark
{
    var $marker_history = array();

    /**
     * Constructor
     *
     * @return void
     * @access public
     */
    function MY_Benchmark()
    {
        // there is no parent constructor

        // Logs initialization message for debugging
        log_message('debug', 'ExiteCMS Benchmark Class Extension Initialized');
    }

    // -----------------------------------------------------------------

    /**
     * Set a benchmark marker
     *
     * When multiple calls to this function are made the execution history
     * is saved so the profiler can show accurate totals
     *
     * @access    public
     * @param    string    $name    name of the marker
     * @return    void
     */
    function mark($name)
    {
        if ( isset($this->marker[$name]) )
        {
             if (preg_match("/(.+?)_end/i", $name, $match))
             {
                if ( ! isset($this->marker_history[$name]) )
                {
                    $this->marker_history[$name] = 0;
                }
                 if (isset($this->marker[$match[1].'_end']) AND isset($this->marker[$match[1].'_start']))
                 {
                     $this->marker_history[$name] += $this->elapsed_time($name, $match[1].'_start');
                 }
            }
        }
        $this->marker[$name] = microtime();
    }

}

/* End of file MY_Benchmark.php */
/* Location: ./exitecms/libraries/MY_Benchmark.php */

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExiteCMS
*
* An open source application development framework for PHP 4.3.2 or newer
* ExiteCMS is based on CodeIgniter, Copyright (c) Ellislab Inc.
*
* @package        ExiteCMS
* @author        WanWizard
* @copyright    Copyright (c) 2009, ExiteCMS.org
* @license        http://www.exitecms.org/license.php
* @link        http://www.exitecms.org
* @since        Version 8.0
* @filesource
*/

// ---------------------------------------------------------------------

class MY_Profiler extends CI_Profiler
{
    /**
     * Constructor
     *
     * @return void
     * @access public
     */
    function MY_Profiler()
    {
        // call the parent constructor
        parent::CI_Profiler();

        // Logs initialization message for debugging
        log_message('debug', 'ExiteCMS Profiler Class Extension Initialized');
    }

     function _compile_benchmarks()
     {
        foreach ( $this->benchmark->marker_history as $key => $value )
        {
            if ( isset($this->benchmark->marker[$key]) )
            {
                list($em, $es) = explode(' ', $this->benchmark->marker[$key]);
                $em += $value;
                $this->benchmark->marker[$key] = $em.' '.$es;

            }
        }

        $output = parent::_compile_benchmarks();

        return $output;
}

/* End of file MY_Profiler.php */
/* Location: ./exitecms/libraries/MY_Profiler.php */
#3

[eluser]Raymond Steigerwalt[/eluser]
Very nice, thank you! I only noticed one small change,

in the MY_Profiler I had to change references to $this->benchmark-> to $this->CI->benchmark->

Thanks for your help!
#4

[eluser]WanWizard[/eluser]
Possible.

I use a modified version of CI, I got fed up with using $this here, $CI there. Either don't use $this, or make sure it can be used everywhere (which I did)...




Theme © iAndrew 2016 - Forum software by © MyBB