Subversion Repositories Applications.framework

Compare Revisions

Ignore whitespace Rev 238 → Rev 239

/trunk/framework/Chronometre.php
11,19 → 11,14
* @copyright Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
* @version SVN : $Id$
* @version $Id$
* @link /doc/framework/
*/
class Chronometre {
/*** Attributs : ***/
private static $instance = null;
private static $pointArretNumero = 1;
private static $temps = array();
 
/** Constructeur : **/
private function __construct() {
self::setTemps('depart', microtime());
}
 
/** Accesseurs :
*
* @param string $cle la cle associée à un chronomètre particulier
31,12 → 26,7
* @return int le temps écoulé
*/
private static function getTemps($cle = null) {
$temps = '';
if (!is_null($cle)) {
$temps = self::$temps[$cle];
} else {
$temps = self::$temps;
}
$temps = (is_null($cle)) ? self::$temps : self::$temps[$cle];
return $temps;
}
 
53,14 → 43,16
/*** Méthodes : ***/
/**
* Effectue un chronometrage.
* Effectue un chronometrage.
* Vous pouvez indiquer le nom du point de chronométrage.
* Si vous n'indiquez rien, un nombre sera généré en débutant à 1.
*
* @param string le nom du point de chronométrage
* @return null
*/
public static function chrono($cle) {
public static function chrono($cle = null) {
$cle = ($cle == null) ? self::$pointArretNumero++ : $cle;
$moment = microtime();
self::verifierCreationInstance();
self::setTemps($cle, $moment);
}
75,37 → 67,16
* Le développeur initial de cette fonction est Loic d'Anterroches.
* Elle a été modifiée par Jean-Pascal Milcent.
*
* @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.
* @author Loic d'Anterroches
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @param string l'eventuel nom du point de chronométrage de fin.
* @return string la chaine XHTML de mesure des temps.
*/
public static function afficherChrono($indentation_origine = 8, $indentation = 4) {
self::verifierCreationInstance();
public static function afficherChrono($cle = null) {
// Création du chrono de fin
self::setTemps('fin', microtime());
self::chrono();
 
// 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 = self::getTemps(0);
list ($usec, $sec) = explode(' ', $tab_depart['depart']);
112,7 → 83,8
 
// Ce temps correspond à tps_fin
$tps_debut = ((float) $usec + (float) $sec);
 
$tbody = '';
foreach (self::getTemps() as $tab_temps) {
foreach ($tab_temps as $cle => $valeur) {
list ($usec, $sec) = explode(' ', $valeur);
120,44 → 92,30
 
$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;
// Gestion affichage
$total_tps_ecoule_fmt = number_format($total_tps_ecoule, 3, ',', ' ');
$tps_ecoule_fmt = number_format($tps_ecoule, 3, ',', ' ');
$tbody .= '<tr><th>'.$cle.'</th><td>'.$tps_ecoule_fmt.'</td><td>'.$total_tps_ecoule_fmt.'</td></tr>'."\n";
}
}
$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
'</tbody>' . "\n";
$total_tps_ecoule_final_fmt = number_format($total_tps_ecoule, 3, ',', ' ');
// Début création de l'affichage
$sortie = '<table id="chrono" lang="fr" summary="Résultat duchronométrage du programme affichant la page actuelle.">'."\n".
'<caption>Chronométrage</caption>'."\n".
'<thead>'."\n".
' <tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n".
'</thead>'."\n".
'<tbody>'."\n".
$tbody.
'</tbody>'."\n".
'<tfoot>'."\n".
' <tr><th>Total du temps écoulé (en s.)</th><td colspan="2">'.$total_tps_ecoule_final_fmt.'</td></tr>'."\n".
'</tfoot>'."\n".
'</table>'."\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;
}
/**
* Vérifie si l'instance de classe à été crée, si non la créer
*/
private static function verifierCreationInstance() {
if (empty(self::$instance)) {
self::$instance = new Chronometre();
}
}
}
?>