Skip to content

Improve quality of event performance tracking #8

Description

@bennothommo

Remake of rainlab/debugbar-plugin#42 by @LukeTowers.

Right now performance / timing tracking on events uses the difference between when the last event was fired to when the current event was fired to say how long a given event took to process. This is obviously wildly inaccurate and unhelpful, so it would be better if we could instead implement our own event data collector that actually tracked how long a given event was taking to execute by hooking one wildcard listener as the highest priority listener (with PHP_INT_MAX) and another wildcard listener as the lowest priority listener (with PHP_INT_MIN) and then recording the timing difference between those two listeners being fired.

This would require a change being made to the October core as currently wildcard listeners don't support subscribing to events with priority, and even if they did you'd still have to ensure that they were added to the priority stream of the non-wildcard listeners correctly.

Something roughly like the following:

$events->listen('*', [$this, 'onWildcardEventStart'], PHP_INT_MAX);
    $events->listen('*', [$this, 'onWildcardEventEnd'], PHP_INT_MIN);
}

protected $timings = [];

public function onWildCardEventStart($name = null, $data = [])
{
    if (empty($name)) { return; }
    $this->timings[$name] = microtime(true);
}
public function onWildCardEventEnd($name = null, $data = [])
{
    if (empty($name)) { return; }
    $this->addMeasure($name, $this->timings[$name], microtime(true), $this->prepareParams($data));
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions