Skip to content

Commit 1b50c01

Browse files
committed
Bring back view measuring
1 parent 0a924d9 commit 1b50c01

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/DataCollector/CacheCollector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ public function onCacheEvent($event)
5555
$class = get_class($event);
5656
$params = get_object_vars($event);
5757
$label = $this->classMap[$class][0];
58-
$endTime = microtime(true);
59-
$startHashKey = $this->getEventHash($this->classMap[$class][1] ?? '', $params);
60-
$startTime = $this->eventStarts[$startHashKey] ?? $endTime;
6158

6259
if (isset($params['value'])) {
6360
$params['memoryUsage'] = strlen(serialize($params['value'])) * 8;
@@ -82,7 +79,10 @@ public function onCacheEvent($event)
8279
]);
8380
}
8481

85-
$this->addMeasure($label . "\t" . ($params['key'] ?? ''), $startTime, $endTime, $params);
82+
$time = microtime(true);
83+
$startHashKey = $this->getEventHash($this->classMap[$class][1] ?? '', $params);
84+
$startTime = $this->eventStarts[$startHashKey] ?? $time;
85+
$this->addMeasure($label . "\t" . ($params['key'] ?? ''), $startTime, $time, $params);
8686
}
8787

8888
public function onStartCacheEvent($event)

src/DebugbarViewEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function get($path, array $data = [])
5959

6060
return $this->laravelDebugbar->measure($shortPath, function () use ($path, $data) {
6161
return $this->engine->get($path, $data);
62-
}, 'views');
62+
}, 'views', 'Views Rendering');
6363
}
6464

6565
/**

src/LaravelDebugbar.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,7 @@ function () use ($startTime) {
289289
$collectData = $config->get('debugbar.options.views.data', true);
290290
$excludePaths = $config->get('debugbar.options.views.exclude_paths', []);
291291
$group = $config->get('debugbar.options.views.group', true);
292-
if ($this->hasCollector('time') && $config->get('debugbar.options.views.timeline', false)) {
293-
$timeCollector = $this['time'];
294-
} else {
295-
$timeCollector = null;
296-
}
297-
$this->addCollector(new ViewCollector($collectData, $excludePaths, $group, $timeCollector));
292+
$this->addCollector(new ViewCollector($collectData, $excludePaths, $group));
298293
$events->listen(
299294
'composing:*',
300295
function ($event, $params) {

src/ServiceProvider.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,42 @@ function ($app) {
4848
}
4949
);
5050

51+
$this->app->extend(
52+
'view',
53+
function (Factory $factory, Container $application): Factory {
54+
$laravelDebugbar = $application->make(LaravelDebugbar::class);
55+
56+
$shouldTrackViewTime = $laravelDebugbar->isEnabled() &&
57+
$laravelDebugbar->shouldCollect('time', true) &&
58+
$laravelDebugbar->shouldCollect('views', true) &&
59+
$application['config']->get('debugbar.options.views.timeline', false);
60+
61+
if (! $shouldTrackViewTime) {
62+
/* Do not swap the engine to save performance */
63+
return $factory;
64+
}
65+
66+
$extensions = array_reverse($factory->getExtensions());
67+
$engines = array_flip($extensions);
68+
$enginesResolver = $application->make('view.engine.resolver');
69+
70+
foreach ($engines as $engine => $extension) {
71+
$resolved = $enginesResolver->resolve($engine);
72+
73+
$factory->addExtension($extension, $engine, function () use ($resolved, $laravelDebugbar) {
74+
return new DebugbarViewEngine($resolved, $laravelDebugbar);
75+
});
76+
}
77+
78+
// returns original order of extensions
79+
foreach ($extensions as $extension => $engine) {
80+
$factory->addExtension($extension, $engine);
81+
}
82+
83+
return $factory;
84+
}
85+
);
86+
5187
Collection::macro('debug', function () {
5288
debug($this);
5389
return $this;

0 commit comments

Comments
 (0)