Normalized on operating in float seconds rather than milliseconds.
This commit is contained in:
1 parent
624e282905
commit
1e75033f25
8 files changed
+15
-19
No files matched your search
@@ -37,13 +37,9 @@ class Toolbar_Manager {
|
|||||||
|
|
||||||
global $timestart;
|
global $timestart;
|
||||||
|
|
||||||
$start = $timestart * 1000;
|
|
||||||
$end = microtime( true ) * 1000;
|
|
||||||
$total = $end - $start;
|
|
||||||
|
|
||||||
$wp_admin_bar->add_node( [
|
$wp_admin_bar->add_node( [
|
||||||
'id' => 'laps',
|
'id' => 'laps',
|
||||||
'title' => sprintf( 'Lap: %ss', round( $total / 1000, 3 ) ),
|
'title' => sprintf( 'Lap: %ss', round( microtime( true ) - $timestart, 3 ) ),
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$wp_admin_bar->add_node( [
|
$wp_admin_bar->add_node( [
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int
|
|||||||
public function register( Container $pimple ) {
|
public function register( Container $pimple ) {
|
||||||
|
|
||||||
$pimple['stopwatch'] = $pimple->factory( function () {
|
$pimple['stopwatch'] = $pimple->factory( function () {
|
||||||
return new Stopwatch();
|
return new Stopwatch( true );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$pimple['collectors'] = function ( Plugin $laps ) {
|
$pimple['collectors'] = function ( Plugin $laps ) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface Record_Interface {
|
|||||||
public function get_origin();
|
public function get_origin();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int Record duration in milliseconds.
|
* @return float Record duration in seconds.
|
||||||
*/
|
*/
|
||||||
public function get_duration();
|
public function get_duration();
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class Sql_Record implements Record_Interface {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_description() {
|
public function get_description() {
|
||||||
$duration = round( $this->duration );
|
|
||||||
|
$duration = round( $this->duration * 1000 ); // s to ms.
|
||||||
|
|
||||||
return "{$this->sql} – {$duration} ms";
|
return "{$this->sql} – {$duration} ms";
|
||||||
}
|
}
|
||||||
@@ -56,7 +57,7 @@ class Sql_Record implements Record_Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int Record duration in milliseconds.
|
* @return float Record duration in seconds.
|
||||||
*/
|
*/
|
||||||
public function get_duration() {
|
public function get_duration() {
|
||||||
return $this->duration;
|
return $this->duration;
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
|||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if ( empty( $this->query_starts ) && ! empty( $wpdb->queries ) ) {
|
if ( empty( $this->query_starts ) && ! empty( $wpdb->queries ) ) {
|
||||||
$this->query_starts[ count( $wpdb->queries ) ] = microtime( true ) * 1000;
|
$this->query_starts[ count( $wpdb->queries ) ] = microtime( true );
|
||||||
} else {
|
} else {
|
||||||
$this->query_starts[] = microtime( true ) * 1000;
|
$this->query_starts[] = microtime( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
@@ -63,7 +63,6 @@ class Sql_Record_Collector implements Record_Collector_Interface {
|
|||||||
$category = 'query-write';
|
$category = 'query-write';
|
||||||
}
|
}
|
||||||
|
|
||||||
$duration *= 1000;
|
|
||||||
$last_query_end = $query_start + $duration;
|
$last_query_end = $query_start + $duration;
|
||||||
|
|
||||||
$query_data[] = new Sql_Record( $sql, $query_start, $duration, $category );
|
$query_data[] = new Sql_Record( $sql, $query_start, $duration, $category );
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Stopwatch_Record implements Record_Interface {
|
|||||||
*/
|
*/
|
||||||
public function get_description() {
|
public function get_description() {
|
||||||
|
|
||||||
$duration = $this->stopwatch_event->getDuration();
|
$duration = round( $this->stopwatch_event->getDuration() );
|
||||||
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
|
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
|
||||||
|
|
||||||
return "{$this->name} – {$duration} ms – {$memory} MB";
|
return "{$this->name} – {$duration} ms – {$memory} MB";
|
||||||
@@ -46,14 +46,14 @@ class Stopwatch_Record implements Record_Interface {
|
|||||||
* @return float Timestamp of record start.
|
* @return float Timestamp of record start.
|
||||||
*/
|
*/
|
||||||
public function get_origin() {
|
public function get_origin() {
|
||||||
return $this->stopwatch_event->getOrigin();
|
return $this->stopwatch_event->getOrigin() / 1000; // ms to s.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int Record duration in milliseconds.
|
* @return float Record duration in seconds.
|
||||||
*/
|
*/
|
||||||
public function get_duration() {
|
public function get_duration() {
|
||||||
return $this->stopwatch_event->getDuration();
|
return $this->stopwatch_event->getDuration() / 1000; // ms to s.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Timeline_Iterator implements \Iterator {
|
|||||||
|
|
||||||
global $timestart;
|
global $timestart;
|
||||||
|
|
||||||
$this->origin = $timestart * 1000;
|
$this->origin = $timestart;
|
||||||
$this->iterator = $iterator;
|
$this->iterator = $iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ class Timeline_Iterator implements \Iterator {
|
|||||||
* Rewind to a topmost record set.
|
* Rewind to a topmost record set.
|
||||||
*/
|
*/
|
||||||
public function rewind() {
|
public function rewind() {
|
||||||
$this->total = microtime( true ) * 1000 - $this->origin;
|
$this->total = microtime( true ) - $this->origin;
|
||||||
$this->current = $this->iterator;
|
$this->current = $this->iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class SqlTest extends LapsTestCase {
|
|||||||
$this->assertEquals( $query, $record->get_name() );
|
$this->assertEquals( $query, $record->get_name() );
|
||||||
$this->assertContains( $query, $record->get_description() );
|
$this->assertContains( $query, $record->get_description() );
|
||||||
$this->assertInternalType( 'float', $record->get_origin() );
|
$this->assertInternalType( 'float', $record->get_origin() );
|
||||||
$this->assertEquals( $duration * 1000, $record->get_duration() );
|
$this->assertEquals( $duration, $record->get_duration() );
|
||||||
$this->assertEquals( 'query-read', $record->get_category() );
|
$this->assertEquals( 'query-read', $record->get_category() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user