Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save felixarntz/887aa45829709991f4ecd114ae52ed14 to your computer and use it in GitHub Desktop.
Save felixarntz/887aa45829709991f4ecd114ae52ed14 to your computer and use it in GitHub Desktop.
wp-server-timing-quick-hack-template.php (using Performance Lab Server-Timing API)
<?php
function my_func() {
global $some_metric_global;
if ( ! isset( $some_metric_global ) ) {
$some_metric_global = 0.0;
add_action(
'wp_footer',
function() {
perflab_server_timing_register_metric(
'some_metric_global',
array(
'measure_callback' => function ( $metric ) {
global $some_metric_global;
$metric->set_value( $some_metric_global * 1000.0 );
},
'access_cap' => 'exist',
)
);
}
);
}
$start = microtime( true );
// More logic...
$some_metric_global += microtime( true ) - $start;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment