Skip to content

Help users start profiling #977

@szepeviktor

Description

@szepeviktor

I'd like to help users to track down culprits.

Copied from the venerable https://github.com/wp-cli/profile-command

Image

qm-profiling.php

<?php

$qm_profiling_stage_hooks = [
    'bootstrap' => [
        'muplugins_loaded',
        'plugins_loaded',
        'setup_theme',
        'after_setup_theme',
        'init',
        'wp_loaded',
    ],
    'main_query' => [
        'parse_request',
        'send_headers',
        // 'pre_get_posts',
        'the_posts',
        'wp',
    ],
    'template' => [
        'template_redirect',
        'template_include',
        'wp_head',
        'loop_start',
        'loop_end',
        'wp_footer',
    ],
];
foreach ($qm_profiling_stage_hooks as $stage => $hooks) {
    foreach ($hooks as $hook) {
        add_filter(
            $hook,
            static function ($value) use ($stage, $hook) {
                do_action('qm/start', sprintf('%s/%s', $stage, $hook));
                return $value;
            },
            PHP_INT_MIN,
            1
        );
        add_filter(
            $hook,
            static function ($value) use ($stage, $hook) {
                do_action('qm/stop', sprintf('%s/%s', $stage, $hook));
                return $value;
            },
            PHP_INT_MAX,
            1
        );
    }
}

How to go on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions