Skip to content

Commit

Permalink
Add some profiler sections
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 authored Nov 28, 2024
1 parent 23825d0 commit 7e5c35a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 9 deletions.
13 changes: 4 additions & 9 deletions js/src/vue/Debug/Widget/ProfilerTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
twig: '#64ad52',
plugins: '#a077a6',
search: '#b6803d',
boot: '#a24e55',
};
let bg_color = '';
if (predefined_colors[category] !== undefined) {
bg_color = predefined_colors[category];
Expand All @@ -52,13 +54,8 @@
bg_color = color;
}
const contrasting_color = tinycolor.mostReadable(bg_color, tinycolor(bg_color).monochromatic(), {
includeFallbackColors: true
}).toHexString();
return {
bg_color: bg_color,
text_color: contrasting_color
};
}
Expand All @@ -83,7 +80,6 @@
name: escapeMarkupText(section.name),
category: escapeMarkupText(section.category),
bg_color: cat_colors.bg_color,
text_color: cat_colors.text_color,
start: section.start,
end: section.end,
duration: duration,
Expand Down Expand Up @@ -132,7 +128,7 @@
<tr :data-profiler-section-id="section.id" v-show="!props.hide_instant_sections || (section.duration > instant_threshold)">
<td class="nesting-spacer" v-for="i in nest_level" :key="i" aria-hidden="true"></td>
<td data-prop="category">
<span class="category-badge fw-bold" :style="`background-color: ${section.bg_color}; color: ${section.text_color}`">
<span class="category-badge badge badge-outline fw-bold border-2" :style="`border-color: ${section.bg_color};`">
{{ section.category }}
</span>
</td>
Expand All @@ -158,7 +154,6 @@
min-width: 2rem;
}
.category-badge {
padding: 5px;
border-radius: 25%;
color: var(--tblr-body-color);
}
</style>
3 changes: 3 additions & 0 deletions src/Glpi/Asset/AssetDefinitionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Glpi\Asset\CustomFieldType\TypeInterface;
use Glpi\CustomObject\AbstractDefinition;
use Glpi\CustomObject\AbstractDefinitionManager;
use Glpi\Debug\Profiler;
use Item_Problem;
use Item_Ticket;
use ReflectionClass;
Expand Down Expand Up @@ -206,7 +207,9 @@ protected function boostrapConcreteClass(AbstractDefinition $definition): void
// Bootstrap capacities
foreach ($capacities as $capacity) {
if ($definition->hasCapacityEnabled($capacity)) {
Profiler::getInstance()->start('Bootstrap ' . $capacity::class . ' on ' . $asset_class_name, Profiler::CATEGORY_CUSTOMOBJECTS);
$capacity->onClassBootstrap($asset_class_name);
Profiler::getInstance()->stop('Bootstrap ' . $capacity::class . ' on ' . $asset_class_name);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Glpi/Config/LegacyConfigurators/CleanPHPSelfParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@
use Glpi\Config\ConfigProviderHasRequestTrait;
use Glpi\Config\ConfigProviderWithRequestInterface;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profiler;

final class CleanPHPSelfParam implements LegacyConfigProviderInterface, ConfigProviderWithRequestInterface
{
use ConfigProviderHasRequestTrait;

public function execute(): void
{
Profiler::getInstance()->start('CleanPHPSelfParam::execute', Profiler::CATEGORY_BOOT);
// Security of PHP_SELF
$self = \Html::cleanParametersURL($this->getRequest()->server->get('PHP_SELF'));

$_SERVER['PHP_SELF'] = $self;
$this->getRequest()->server->set('PHP_SELF', $self);
Profiler::getInstance()->stop('CleanPHPSelfParam::execute');
}
}
3 changes: 3 additions & 0 deletions src/Glpi/Config/LegacyConfigurators/ConfigRest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
namespace Glpi\Config\LegacyConfigurators;

use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profiler;
use Session;

final readonly class ConfigRest implements LegacyConfigProviderInterface
Expand All @@ -58,6 +59,7 @@ public function execute(): void
$HEADER_LOADED = false;
$FOOTER_LOADED = false;

Profiler::getInstance()->start('ConfigRest::execute', Profiler::CATEGORY_BOOT);
// Security : check CSRF token
if (!isAPI() && count($_POST) > 0) {
if (preg_match(':' . $CFG_GLPI['root_doc'] . '(/(plugins|marketplace)/[^/]*|)/ajax/:', $_SERVER['REQUEST_URI']) === 1) {
Expand Down Expand Up @@ -103,5 +105,6 @@ public function execute(): void
) {
Session::loadGroups();
}
Profiler::getInstance()->stop('ConfigRest::execute');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use DBConnection;
use Glpi\Asset\AssetDefinitionManager;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profiler;
use Glpi\Dropdown\DropdownDefinitionManager;

final readonly class CustomObjectsAutoloader implements LegacyConfigProviderInterface
Expand All @@ -48,7 +49,9 @@ public function execute(): void
return;
}

Profiler::getInstance()->start('CustomObjectsAutoloader::execute', Profiler::CATEGORY_BOOT);
AssetDefinitionManager::getInstance()->registerAutoload();
DropdownDefinitionManager::getInstance()->registerAutoload();
Profiler::getInstance()->stop('CustomObjectsAutoloader::execute');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use DBConnection;
use Glpi\Asset\AssetDefinitionManager;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profiler;
use Glpi\Dropdown\DropdownDefinitionManager;

final readonly class CustomObjectsBootstrap implements LegacyConfigProviderInterface
Expand All @@ -48,7 +49,9 @@ public function execute(): void
return;
}

Profiler::getInstance()->start('CustomObjectsBootstrap::execute', Profiler::CATEGORY_BOOT);
AssetDefinitionManager::getInstance()->bootstrapClasses();
DropdownDefinitionManager::getInstance()->bootstrapClasses();
Profiler::getInstance()->stop('CustomObjectsBootstrap::execute');
}
}
3 changes: 3 additions & 0 deletions src/Glpi/Config/LegacyConfigurators/InitializePlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
namespace Glpi\Config\LegacyConfigurators;

use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profiler;
use Glpi\DependencyInjection\PluginContainer;
use Plugin;
use Update;
Expand All @@ -55,9 +56,11 @@ public function execute(): void
return;
}

Profiler::getInstance()->start('InitializePlugins::execute', Profiler::CATEGORY_BOOT);
$plugin = new Plugin();
$plugin->init(true);

$this->pluginContainer->initializeContainer();
Profiler::getInstance()->stop('InitializePlugins::execute');
}
}
3 changes: 3 additions & 0 deletions src/Glpi/Config/LegacyConfigurators/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Glpi\Config\ConfigProviderWithRequestInterface;
use Glpi\Config\LegacyConfigProviderInterface;
use Glpi\Debug\Profile;
use Glpi\Debug\Profiler;
use Glpi\Toolbox\URL;
use Session;

Expand All @@ -47,6 +48,7 @@ final class SessionConfig implements LegacyConfigProviderInterface, ConfigProvid

public function execute(): void
{
Profiler::getInstance()->start('SessionConfig::execute', Profiler::CATEGORY_BOOT);
if (
isset($_SESSION['glpi_use_mode'])
&& ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE)
Expand Down Expand Up @@ -77,5 +79,6 @@ public function execute(): void
if (isset($_REQUEST['glpilist_limit'])) {
$_SESSION['glpilist_limit'] = $_REQUEST['glpilist_limit'];
}
Profiler::getInstance()->stop('SessionConfig::execute');
}
}
2 changes: 2 additions & 0 deletions src/Glpi/Debug/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ final class Profiler

private $disabled = false;

public const CATEGORY_BOOT = 'boot';
public const CATEGORY_CORE = 'core';
public const CATEGORY_PLUGINS = 'plugins';
public const CATEGORY_DB = 'db';
public const CATEGORY_TWIG = 'twig';
public const CATEGORY_SEARCH = 'search';
public const CATEGORY_CUSTOMOBJECTS = 'customobjects';

private static $instance;

Expand Down

0 comments on commit 7e5c35a

Please sign in to comment.