Adjusted from returning raw Stopwatch event objects from providers.
This commit is contained in:
1 parent
c93249875b
commit
31b80d0413
3 files changed
+44
-7
No files matched your search
@@ -7,6 +7,7 @@ use Pimple\ServiceProviderInterface;
|
|||||||
use Rarst\Laps\Bootable_Provider_Interface;
|
use Rarst\Laps\Bootable_Provider_Interface;
|
||||||
use Rarst\Laps\Laps;
|
use Rarst\Laps\Laps;
|
||||||
use Symfony\Component\Stopwatch\Stopwatch;
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||||
|
|
||||||
class Hook_Events_Provider implements ServiceProviderInterface, Bootable_Provider_Interface, Events_Provider_Interface {
|
class Hook_Events_Provider implements ServiceProviderInterface, Bootable_Provider_Interface, Events_Provider_Interface {
|
||||||
|
|
||||||
@@ -100,6 +101,23 @@ class Hook_Events_Provider implements ServiceProviderInterface, Bootable_Provide
|
|||||||
|
|
||||||
public function get_events() {
|
public function get_events() {
|
||||||
|
|
||||||
return $this->stopwatch->getSectionEvents( '__root__' );
|
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
||||||
|
|
||||||
|
return array_map( [ $this, 'transform' ], array_keys( $events ), $events );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function transform( $name, StopwatchEvent $event ) {
|
||||||
|
|
||||||
|
$duration = $event->getDuration();
|
||||||
|
$memory = $event->getMemory() / 1024 / 1024;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $name,
|
||||||
|
'description' => "{$name} - {$duration} ms - {$memory} MB",
|
||||||
|
'origin' => $event->getOrigin(),
|
||||||
|
'duration' => $duration,
|
||||||
|
'memory' => $memory,
|
||||||
|
'category' => $event->getCategory(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ use Pimple\ServiceProviderInterface;
|
|||||||
use Rarst\Laps\Bootable_Provider_Interface;
|
use Rarst\Laps\Bootable_Provider_Interface;
|
||||||
use Rarst\Laps\Laps;
|
use Rarst\Laps\Laps;
|
||||||
use Symfony\Component\Stopwatch\Stopwatch;
|
use Symfony\Component\Stopwatch\Stopwatch;
|
||||||
|
use Symfony\Component\Stopwatch\StopwatchEvent;
|
||||||
|
|
||||||
class Http_Events_Provider implements ServiceProviderInterface, Bootable_Provider_Interface, Events_Provider_Interface {
|
class Http_Events_Provider implements ServiceProviderInterface, Bootable_Provider_Interface, Events_Provider_Interface {
|
||||||
|
|
||||||
@@ -61,6 +62,23 @@ class Http_Events_Provider implements ServiceProviderInterface, Bootable_Provide
|
|||||||
|
|
||||||
public function get_events() {
|
public function get_events() {
|
||||||
|
|
||||||
return $this->stopwatch->getSectionEvents( '__root__' );
|
$events = $this->stopwatch->getSectionEvents( '__root__' );
|
||||||
|
|
||||||
|
return array_map( [ $this, 'transform' ], array_keys( $events ), $events );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function transform( $name, StopwatchEvent $event ) {
|
||||||
|
|
||||||
|
$duration = $event->getDuration();
|
||||||
|
$memory = $event->getMemory() / 1024 / 1024;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $name,
|
||||||
|
'description' => $name,
|
||||||
|
'origin' => $event->getOrigin(),
|
||||||
|
'duration' => $duration,
|
||||||
|
'memory' => $memory,
|
||||||
|
'category' => $event->getCategory(),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-5
@@ -176,19 +176,20 @@ class Laps extends Container {
|
|||||||
$event_data = array();
|
$event_data = array();
|
||||||
$http_data = array();
|
$http_data = array();
|
||||||
|
|
||||||
foreach ( $events as $name => $event ) {
|
foreach ( $events as $event ) {
|
||||||
|
|
||||||
$offset = round( ( $event->getOrigin() - $start ) / $total * 100, 2 );
|
$name = $event['name'];
|
||||||
$duration = $event->getDuration();
|
$offset = round( ( $event['origin'] - $start ) / $total * 100, 2 );
|
||||||
|
$duration = $event['duration'];
|
||||||
$width = round( $duration / $total * 100, 2 );
|
$width = round( $duration / $total * 100, 2 );
|
||||||
$category = $event->getCategory();
|
$category = $event['category'];
|
||||||
|
|
||||||
if ( 'http' === $category ) {
|
if ( 'http' === $category ) {
|
||||||
$http_data[] = compact( 'name', 'offset', 'duration', 'width', 'category' );
|
$http_data[] = compact( 'name', 'offset', 'duration', 'width', 'category' );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$memory = $event->getMemory() / 1024 / 1024;
|
$memory = $event['memory'];
|
||||||
|
|
||||||
$event_data[] = compact( 'name', 'offset', 'duration', 'width', 'category', 'memory' );
|
$event_data[] = compact( 'name', 'offset', 'duration', 'width', 'category', 'memory' );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user