Skip to content

Improve quality of event performance tracking #42

@LukeTowers

Description

@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));
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: AcceptedEnhancement that has been approved in theory.Type: EnhancementProposed enhancement that has been accepted / implementedhelp wantedMakes the issue / PR show up in GitHub's list of Help Wanted issues / PRs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions