Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
2 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
285 jpm 22
// CVS : $Id: BOG_chrono.fonct.php,v 1.3 2005-02-28 11:14:45 jpm Exp $
2 jpm 23
/**
24
* Bibliothèque de fonctions permettant de mesure le temps d'execution d'un script.
25
*
26
* Contient des fonctions permettant d'évaluer un script.
27
*
28
*@package Debogage
29
//Auteur original :
30
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
31
//Autres auteurs :
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
285 jpm 34
*@version       $Revision: 1.3 $ $Date: 2005-02-28 11:14:45 $
2 jpm 35
// +------------------------------------------------------------------------------------------------------+
36
*/
37
 
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                           LISTE de FONCTIONS                                         |
40
// +------------------------------------------------------------------------------------------------------+
41
/**Fonction BOG_afficherChrono() - Permet d'afficher les temps d'éxécution de différentes parties d'un script.
42
*
43
* Cette fonction permet d'afficher un ensemble de mesure de temps prises à différents endroits d'un script.
44
* Ces mesures sont affichées au sein d'un tableau XHTML dont on peut controler l'indentation des balises.
45
* Pour un site en production, il suffit d'ajouter un style #chrono {display:none;} dans la css. De cette façon,
46
* le tableau ne s'affichera pas. Le webmaster lui pourra rajouter sa propre feuille de style affichant le tableau.
47
* Le développeur initial de cette fonction est Loic d'Anterroches. Elle a été modifiée par Jean-Pascal Milcent.
187 jpm 48
* Elle utilise une variable gobale : $_CHRONO_
2 jpm 49
*
285 jpm 50
* @author   Loic d'Anterroches
51
* @author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
2 jpm 52
* @param    int     l'indentation de base pour le code html du tableau.
53
* @param    int     le pas d'indentation pour le code html du tableau.
54
* @return   string  la chaine XHTML de mesure des temps.
55
*/
56
function BOG_afficherChrono($indentation_origine = 8, $indentation = 4)
57
{
58
    $sortie = str_repeat(' ', $indentation_origine).
59
        '<table id="chrono" lang="fr" summary="Résultat du chronométrage du programme affichant la page actuelle.">'."\n";
60
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
61
            '<caption>Chronométrage</caption>'."\n";
62
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
63
            '<thead>'."\n";
64
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
65
                '<tr><th>Action</th><th>Temps écoulé (en s.)</th><th>Cumul du temps écoulé (en s.)</th></tr>'."\n";
66
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
67
            '</thead>'."\n";
68
 
69
    $tbody = str_repeat(' ', ($indentation_origine + ($indentation * 1))).
70
            '<tbody>'."\n";
71
    $total_tps_ecoule = 0;
72
    // Récupération de la première mesure
187 jpm 73
    list($usec, $sec) = explode(' ', $GLOBALS['_CHRONO_']['depart']);
2 jpm 74
    // Ce temps correspond à tps_fin
75
    $tps_fin = ((float)$usec + (float)$sec);
76
 
187 jpm 77
    foreach ($GLOBALS['_CHRONO_'] as $cle => $valeur) {
2 jpm 78
        list($usec, $sec) = explode(' ',$valeur);
79
        $tps_debut = ((float)$usec + (float)$sec);
80
 
81
        $tps_ecoule = abs($tps_fin - $tps_debut);
82
        $total_tps_ecoule += $tps_ecoule;
83
 
84
        $tbody .=   str_repeat(' ', ($indentation_origine + ($indentation * 2))).
85
                    '<tr>'.
86
                        '<th>'.$cle.'</th>'.
87
                        '<td>'.number_format($tps_ecoule,3).'</td>'.
88
                        '<td>'.number_format($total_tps_ecoule,3).'</td>'.
89
                    '</tr>'."\n";
90
        $tps_fin = $tps_debut;
91
    }
92
    $tbody .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
93
            '</tbody>'."\n";
94
 
95
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
96
            '<tfoot>'."\n";
97
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 2))).
98
                '<tr>'.
99
                    '<th>'.'Total du temps écoulé (en s.)'.'</th>'.
100
                    '<td colspan="2">'.number_format($total_tps_ecoule,3).'</td>'.
101
                '</tr>'."\n";
102
    $sortie .= str_repeat(' ', ($indentation_origine + ($indentation * 1))).
103
            '</tfoot>'."\n";
104
    $sortie .= $tbody;
105
    $sortie .= str_repeat(' ', $indentation_origine).
106
        '</table>'."\n";
107
 
108
    return $sortie;
109
}
110
 
111
/* +--Fin du code ----------------------------------------------------------------------------------------+
112
*
2150 mathias 113
* $Log: BOG_chrono.fonct.php,v $
114
* Revision 1.3  2005-02-28 11:14:45  jpm
115
* Modification des auteurs.
116
*
285 jpm 117
* Revision 1.2  2004/11/29 15:54:16  jpm
118
* Changement de nom de variable et légère correction.
119
*
187 jpm 120
* Revision 1.1  2004/06/15 10:13:07  jpm
121
* Intégration dans Papyrus.
122
*
2 jpm 123
* Revision 1.2  2004/04/22 09:01:55  jpm
124
* Ajout de l'attribut lang au tableau.
125
*
126
* Revision 1.1  2004/04/21 07:49:13  jpm
127
* Ajout d'une bibliothèque de fonction pour le chronométrage des scripts.
128
*
129
*
130
* +-- Fin du code ----------------------------------------------------------------------------------------+
131
*/
132
?>