<p>I'm trying to debug why certain pages on a site are slow using the 'Profiling Summary Report' data that is logged to the console when devMode is enabled.</p>

<p>For easy viewing, I've tried to output the values in a flash message on the front end of the site using the following code, placed in the <code>init()</code> function of a plugin:</p>

<pre><code>if ( craft()-&gt;config-&gt;get( 'devMode' ) &amp;&amp; craft()-&gt;request-&gt;isSiteRequest() )
{
  $debugInfo = 'Time: ' . sprintf( '%0.5f', Craft::getLogger()-&gt;getExecutionTime() ) . 's' . "\n";
  $debugInfo .= ' — ' . 'Memory: ' . number_format( Craft::getLogger()-&gt;getMemoryUsage() / 1024 ) . 'Kb';
  $debugInfo .= ' — ' . 'Queries: ' . count( Craft::getLogger()-&gt;getLogs( '', 'system.db.CDbCommand' ) );
  craft()-&gt;userSession-&gt;setFlash( 'debug', $debugInfo );
}
</code></pre>

<p>They successfully log values (that look correct for seconds, kb's and query counts) but they are different to what is displayed in the console.</p>

<p><strong>Update</strong>: These are the values from 4 different page loads. I have a suspicion that these are referring to a different process, not the current page, as they're too consistent.</p>

<pre><code>Time: 0.14093s — Memory: 12,458Kb — Queries: 5
Time: 0.14069s — Memory: 12,217Kb — Queries: 5
Time: 0.13179s — Memory: 12,218Kb — Queries: 5
Time: 0.13125s — Memory: 12,218Kb — Queries: 5
</code></pre>

<p>Does anybody know why this might be? I had a feeling it was logging the values of a different process to the console. Is <code>getLogger()</code> relative to where it's called?</p>

CC BY-SA 3.0
2016-06-29T17:08:02.593Z
How are you retrieving the flash data on the front-end?  My first guess is that the data you're flashing on the front-end is info for the _previous_ request, whereas what's displayed in the browser console is info for the _current_ request.
Brad Bell
CC BY-SA 3.0
2016-06-29T17:11:43.983Z
I'm using a simple `{{ craft.session.getFlash('debug') }}` currently. I'll update my question with some more info on the values.
Luke Pearce
CC BY-SA 3.0
2016-06-29T17:35:12.260Z
I think your conclusion is right, I'm just not 100% sure why... `getLogger()` is relative to the current request, so if you call it over an AJAX request, it will return a new instance with different logging info.
Brad Bell
<devmode><debugging><logging>
Showing Profiling Summary Report data in the frontend
# Showing Profiling Summary Report data in the frontend

(Asked by: username_0 on 2016-06-29)

I'm trying to debug why certain pages on a site are slow using the 'Profiling Summary Report' data that is logged to the console when devMode is enabled.
For easy viewing, I've tried to output the values in a flash message on the front end of the site using the following code, placed in the init() function of a plugin:
if ( craft()->config->get( 'devMode' ) && craft()->request->isSiteRequest() )
{
  $debugInfo = 'Time: ' . sprintf( '%0.5f', Craft::getLogger()->getExecutionTime() ) . 's' . "\n";
  $debugInfo .= ' — ' . 'Memory: ' . number_format( Craft::getLogger()->getMemoryUsage() / 1024 ) . 'Kb';
  $debugInfo .= ' — ' . 'Queries: ' . count( Craft::getLogger()->getLogs( '', 'system.db.CDbCommand' ) );
  craft()->userSession->setFlash( 'debug', $debugInfo );
}

They successfully log values (that look correct for seconds, kb's and query counts) but they are different to what is displayed in the console.
Update: These are the values from 4 different page loads. I have a suspicion that these are referring to a different process, not the current page, as they're too consistent.
Time: 0.14093s — Memory: 12,458Kb — Queries: 5
Time: 0.14069s — Memory: 12,217Kb — Queries: 5
Time: 0.13179s — Memory: 12,218Kb — Queries: 5
Time: 0.13125s — Memory: 12,218Kb — Queries: 5

Does anybody know why this might be? I had a feeling it was logging the values of a different process to the console. Is getLogger() relative to where it's called?

**Tags:** devmode, debugging, logging
> **Comments:**
> **username_1**: How are you retrieving the flash data on the front-end?  My first guess is that the data you're flashing on the front-end is info for the _previous_ request, whereas what's displayed in the browser console is info for the _current_ request.  
> **username_0**: I'm using a simple `{{ craft.session.getFlash('debug') }}` currently. I'll update my question with some more info on the values.  
> **username_1**: I think your conclusion is right, I'm just not 100% sure why... `getLogger()` is relative to the current request, so if you call it over an AJAX request, it will return a new instance with different logging info.  

---

## 0 answers

