Skip to content

Missing stopwatch component gives inaccurate message in profiler #31056

@linaori

Description

@linaori

Symfony version(s) affected: 3.4+

Description
When you are missing the stopwatch component, you can't see the timings in the webdeveloper toolbar. When you navigate through the WDT via the "n/a" timings, you will arrive at a page saying: "No timing events have been recorded. Are you sure that debugging is enabled in the kernel?". While this message is a good hint, my application is running in debug, so it's only one of a few cases. Luckily I knew a missing stopwatch could cause missing timings, but I can imagine this to be very difficult to find for a developer with less Symfony experience.

How to reproduce

  1. Ensure the stopwatch component is not installed (no indirect dependencies either).
  2. Ensure your application is running in debug
  3. Load a page and verify the timing is saying "n/a":
    image
  4. Open this specific WDT link
  5. You will see the following:
    image

Possible Solution
I think the easiest solution would be to detect whether or not the stopwatch component is installed. If not, pass that information to the collected data, so we can show a different message:

public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (null !== $this->kernel) {
$startTime = $this->kernel->getStartTime();
} else {
$startTime = $request->server->get('REQUEST_TIME_FLOAT');
}
$this->data = [
'token' => $response->headers->get('X-Debug-Token'),
'start_time' => $startTime * 1000,
'events' => [],
];
}

# TimeDataCollector would look like this
use Symfony\Component\Stopwatch\Stopwatch;

$this->data = [
    'token' => $response->headers->get('X-Debug-Token'),
    'start_time' => $startTime * 1000,
    'events' => [],
    'stopwatch_installed' => class_exists(Stopwatch::class, false),
];
{% if not collector.stopwatch_installed %}
    <div class="empty">
        <p>The stopwatch component is not installed. If you want to see timing events, run <code>composer require symfony/stopwatch</code></p>.
    </div>
{% else if collector.events is empty %}
    <div class="empty">
        <p>No timing events have been recorded. Are you sure that debugging is enabled in the kernel?</p>
    </div>
{% else %}
    {{ block('panelContent') }}
{% endif %}

Additional context
Current location of the template code triggered:

{% if collector.events is empty %}
<div class="empty">
<p>No timing events have been recorded. Are you sure that debugging is enabled in the kernel?</p>
</div>
{% else %}
{{ block('panelContent') }}
{% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)StopwatchWebProfilerBundle

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions