Subversion Repositories Applications.papyrus

Rev

Rev 2014 | Details | Compare with Previous | Last modification | View Log | RSS feed

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