Subversion Repositories Applications.framework

Rev

Rev 217 | Rev 241 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 217 Rev 239
Line 9... Line 9...
9
 * @package	Framework
9
 * @package	Framework
10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
11
 * @copyright	Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
12
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
12
 * @license	http://www.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
13
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 
13
 * @license	http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2 
14
 * @version	SVN : $Id: Chronometre.php 217 2010-11-10 11:32:05Z jpm $
14
 * @version	$Id: Chronometre.php 239 2010-11-25 18:04:00Z jpm $
15
 * @link		/doc/framework/
15
 * @link		/doc/framework/
16
 */
16
 */
17
class Chronometre {
17
class Chronometre {
18
	/*** Attributs : ***/
18
	/*** Attributs : ***/
19
	private static $instance = null;
19
	private static $pointArretNumero = 1;
20
	private static $temps = array();
20
	private static $temps = array();
Line 21... Line -...
21
 
-
 
22
	/** Constructeur : **/
-
 
23
	private function __construct() {
-
 
24
		self::setTemps('depart', microtime());
-
 
25
	}
-
 
26
 
21
 
27
	/** Accesseurs :
22
	/** Accesseurs :
28
	 *
23
	 *
29
	 * @param string $cle la cle associée à un chronomètre particulier
24
	 * @param string $cle la cle associée à un chronomètre particulier
30
	 *
25
	 *
31
	 * @return int le temps écoulé
26
	 * @return int le temps écoulé
32
	 */
27
	 */
33
	private static function getTemps($cle = null) {
-
 
34
		$temps = '';
-
 
35
		if (!is_null($cle)) {
28
	private static function getTemps($cle = null) {
36
			$temps = self::$temps[$cle];
-
 
37
		} else {
-
 
38
			$temps = self::$temps;
-
 
39
		}
29
		$temps = (is_null($cle)) ? self::$temps : self::$temps[$cle];
40
		return $temps;
30
		return $temps;
Line 41... Line 31...
41
	}
31
	}
42
 
32
 
Line 51... Line 41...
51
	}
41
	}
Line 52... Line 42...
52
 
42
 
Line 53... Line 43...
53
	/*** Méthodes : ***/
43
	/*** Méthodes : ***/
54
	
44
	
-
 
45
	/** 
-
 
46
	 *	Effectue un chronometrage. 
55
	/** 
47
	 * Vous pouvez indiquer le nom du point de chronométrage.
56
	 *	Effectue un chronometrage.
48
	 * Si vous n'indiquez rien, un nombre sera généré en débutant à 1.
57
	 *
49
	 *
58
	 * @param string le nom du point de chronométrage
50
	 * @param string le nom du point de chronométrage
59
	 * @return null
51
	 * @return null
-
 
52
	 */
60
	 */
53
	public static function chrono($cle = null) {
61
	public static function chrono($cle) {
-
 
62
		$moment = microtime();
54
		$cle = ($cle == null) ? self::$pointArretNumero++ : $cle;
63
		self::verifierCreationInstance();
55
		$moment = microtime();
Line 64... Line 56...
64
		self::setTemps($cle, $moment);
56
		self::setTemps($cle, $moment);
65
	}
57
	}
Line 73... Line 65...
73
	* De cette façon, le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style 
65
	* De cette façon, le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style 
74
	* affichant le tableau.
66
	* affichant le tableau.
75
	* Le développeur initial de cette fonction est Loic d'Anterroches.
67
	* Le développeur initial de cette fonction est Loic d'Anterroches.
76
	* Elle a été modifiée par Jean-Pascal Milcent.
68
	* Elle a été modifiée par Jean-Pascal Milcent.
77
	*
69
	*
78
	* @author   Loic d'Anterroches
70
	* @author Loic d'Anterroches
79
	* @author	Jean-Pascal MILCENT <jpm@tela-botanica.org>
71
	* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
80
	*
-
 
81
	* @param	int	 $indentation_origine l'indentation de base.
72
	* @param string l'eventuel nom du point de chronométrage de fin.
82
	* @param	int	 $indentation le pas d'indentation.
-
 
83
	* @return   string  la chaine XHTML de mesure des temps.
73
	* @return   string  la chaine XHTML de mesure des temps.
84
	*/
74
	*/
85
	public static function afficherChrono($indentation_origine = 8, $indentation = 4) {
75
	public static function afficherChrono($cle = null) {
86
		self::verifierCreationInstance();
-
 
87
		// Création du chrono de fin
76
		// Création du chrono de fin
88
		self::setTemps('fin', microtime());
-
 
89
 
-
 
90
		// Début création de l'affichage
-
 
91
		$sortie = str_repeat(' ', $indentation_origine) .
-
 
92
		'<table id="chrono" lang="fr" summary="Résultat du
-
 
93
			chronométrage du programme affichant la page actuelle.">' . "\n";
-
 
94
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
-
 
95
		'<caption>Chronométrage</caption>' . "\n";
-
 
96
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
-
 
97
		'<thead>' . "\n";
77
		self::chrono();
98
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) .
-
 
99
		'<tr><th>Action</th><th>Temps écoulé (en s.)</th>
-
 
100
		<th>Cumul du temps écoulé (en s.)</th></tr>' . "\n";
-
 
101
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
-
 
102
		'</thead>' . "\n";
-
 
103
 
-
 
104
		$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
-
 
105
		'<tbody>' . "\n";
-
 
Line 106... Line 78...
106
 
78
 
107
		$total_tps_ecoule = 0;
-
 
108
 
79
		$total_tps_ecoule = 0;
109
		// Récupération de la premiére mesure
80
		// Récupération de la premiére mesure
110
		$tab_depart = self::getTemps(0);
81
		$tab_depart = self::getTemps(0);
Line 111... Line 82...
111
		list ($usec, $sec) = explode(' ', $tab_depart['depart']);
82
		list ($usec, $sec) = explode(' ', $tab_depart['depart']);
112
 
83
 
113
		// Ce temps correspond à tps_fin
84
		// Ce temps correspond à tps_fin
-
 
85
		$tps_debut = ((float) $usec + (float) $sec);
114
		$tps_debut = ((float) $usec + (float) $sec);
86
		
115
 
87
		$tbody = '';
116
		foreach (self::getTemps() as $tab_temps) {
88
		foreach (self::getTemps() as $tab_temps) {
117
			foreach ($tab_temps as $cle => $valeur) {
89
			foreach ($tab_temps as $cle => $valeur) {
Line 118... Line 90...
118
				list ($usec, $sec) = explode(' ', $valeur);
90
				list ($usec, $sec) = explode(' ', $valeur);
119
				$tps_fin = ((float) $usec + (float) $sec);
91
				$tps_fin = ((float) $usec + (float) $sec);
120
 
-
 
121
				$tps_ecoule = abs($tps_fin - $tps_debut);
-
 
122
				$total_tps_ecoule += $tps_ecoule;
-
 
123
 
-
 
124
				$tbody .= str_repeat(' ',
-
 
125
								($indentation_origine + ($indentation * 2))) .
-
 
126
				'<tr>' .
-
 
127
				'<th>' . $cle . '</th>' .
-
 
128
				'<td>' . number_format($tps_ecoule, 3, ',', ' ') . '</td>' .
92
 
-
 
93
				$tps_ecoule = abs($tps_fin - $tps_debut);
-
 
94
				$total_tps_ecoule += $tps_ecoule;
-
 
95
				$tps_debut = $tps_fin;
-
 
96
				
-
 
97
				// Gestion affichage
129
				'<td>' . number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' .
98
				$total_tps_ecoule_fmt = number_format($total_tps_ecoule, 3, ',', ' ');
130
				'</tr>' . "\n";
99
				$tps_ecoule_fmt = number_format($tps_ecoule, 3, ',', ' ');
131
				$tps_debut = $tps_fin;
100
				$tbody .= '<tr><th>'.$cle.'</th><td>'.$tps_ecoule_fmt.'</td><td>'.$total_tps_ecoule_fmt.'</td></tr>'."\n";
132
			}
101
			}
133
		}
-
 
134
		$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
102
		}
-
 
103
		$total_tps_ecoule_final_fmt = number_format($total_tps_ecoule, 3, ',', ' ');
135
		'</tbody>' . "\n";
104
		// Début création de l'affichage
136
 
105
		$sortie = '<table id="chrono" lang="fr" summary="Résultat duchronométrage du programme affichant la page actuelle.">'."\n".
137
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
106
			'<caption>Chronométrage</caption>'."\n".
138
		'<tfoot>' . "\n";
107
			'<thead>'."\n".
139
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))) .
108
			'	<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n".
140
		'<tr>' .
109
			'</thead>'."\n".
141
		'<th>' . 'Total du temps écoulé (en s.)' . '</th>' .
110
			'<tbody>'."\n".
142
		'<td colspan="2">' .
111
				$tbody.
143
			number_format($total_tps_ecoule, 3, ',', ' ') . '</td>' .
112
			'</tbody>'."\n".
144
		'</tr>' . "\n";
-
 
145
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))) .
-
 
146
		'</tfoot>' . "\n";
113
			'<tfoot>'."\n".
Line 147... Line 114...
147
		$sortie .= $tbody;
114
			'	<tr><th>Total du temps écoulé (en s.)</th><td colspan="2">'.$total_tps_ecoule_final_fmt.'</td></tr>'."\n".
148
		$sortie .= str_repeat(' ', $indentation_origine) .
115
			'</tfoot>'."\n".
149
		'</table>' . "\n";
-
 
150
 
-
 
151
		return $sortie;
-
 
152
	}
-
 
153
	
-
 
154
	/**
-
 
155
	 * Vérifie si l'instance de classe à été crée, si non la créer
-
 
156
	 */
-
 
157
	private static function verifierCreationInstance() {
-
 
158
		if (empty(self::$instance)) {
116
			'</table>'."\n";
159
			self::$instance = new Chronometre();
117
 
160
		}
118
		return $sortie;