Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Custom benchmark/miniprofiler

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 :

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.

What happens if you put in the controller constructor?

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...

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.

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

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

Theme © iAndrew 2016 - Forum software by © MyBB