From 3757937660cd0a8cf11f1a192827f97cca5103f4 Mon Sep 17 00:00:00 2001 From: Cerdic <cedric@yterium.com> Date: Thu, 4 Apr 2024 11:08:30 +0200 Subject: [PATCH] feat: avoir le nombre d'appel d'un squelette et le temps de calcul total dans le debugeur --- ecrire/lang/spip_fr.php | 2 ++ ecrire/public/debusquer.php | 27 +++++++++++++++++++++++---- ecrire/public/parametrer.php | 4 +++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ecrire/lang/spip_fr.php b/ecrire/lang/spip_fr.php index d6b214022c..00a60693c9 100644 --- a/ecrire/lang/spip_fr.php +++ b/ecrire/lang/spip_fr.php @@ -732,6 +732,8 @@ et vous reconnecter au site. 'zbug_pagination_sans_critere' => 'Balise #PAGINATION sans critère {pagination} ou employé dans une boucle récursive', 'zbug_parametres_inclus_incorrects' => 'Paramètre d’inclusion incorrect : @param@', 'zbug_profile' => 'Temps de calcul : @time@', + 'zbug_profile_total' => 'Temps total : @time@', + 'zbug_profile_nb' => 'Nb calcul : @nb@', 'zbug_resultat' => 'résultat', 'zbug_serveur_indefini' => 'Serveur SQL indéfini', 'zbug_statistiques' => 'Statistiques des requêtes SQL classées par durée', diff --git a/ecrire/public/debusquer.php b/ecrire/public/debusquer.php index cbbc849ebd..f42d6d6362 100644 --- a/ecrire/public/debusquer.php +++ b/ecrire/public/debusquer.php @@ -677,6 +677,17 @@ function count_occ($regs) { return $encore; } +function debusquer_format_millisecondes($t) { + if ($t < 1000) { + $s = ''; + } else { + $s = sprintf('%d ', $x = floor($t / 1000)); + $t -= ($x * 1000); + } + + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $t); +} + function debusquer_navigation_squelettes($self) { $res = ''; @@ -686,10 +697,18 @@ function debusquer_navigation_squelettes($self) { foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { $self2 = parametre_url($self, 'var_mode_objet', $nom); $nav = $boucles ? debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile) : ''; - $temps = isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? _T( - 'zbug_profile', - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] - ) : ''; + $temps = ''; + if (!empty($GLOBALS['debug_objets']['profile'][$sourcefile])) { + $t = debusquer_format_millisecondes($GLOBALS['debug_objets']['profile'][$sourcefile]); + $temps = _T('zbug_profile', ['time' => $t]); + if (!empty($GLOBALS['debug_objets']['profile_nb'][$sourcefile])) { + $temps .= ' | ' . _T('zbug_profile_nb', ['nb' => $GLOBALS['debug_objets']['profile_nb'][$sourcefile]]); + } + if (!empty($GLOBALS['debug_objets']['profile_total'][$sourcefile])) { + $t = debusquer_format_millisecondes($GLOBALS['debug_objets']['profile_total'][$sourcefile]); + $temps .= ' | ' . _T('zbug_profile_total', ['time' => $t]); + } + } $res .= "<fieldset id='f_" . $nom . "'><legend>" . $t_skel diff --git a/ecrire/public/parametrer.php b/ecrire/public/parametrer.php index 38b8b1f41b..61b6856e9a 100644 --- a/ecrire/public/parametrer.php +++ b/ecrire/public/parametrer.php @@ -141,7 +141,7 @@ function public_parametrer_dist($fond, $contexte = '', $cache = '', string $conn // spip_log: un joli contexte $infos = presenter_contexte(array_filter($contexte)); - $profile = spip_timer($a); + $profile = spip_timer($a, true); spip_logger()->info("calcul ($profile) [$skel] $infos" . ' (' . strlen((string) $page['texte']) . ' octets)'); @@ -156,6 +156,8 @@ function public_parametrer_dist($fond, $contexte = '', $cache = '', string $conn $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; $GLOBALS['debug_objets']['courant'] = $courant; $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; + $GLOBALS['debug_objets']['profile_total'][$sourcefile] = ($GLOBALS['debug_objets']['profile_total'][$sourcefile] ?? 0) + $profile; + $GLOBALS['debug_objets']['profile_nb'][$sourcefile] = ($GLOBALS['debug_objets']['profile_nb'][$sourcefile] ?? 0) + 1; if ( $GLOBALS['debug_objets']['sourcefile'] && _request('var_mode_objet') == $fonc -- GitLab