Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Profiling
#1

[eluser]julietteculver[/eluser]
Hi there,

I'd like to be able to get a list of the database queries run for any page of my site along with how long each one took to run.

I've enabled Profiler for all my controllers, but looking at the Profiler/Benchmarking documentation, I need to manually set benchmarks before and after each query and then display the data afterwards. If I do this for the whole site, this is obviously going to take painfully long.

Are there any short cuts here?

Thanks,
Juliette
#2

[eluser]mddd[/eluser]
I guess it would not be too hard to adapt the database class to automatically start a benchmark before running a query, and stopping it after the query is done. That way, benchmarking would be automatic.
#3

[eluser]WanWizard[/eluser]
Eh, isn't that standard in the profiler ouput?
#4

[eluser]danmontgomery[/eluser]
[quote author="WanWizard" date="1276206350"]Eh, isn't that standard in the profiler ouput?[/quote]

Yep
#5

[eluser]mddd[/eluser]
Okay, that shows how long I haven't used the profiler.
It does leave me puzzled as to why julietteculver is asking the question.. if she's using the profiler, what is her question exactly?
#6

[eluser]WanWizard[/eluser]
I wonder? Might have something to do with the fact that CI doesn't log 'simple' queries, only AR queries, so the profiler output is incomplete.

I have moved the logging code in DB_Driver.php from the query() to the simple_query() method, to make sure I capture all queries.
#7

[eluser]julietteculver[/eluser]
I must admit I was a bit puzzled because when I googled these forums for things related to profiling, I got the impression that profiler would do what I want with links to the profiler documentation saying that profiler documentation was very thorough. However the profiler documentation is actually very slim http://ellislab.com/codeigniter/user-gui...iling.html

I wasn't getting any output from the profiler at all - have I set it up wrong? I can benchmark parts of the code and get the expired time fine.

So I was half-wondering if some of the documentation was missing or I was being blind and just hadn't found it!
#8

[eluser]WanWizard[/eluser]
That's odd, because the profiler is an all-or-nothing kinda thing. If enabled, it outputs all it has.
So if you see the code benchmarks, but not the database one's you might have run into the database selection bug.

The profiler library uses:
Code:
foreach (get_object_vars($this->CI) as $CI_object)
{
    if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
    {
        $dbs[] = $CI_object;
    }
}

I had to change that to this to get it to work on all my staging environments:
Code:
foreach (get_object_vars($this->CI) as $CI_object)
{
    if ( strtolower(get_parent_class($CI_object)) == 'ci_db' )
    {
        $dbs[] = $CI_object;
    }
}
You can check our demo site to see what it could look like...
#9

[eluser]julietteculver[/eluser]
Thanks, WanWizard - it's useful to know that it is at least meant to display the type of output I want!

Changed those lines, but don't see anything - where does the Profiler output appear? Maybe I've just not been looking in the right place for it all this time anyway?
#10

[eluser]WanWizard[/eluser]
If the profiler is enabled, the output is automatically generated by the output library, where it is appended to the output of your views. So it always appears at the bottom of the page.

Note that I use an extended version of the profiler library, so not all sections visible on our demo site are available when you use the standard library.




Theme © iAndrew 2016 - Forum software by © MyBB