New file |
0,0 → 1,152 |
<?php |
// declare(encoding='UTF-8'); |
/** Classe Chronometre() - Permet de stocker et d'afficher |
* les temps d'éxécution de script. |
* |
* Cette classe permet de réaliser un ensemble |
* de mesure de temps prises à |
* différents endroits d'un script. |
* Ces mesures peuvent ensuite être affichées au |
* sein d'un tableau XHTML. |
* |
* |
* PHP Version 5 |
* |
* @category PHP |
* @package Framework |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* @copyright 2009 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version Release: <package_version> |
* @link /doc/framework/ |
*/ |
class Chronometre { |
/*** Attributs : ***/ |
private $_temps = array(); |
|
/** Constructeur : **/ |
public function __construct() { |
$this->setTemps(array('depart' => microtime())); |
} |
|
/** Accesseurs : |
* |
* @param string $cle la cle associée à un chronomètre particulier |
* |
* @return int le temps écoulé |
*/ |
public function getTemps($cle = null) { |
$temps = ''; |
if (!is_null($cle)) { |
$temps = $this->_temps[$cle]; |
} else { |
$temps = $this->_temps; |
} |
return $temps; |
} |
|
/** Setteur pour la variable temps |
* |
* @param array() $moment ajoute des points de chronométrage au tableau _temps |
* |
* @return null |
*/ |
public function setTemps($moment = array ()) { |
array_push($this->_temps, $moment); |
} |
|
/*** Méthodes : ***/ |
|
/** Méthode afficherChrono() - |
* Permet d'afficher les temps d'éxécution de différentes parties d'un script. |
* |
* Cette fonction permet d'afficher un ensemble de |
* mesure de temps prises à différents endroits d'un script. |
* Ces mesures sont affichées au sein d'un tableau XHTML |
* dont on peut controler l'indentation des balises. |
* Pour un site en production, il suffit d'ajouter un style |
* #chrono {display:none;} dans la css. De cette façon, |
* le tableau ne s'affichera pas. Le webmaster lui pourra |
* rajouter sa propre feuille de style affichant le tableau. |
* Le développeur initial de cette fonction est Loic d'Anterroches. |
* Elle a été modifiée par Jean-Pascal Milcent. |
* Elle utilise une variable gobale : $_CHRONO_ |
* |
* @author Loic d'Anterroches |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
* |
* @param int $indentation_origine l'indentation de base. |
* @param int $indentation le pas d'indentation. |
* @return string la chaine XHTML de mesure des temps. |
*/ |
public function afficherChrono($indentation_origine = 8, $indentation = 4) { |
// Création du chrono de fin |
$GLOBALS['_SCRIPT_']['chrono']->setTemps(array ( |
'fin' => microtime() |
)); |
|
// Début création de l'affichage |
$sortie = str_repeat(' ', $indentation_origine) . |
'<table id="chrono" lang="fr" summary="Résultat du |
chronométrage du programme affichant la page actuelle.">' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'<caption>Chronométrage</caption>' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'<thead>' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) . |
'<tr><th>Action</th><th>Temps écoulé (en s.)</th> |
<th>Cumul du temps écoulé (en s.)</th></tr>' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'</thead>' . "\n"; |
|
$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'<tbody>' . "\n"; |
|
$total_tps_ecoule = 0; |
|
// Récupération de la premiére mesure |
$tab_depart = & $this->getTemps(0); |
list ($usec, $sec) = explode(' ', $tab_depart['depart']); |
|
// Ce temps correspond à tps_fin |
$tps_debut = ((float) $usec + (float) $sec); |
|
foreach ($this->getTemps() as $tab_temps) { |
foreach ($tab_temps as $cle => $valeur) { |
list ($usec, $sec) = explode(' ', $valeur); |
$tps_fin = ((float) $usec + (float) $sec); |
|
$tps_ecoule = abs($tps_fin - $tps_debut); |
$total_tps_ecoule += $tps_ecoule; |
|
$tbody .= str_repeat(' ', |
($indentation_origine + ($indentation * 2))) . |
'<tr>' . |
'<th>' . $cle . '</th>' . |
'<td>' . number_format($tps_ecoule, 3, ',', ' ') . '</td>' . |
'<td>' . number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' . |
'</tr>' . "\n"; |
$tps_debut = $tps_fin; |
} |
} |
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'</tbody>' . "\n"; |
|
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'<tfoot>' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) . |
'<tr>' . |
'<th>' . 'Total du temps écoulé (en s.)' . '</th>' . |
'<td colspan="2">' . |
number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' . |
'</tr>' . "\n"; |
$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) . |
'</tfoot>' . "\n"; |
$sortie .= $tbody; |
$sortie .= str_repeat(' ', $indentation_origine) . |
'</table>' . "\n"; |
|
return $sortie; |
} |
} |
?> |
Property changes: |
Added: svn:eol-style |
+native |
\ No newline at end of property |