MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mprofile.class
Ir para a documentação deste ficheiro.
1<?php
6class MProfile extends MService
7{
11 private $profile;
12
16 private $log;
17
25 function __construct()
26 {
27 parent::__construct();
28 $this->log = $this->manager->log;
29 }
30
38 function ProfileTime()
39 {
40 list($msec, $sec) = explode(' ', microtime());
41 return $sec + $msec;
42 }
43
53 function ProfileEnter($name)
54 {
55 $this->profile[$name][0] = $this->ProfileTime(); // current time stamp
56 $this->profile[$name][1] = 0; // accumulated usage time
57 $this->profile[$name][2] = true; // state: active
58 }
59
69 function ProfileExit($name)
70 {
71 $now = $this->ProfileTime();
72 $usage = $now - $this->profile[$name][0];
73
74 $this->profile[$name][0] = $now; // current time stamp
75 $this->profile[$name][1] += $usage; // accumulated usage time
76 $this->profile[$name][2] = false; // state: inactive
77 }
78
86 function ProfileDump()
87 {
88 if ($this->profile)
89 {
90 $total = 0;
91 $text = '';
92
93 foreach (array_keys($this->profile)as $name)
94 {
95 // is profile still active - terminate first
96 if ($this->profile[$name][2])
97 {
98 $this->ProfileExit($name);
99 }
100
101 $time = $this->profile[$name][1];
102
103 $usage = sprintf("%.3f", $time);
104 $msg = "[PROFILE]$name: $usage sec";
105 $this->log->LogMessage($msg);
106 $text .= $msg . '\n';
107 $total += $time;
108 }
109
110 $total = sprintf("%.3f", $total);
111 $msg = "[PROFILE]Total: $total sec";
112 $this->log->LogMessage($msg);
113 $text .= $msg . '\n';
114 return $text;
115 }
116 }
117
125 function GetProfileDump()
126 {
127 if ($this->profile)
128 {
129 $total = 0;
130
131 $html = "<p><b>Profile Information:</b><br>\n"
132 . "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
133
134 foreach (array_keys($this->profile)as $name)
135 {
136 // caso profile est? ativo; termina o primeiro
137 if ($this->profile[$name][2])
138 {
139 $this->ProfileExit($name);
140 }
141
142 $usage = sprintf("%.3f", $this->profile[$name][1]);
143
144 $html .= "<tr><td>&nbsp;&nbsp;$name:</td><td align=\"right\">&nbsp;$usage&nbsp;sec</td></tr>\n";
145 }
146
147 $html .= "</table>\n";
148 }
149
150 return $html;
151 }
152}
153?>
__construct()
Definição mprofile.class:25
ProfileDump()
Definição mprofile.class:86
ProfileTime()
Definição mprofile.class:38
ProfileExit($name)
Definição mprofile.class:69
GetProfileDump()
Definição mprofile.class:125
ProfileEnter($name)
Definição mprofile.class:53