Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve quality of event performance tracking #8

Open
bennothommo opened this issue Aug 5, 2021 · 0 comments
Open

Improve quality of event performance tracking #8

bennothommo opened this issue Aug 5, 2021 · 0 comments

Comments

@bennothommo
Copy link
Member

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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant