Subversion Repositories Applications.gtt

Rev

Rev 118 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 118 Rev 119
1
<?php
1
<?php
2
// +------------------------------------------------------------------------------------------------------+
2
// +------------------------------------------------------------------------------------------------------+
3
// | PHP version 5.0.4                                                                                    |
3
// | PHP version 5.0.4                                                                                    |
4
// +------------------------------------------------------------------------------------------------------+
4
// +------------------------------------------------------------------------------------------------------+
5
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org)                                         |
5
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// +------------------------------------------------------------------------------------------------------+
6
// +------------------------------------------------------------------------------------------------------+
7
// | This file is part of eFlore-Debogage.                                                                |
7
// | This file is part of eFlore-Debogage.                                                                |
8
// |                                                                                                      |
8
// |                                                                                                      |
9
// | Foobar is free software; you can redistribute it and/or modify                                       |
9
// | Foobar is free software; you can redistribute it and/or modify                                       |
10
// | it under the terms of the GNU General Public License as published by                                 |
10
// | it under the terms of the GNU General Public License as published by                                 |
11
// | the Free Software Foundation; either version 2 of the License, or                                    |
11
// | the Free Software Foundation; either version 2 of the License, or                                    |
12
// | (at your option) any later version.                                                                  |
12
// | (at your option) any later version.                                                                  |
13
// |                                                                                                      |
13
// |                                                                                                      |
14
// | Foobar is distributed in the hope that it will be useful,                                            |
14
// | Foobar is distributed in the hope that it will be useful,                                            |
15
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
16
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
16
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
17
// | GNU General Public License for more details.                                                         |
17
// | GNU General Public License for more details.                                                         |
18
// |                                                                                                      |
18
// |                                                                                                      |
19
// | You should have received a copy of the GNU General Public License                                    |
19
// | You should have received a copy of the GNU General Public License                                    |
20
// | along with Foobar; if not, write to the Free Software                                                |
20
// | along with Foobar; if not, write to the Free Software                                                |
21
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
22
// +------------------------------------------------------------------------------------------------------+
22
// +------------------------------------------------------------------------------------------------------+
23
// CVS : $Id: Chronometre.class.php,v 1.1 2007-01-12 13:16:09 jp_milcent Exp $
23
// CVS : $Id: Chronometre.class.php,v 1.1 2007-01-12 13:16:09 jp_milcent Exp $
24
/**
24
/**
25
* Classe permettant de mesurer le temps d'execution d'un script.
25
* Classe permettant de mesurer le temps d'execution d'un script.
26
*
26
*
27
* Contient des méthodes permettant d'évaluer la vitesse d'exécution d'un script.
27
* Contient des méthodes permettant d'évaluer la vitesse d'exécution d'un script.
28
*
28
*
29
*@package eFlore
29
*@package eFlore
30
*@subpackage Debogage
30
*@subpackage Debogage
31
//Auteur original :
31
//Auteur original :
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
//Autres auteurs :
33
//Autres auteurs :
34
*@author        aucun
34
*@author        aucun
35
*@copyright     Tela-Botanica 2000-2005
35
*@copyright     Tela-Botanica 2000-2005
36
*@version       $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $
36
*@version       $Revision: 1.1 $ $Date: 2007-01-12 13:16:09 $
37
// +------------------------------------------------------------------------------------------------------+
37
// +------------------------------------------------------------------------------------------------------+
38
*/
38
*/
39
 
39
 
40
// +------------------------------------------------------------------------------------------------------+
40
// +------------------------------------------------------------------------------------------------------+
41
// |                                            ENTETE du PROGRAMME                                       |
41
// |                                            ENTETE du PROGRAMME                                       |
42
// +------------------------------------------------------------------------------------------------------+
42
// +------------------------------------------------------------------------------------------------------+
43
 
43
 
44
 
44
 
45
// +------------------------------------------------------------------------------------------------------+
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                            CORPS du PROGRAMME                                        |
46
// |                                            CORPS du PROGRAMME                                        |
47
// +------------------------------------------------------------------------------------------------------+
47
// +------------------------------------------------------------------------------------------------------+
48
/**Classe Chronometre() - Permet de stocker et d'afficher les temps d'éxécution de script.
48
/**Classe Chronometre() - Permet de stocker et d'afficher les temps d'éxécution de script.
49
*
49
*
50
* Cette classe permet de réaliser un ensemble de mesure de temps prises à
50
* Cette classe permet de réaliser un ensemble de mesure de temps prises à
51
* différents endroits d'un script. Ces mesures peuvent ensuite être affichées au
51
* différents endroits d'un script. Ces mesures peuvent ensuite être affichées au
52
* sein d'un tableau XHTML.
52
* sein d'un tableau XHTML.
53
* 
53
* 
54
* @author	Jean-Pascal MILCENT <jpm@tela-botanica.org>
54
* @author	Jean-Pascal MILCENT <jpm@tela-botanica.org>
55
*/
55
*/
56
class Chronometre
56
class Chronometre
57
{
57
{
58
	/*** Attributs : ***/
58
	/*** Attributs : ***/
59
	private $temps = array();
59
	private $temps = array();
60
	private $temps_sql = 0;
60
	private $temps_sql = 0;
61
	
61
	
62
	/*** Constructeur : ***/
62
	/*** Constructeur : ***/
63
	public function __construct() {
63
	public function __construct() {
64
		$this->setTemps(array('depart' => microtime()));
64
		$this->setTemps(array('depart' => microtime()));
65
	}
65
	}
66
	
66
	
67
	/*** Accesseurs : ***/
67
	/*** Accesseurs : ***/
68
	
68
	
69
	// Temps
69
	// Temps
70
	public function getTemps($cle = NULL) {
70
	public function getTemps($cle = NULL) {
71
		if (!is_null($cle)) {
71
		if (!is_null($cle)) {
72
			return $this->temps[$cle];
72
			return $this->temps[$cle];
73
		} else {
73
		} else {
74
			return $this->temps;
74
			return $this->temps;
75
		}
75
		}
76
	}
76
	}
77
	public function setTemps($moment = array()) {
77
	public function setTemps($moment = array()) {
78
		array_push($this->temps, $moment);	
78
		array_push($this->temps, $moment);	
79
	}
79
	}
80
 
80
 
81
	// Temps Sql
81
	// Temps Sql
-
 
82
	// Notes : utiliser microtime(true) pour renvoyer un float
82
	public function getTempsSql() {
83
	public function getTempsSql() {
83
		return $this->temps_sql;
84
		return $this->temps_sql;
84
	}
85
	}
85
	public function setTempsSql($tps_deb, $tps_fin = null) {
86
	public function setTempsSql($tps_deb, $tps_fin = null) {
86
		if (is_null($tps_fin)) {
87
		if (is_null($tps_fin)) {
87
			if (is_float($tps_deb)) {
88
			if (is_float($tps_deb)) {
88
				$this->temps_sql += $tps_deb;
89
				$this->temps_sql += $tps_deb;
89
			}
90
			}
90
		} else {
91
		} else {
91
			if (is_float($tps_deb) && is_float($tps_fin)) {
92
			if (is_float($tps_deb) && is_float($tps_fin)) {
92
				$this->temps_sql += $tps_fin - $tps_deb;
93
				$this->temps_sql += $tps_fin - $tps_deb;
93
			}
94
			}
94
		}
95
		}
95
	}
96
	}
96
	
97
	
97
	/*** Méthodes : ***/
98
	/*** Méthodes : ***/
98
	
99
	
99
	/**Méthode afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script.
100
	/**Méthode afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script.
100
	*
101
	*
101
	* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script.
102
	* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script.
102
	* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises.
103
	* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises.
103
	* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon,
104
	* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon,
104
	* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau.
105
	* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau.
105
	* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent.
106
	* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent.
106
	* Elle utilise une variable gobale : $_CHRONO_
107
	* Elle utilise une variable gobale : $_CHRONO_
107
	*
108
	*
108
	* @author   Loic d'Anterroches
109
	* @author   Loic d'Anterroches
109
	* @author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
110
	* @author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
110
	* @param    int     l'indentation de base pour le code html du tableau.
111
	* @param    int     l'indentation de base pour le code html du tableau.
111
	* @param    int     le pas d'indentation pour le code html du tableau.
112
	* @param    int     le pas d'indentation pour le code html du tableau.
112
	* @return   string  la chaine XHTML de mesure des temps.
113
	* @return   string  la chaine XHTML de mesure des temps.
113
	*/
114
	*/
114
	function afficherChrono($indentation_origine = 8, $indentation = 4)	{
115
	function afficherChrono($indentation_origine = 8, $indentation = 4)	{
115
		// Création du chrono de fin
116
		// Création du chrono de fin
116
		$GLOBALS['_EFLORE_']['chrono']->setTemps(array('fin' => microtime()));
117
		$GLOBALS['_EFLORE_']['chrono']->setTemps(array('fin' => microtime()));
117
 
118
 
118
		// Début création de l'affichage
119
		// Début création de l'affichage
119
		$sortie = str_repeat(' ', $indentation_origine).
120
		$sortie = str_repeat(' ', $indentation_origine).
120
		    		'<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n";
121
		    		'<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n";
121
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
122
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
122
		        '<caption>Chronométrage</caption>'."\n";
123
		        '<caption>Chronométrage</caption>'."\n";
123
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
124
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
124
		        '<thead>'."\n";
125
		        '<thead>'."\n";
125
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
126
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
126
		            '<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n";
127
		            '<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n";
127
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
128
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
128
		        '</thead>'."\n";
129
		        '</thead>'."\n";
129
		
130
		
130
		$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))).
131
		$tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))).
131
		        '<tbody>'."\n";
132
		        '<tbody>'."\n";
132
		        
133
		        
133
		$total_tps_ecoule = 0;
134
		$total_tps_ecoule = 0;
134
		
135
		
135
		// Récupération de la première mesure
136
		// Récupération de la première mesure
136
		$tab_depart =& $this->getTemps(0);
137
		$tab_depart =& $this->getTemps(0);
137
		list($usec, $sec) = explode(' ', $tab_depart['depart']);
138
		list($usec, $sec) = explode(' ', $tab_depart['depart']);
138
		
139
		
139
		// Ce temps correspond à tps_fin
140
		// Ce temps correspond à tps_fin
140
		$tps_debut = ((float)$usec + (float)$sec);
141
		$tps_debut = ((float)$usec + (float)$sec);
141
		
142
		
142
		foreach ($this->getTemps() as $tab_temps) {
143
		foreach ($this->getTemps() as $tab_temps) {
143
			foreach ($tab_temps as $cle => $valeur) {
144
			foreach ($tab_temps as $cle => $valeur) {
144
				list($usec, $sec) = explode(' ', $valeur);
145
				list($usec, $sec) = explode(' ', $valeur);
145
				$tps_fin = ((float)$usec + (float)$sec);
146
				$tps_fin = ((float)$usec + (float)$sec);
146
				
147
				
147
				$tps_ecoule = abs($tps_fin - $tps_debut);
148
				$tps_ecoule = abs($tps_fin - $tps_debut);
148
				$total_tps_ecoule += $tps_ecoule;
149
				$total_tps_ecoule += $tps_ecoule;
149
				
150
				
150
				$tbody .=   str_repeat(' ', ($indentation_origine + ($indentation * 2))).
151
				$tbody .=   str_repeat(' ', ($indentation_origine + ($indentation * 2))).
151
				        '<tr>'.
152
				        '<tr>'.
152
				            '<th>'.$cle.'</th>'.
153
				            '<th>'.$cle.'</th>'.
153
				            '<td>'.number_format($tps_ecoule, 3, ',', ' ').'</td>'.
154
				            '<td>'.number_format($tps_ecoule, 3, ',', ' ').'</td>'.
154
				            '<td>'.number_format($total_tps_ecoule, 3, ',', ' ').'</td>'.
155
				            '<td>'.number_format($total_tps_ecoule, 3, ',', ' ').'</td>'.
155
				        '</tr>'."\n";
156
				        '</tr>'."\n";
156
				$tps_debut = $tps_fin;
157
				$tps_debut = $tps_fin;
157
			}
158
			}
158
		}
159
		}
159
		$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
160
		$tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
160
		        '</tbody>'."\n";
161
		        '</tbody>'."\n";
161
		
162
		
162
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
163
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
163
		        '<tfoot>'."\n";
164
		        '<tfoot>'."\n";
164
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
165
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
165
		            '<tr>'.
166
		            '<tr>'.
166
		                '<th>'.'Total du temps écoulé (en s.)'.'</th>'.
167
		                '<th>'.'Total du temps écoulé (en s.)'.'</th>'.
167
		                '<td colspan="2">'.number_format($total_tps_ecoule,3, ',', ' ').'</td>'.
168
		                '<td colspan="2">'.number_format($total_tps_ecoule,3, ',', ' ').'</td>'.
168
		            '</tr>'."\n";
169
		            '</tr>'."\n";
169
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
170
		$sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
170
		        '</tfoot>'."\n";
171
		        '</tfoot>'."\n";
171
		$sortie .= $tbody;
172
		$sortie .= $tbody;
172
		$sortie .= str_repeat(' ', $indentation_origine).
173
		$sortie .= str_repeat(' ', $indentation_origine).
173
		    '</table>'."\n";
174
		    '</table>'."\n";
174
		
175
		
175
		return $sortie;
176
		return $sortie;
176
	}
177
	}
177
 
178
 
178
}
179
}
179
 
180
 
180
/* +--Fin du code ----------------------------------------------------------------------------------------+
181
/* +--Fin du code ----------------------------------------------------------------------------------------+
181
*
182
*
182
* $Log$
183
* $Log$
183
*
184
*
184
* +-- Fin du code ----------------------------------------------------------------------------------------+
185
* +-- Fin du code ----------------------------------------------------------------------------------------+
185
*/
186
*/
186
?>
187
?>