diff --git a/src/Manager/Toolbar_Manager.php b/src/Manager/Toolbar_Manager.php index 8499fd2..bc4fd52 100644 --- a/src/Manager/Toolbar_Manager.php +++ b/src/Manager/Toolbar_Manager.php @@ -37,13 +37,9 @@ class Toolbar_Manager { global $timestart; - $start = $timestart * 1000; - $end = microtime( true ) * 1000; - $total = $end - $start; - $wp_admin_bar->add_node( [ 'id' => 'laps', - 'title' => sprintf( 'Lap: %ss', round( $total / 1000, 3 ) ), + 'title' => sprintf( 'Lap: %ss', round( microtime( true ) - $timestart, 3 ) ), ] ); $wp_admin_bar->add_node( [ diff --git a/src/Provider/Record_Provider.php b/src/Provider/Record_Provider.php index 83fcca5..411619e 100644 --- a/src/Provider/Record_Provider.php +++ b/src/Provider/Record_Provider.php @@ -22,7 +22,7 @@ class Record_Provider implements ServiceProviderInterface, Bootable_Provider_Int public function register( Container $pimple ) { $pimple['stopwatch'] = $pimple->factory( function () { - return new Stopwatch(); + return new Stopwatch( true ); } ); $pimple['collectors'] = function ( Plugin $laps ) { diff --git a/src/Record/Record_Interface.php b/src/Record/Record_Interface.php index 6165554..306fb23 100644 --- a/src/Record/Record_Interface.php +++ b/src/Record/Record_Interface.php @@ -23,7 +23,7 @@ interface Record_Interface { public function get_origin(); /** - * @return int Record duration in milliseconds. + * @return float Record duration in seconds. */ public function get_duration(); diff --git a/src/Record/Sql_Record.php b/src/Record/Sql_Record.php index e80d33f..09ab78e 100644 --- a/src/Record/Sql_Record.php +++ b/src/Record/Sql_Record.php @@ -43,7 +43,8 @@ class Sql_Record implements Record_Interface { * @return string */ public function get_description() { - $duration = round( $this->duration ); + + $duration = round( $this->duration * 1000 ); // s to 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() { return $this->duration; diff --git a/src/Record/Sql_Record_Collector.php b/src/Record/Sql_Record_Collector.php index 8acb597..9597bf7 100644 --- a/src/Record/Sql_Record_Collector.php +++ b/src/Record/Sql_Record_Collector.php @@ -32,9 +32,9 @@ class Sql_Record_Collector implements Record_Collector_Interface { global $wpdb; 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 { - $this->query_starts[] = microtime( true ) * 1000; + $this->query_starts[] = microtime( true ); } return $query; @@ -63,7 +63,6 @@ class Sql_Record_Collector implements Record_Collector_Interface { $category = 'query-write'; } - $duration *= 1000; $last_query_end = $query_start + $duration; $query_data[] = new Sql_Record( $sql, $query_start, $duration, $category ); diff --git a/src/Record/Stopwatch_Record.php b/src/Record/Stopwatch_Record.php index 51ec916..d954ac9 100644 --- a/src/Record/Stopwatch_Record.php +++ b/src/Record/Stopwatch_Record.php @@ -36,7 +36,7 @@ class Stopwatch_Record implements Record_Interface { */ public function get_description() { - $duration = $this->stopwatch_event->getDuration(); + $duration = round( $this->stopwatch_event->getDuration() ); $memory = $this->stopwatch_event->getMemory() / 1024 / 1024; return "{$this->name} – {$duration} ms – {$memory} MB"; @@ -46,14 +46,14 @@ class Stopwatch_Record implements Record_Interface { * @return float Timestamp of record start. */ 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() { - return $this->stopwatch_event->getDuration(); + return $this->stopwatch_event->getDuration() / 1000; // ms to s. } /** diff --git a/src/Record/Timeline_Iterator.php b/src/Record/Timeline_Iterator.php index 3a3e1a8..1a2fee4 100644 --- a/src/Record/Timeline_Iterator.php +++ b/src/Record/Timeline_Iterator.php @@ -26,7 +26,7 @@ class Timeline_Iterator implements \Iterator { global $timestart; - $this->origin = $timestart * 1000; + $this->origin = $timestart; $this->iterator = $iterator; } @@ -71,7 +71,7 @@ class Timeline_Iterator implements \Iterator { * Rewind to a topmost record set. */ public function rewind() { - $this->total = microtime( true ) * 1000 - $this->origin; + $this->total = microtime( true ) - $this->origin; $this->current = $this->iterator; } diff --git a/tests/Record/SqlTest.php b/tests/Record/SqlTest.php index 18bebdd..f907239 100644 --- a/tests/Record/SqlTest.php +++ b/tests/Record/SqlTest.php @@ -37,7 +37,7 @@ class SqlTest extends LapsTestCase { $this->assertEquals( $query, $record->get_name() ); $this->assertContains( $query, $record->get_description() ); $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() ); } }