[SOLVED] Custom benchmark/miniprofiler

#1
[eluser]Kenshiro[/eluser]
hello i have built a custom mini/profiler for my current project (i used 3 different methods as a standalone library, as profiler extension and as a benchmark extension)

I have a little problem though... if it's standalone/benchmark... the number of queries returned is always off.. it never goes over 7...

The drawback of using it as a profiler extension though is that i lose the normal profiler for dev purpose (as it replace the profiler) but then the number of queries seems to be accurate...

here is the method invoked :

Code:
function _compile_queries() {
        $nbqueries = count($this->CI->db->queries);
        $output = '<li class="sql">'.$nbqueries.' queries</li>';
        return $output;
    }

** Update ** i tried a couple of methods... and it only returns the number of queries run in the constructor of my controller and not during a method is parsed... as i am using templates i have to append manually the footer to each submethods of my controller... which is counter efficient Confused...

I use a main template, the methods in my controller only call the model to retrieve/parse the data and the method output the global template, this way i partially build the template from the controller (all pages besides the content have the same layout). It avoids duplication of calls to $this->parser to generate header/body/footer...

But because i do so, the number of queries are off as only what's in the controller get accounted.

#2
[eluser]pickupman[/eluser]
What happens if you put in the controller constructor?
Code:
$this->output->enable_profiler(TRUE);

#3
[eluser]Kenshiro[/eluser]
the profiler gives the right results (this is the second picture on the right showing 9 queries (the correct number) )

there is one work around i found... but really it's not so good :

using the php5 __destruct to compile the whole template and output it... problem is i have to use $this->output->get_output(); method... and if the profiler is enabled it appears twice ...

There is no easy solution... if i do a custom output class maybe... to hack the profiler and allow the output to use both a miniprofiler and the normal CI one...

#4
[eluser]pickupman[/eluser]
The CI profiler access the DB information in system/libraries/Profiler.php at line 103. You could either duplicate this code to the format you need, or extend the Profiler class and add a method to output the number of queries as a string.

#5
[eluser]Kenshiro[/eluser]
This is actually what i did, same result, the problem is just that when i invoke my profiler it's always before any controller is called, thus anything after that won't work...

But well i will do it with a custom MY_Output and MY_profiler

#6
[eluser]Kenshiro[/eluser]
OK a mod can mark this as solved, i made a custom MY_Output and MY_Profiler, anytime there is a {mini_profiler} in a view or template and that $this->output->enableminiprofiler(TRUE); is set to true.. the mini profiler will be displayed.

Thanks anyway for trying to help Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.