Localisation updates: Adding/updating Persian translations
[mediawiki.git] / profileinfo.php
blobbf3cd0f81f3a9a980e10fe9336304d048a83e32f
1 <!--
2 Show profiling data.
4 Copyright 2005 Kate Turner.
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
24 -->
25 <html>
26 <head>
27 <title>Profiling data</title>
28 <style type="text/css">
29 th {
30 text-align: left;
31 border-bottom: solid 1px black;
34 th, td {
35 padding-left: 0.5em;
36 padding-right: 0.5em;
39 td.timep, td.memoryp, td.count, td.cpr, td.tpc, td.mpc, td.tpr, td.mpr {
40 text-align: right;
42 td.timep, td.tpc, td.tpr {
43 background-color: #fffff0;
45 td.memoryp, td.mpc, td.mpr {
46 background-color: #f0f8ff;
48 td.count, td,cpr {
49 background-color: #f0fff0;
51 td.name {
52 background-color: #f9f9f9;
54 </style>
55 </head>
56 <body>
57 <?php
58 ini_set( 'zlib.output_compression', 'off' );
60 $wgDBadminuser = $wgDBadminpassword = $wgDBserver = $wgDBname = $wgEnableProfileInfo = $wgDBprefix = false;
62 define( 'MW_NO_SETUP', 1 );
63 require_once( './includes/WebStart.php' );
64 require_once("./AdminSettings.php");
65 require_once( './includes/GlobalFunctions.php' );
67 if (!$wgEnableProfileInfo) {
68 echo "disabled\n";
69 exit( 1 );
72 foreach (array("wgDBadminuser", "wgDBadminpassword", "wgDBserver", "wgDBname") as $var)
73 if ($$var === false) {
74 echo "AdminSettings.php not correct\n";
75 exit( 1 );
79 $expand = array();
80 if (isset($_REQUEST['expand']))
81 foreach(explode(",", $_REQUEST['expand']) as $f)
82 $expand[$f] = true;
84 class profile_point {
85 var $name;
86 var $count;
87 var $time;
88 var $children;
90 function profile_point($name, $count, $time, $memory ) {
91 $this->name = $name;
92 $this->count = $count;
93 $this->time = $time;
94 $this->memory = $memory;
95 $this->children = array();
98 function add_child($child) {
99 $this->children[] = $child;
102 function display($indent = 0.0) {
103 global $expand, $totaltime, $totalmemory, $totalcount;
104 usort($this->children, "compare_point");
106 $extet = '';
107 if (isset($expand[$this->name()]))
108 $ex = true;
109 else $ex = false;
110 if (!$ex) {
111 if (count($this->children)) {
112 $url = makeurl(false, false, $expand + array($this->name() => true));
113 $extet = " <a href=\"$url\">[+]</a>";
114 } else $extet = '';
115 } else {
116 $e = array();
117 foreach ($expand as $name => $ep)
118 if ($name != $this->name())
119 $e += array($name => $ep);
121 $extet = " <a href=\"" . makeurl(false, false, $e) . "\">[&ndash;]</a>";
124 <tr>
125 <td class="name" style="padding-left: <?php echo $indent ?>em;">
126 <?php echo htmlspecialchars($this->name()) . $extet ?>
127 </td>
128 <td class="timep"><?php echo @wfPercent( $this->time() / $totaltime * 100 ) ?></td>
129 <td class="memoryp"><?php echo @wfPercent( $this->memory() / $totalmemory * 100 ) ?></td>
130 <td class="count"><?php echo $this->count() ?></td>
131 <td class="cpr"><?php echo round( sprintf( '%.2f', $this->callsPerRequest() ), 2 ) ?></td>
132 <td class="tpc"><?php echo round( sprintf( '%.2f', $this->timePerCall() ), 2 ) ?></td>
133 <td class="mpc"><?php echo round( sprintf( '%.2f' ,$this->memoryPerCall() / 1024 ), 2 ) ?></td>
134 <td class="tpr"><?php echo @round( sprintf( '%.2f', $this->time() / $totalcount ), 2 ) ?></td>
135 <td class="mpr"><?php echo @round( sprintf( '%.2f' ,$this->memory() / $totalcount / 1024 ), 2 ) ?></td>
136 </tr>
137 <?php
138 if ($ex) {
139 foreach ($this->children as $child) {
140 $child->display($indent + 2);
145 function name() {
146 return $this->name;
149 function count() {
150 return $this->count;
153 function time() {
154 return $this->time;
157 function memory() {
158 return $this->memory;
161 function timePerCall() {
162 return @($this->time / $this->count);
165 function memoryPerCall() {
166 return @($this->memory / $this->count);
169 function callsPerRequest() {
170 global $totalcount;
171 return @($this->count / $totalcount);
174 function timePerRequest() {
175 global $totalcount;
176 return @($this->time / $totalcount);
179 function memoryPerRequest() {
180 global $totalcount;
181 return @($this->memory / $totalcount);
184 function fmttime() {
185 return sprintf("%5.02f", $this->time);
189 function compare_point($a, $b) {
190 global $sort;
191 switch ($sort) {
192 case "name":
193 return strcmp($a->name(), $b->name());
194 case "time":
195 return $a->time() > $b->time() ? -1 : 1;
196 case "memory":
197 return $a->memory() > $b->memory() ? -1 : 1;
198 case "count":
199 return $a->count() > $b->count() ? -1 : 1;
200 case "time_per_call":
201 return $a->timePerCall() > $b->timePerCall() ? -1 : 1;
202 case "memory_per_call":
203 return $a->memoryPerCall() > $b->memoryPerCall() ? -1 : 1;
204 case "calls_per_req":
205 return $a->callsPerRequest() > $b->callsPerRequest() ? -1 : 1;
206 case "time_per_req":
207 return $a->timePerRequest() > $b->timePerRequest() ? -1 : 1;
208 case "memory_per_req":
209 return $a->memoryPerRequest() > $b->memoryPerRequest() ? -1 : 1;
213 $sorts = array("time","memory","count","calls_per_req","name","time_per_call","memory_per_call","time_per_req","memory_per_req");
214 $sort = 'time';
215 if (isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sorts))
216 $sort = $_REQUEST['sort'];
218 $dbh = mysql_connect($wgDBserver, $wgDBadminuser, $wgDBadminpassword)
219 or die("mysql server failed: " . mysql_error());
220 mysql_select_db($wgDBname, $dbh) or die(mysql_error($dbh));
221 $res = mysql_query("
222 SELECT pf_count, pf_time, pf_memory, pf_name
223 FROM {$wgDBprefix}profiling
224 ORDER BY pf_name ASC
225 ", $dbh) or die("query failed: " . mysql_error());
227 if (isset($_REQUEST['filter']))
228 $filter = $_REQUEST['filter'];
229 else $filter = '';
232 <form method="profiling.php">
234 <input type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>"/>
235 <input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort)?>"/>
236 <input type="hidden" name="expand" value="<?php echo htmlspecialchars(implode(",", array_keys($expand)))?>"/>
237 <input type="submit" value="Filter" />
238 </p>
239 </form>
241 <table cellspacing="0" border="1">
242 <tr id="top">
243 <th><a href="<?php echo makeurl(false, "name") ?>">Name</a></th>
244 <th><a href="<?php echo makeurl(false, "time") ?>">Time (%)</a></th>
245 <th><a href="<?php echo makeurl(false, "memory") ?>">Memory (%)</a></th>
246 <th><a href="<?php echo makeurl(false, "count") ?>">Count</a></th>
247 <th><a href="<?php echo makeurl(false, "calls_per_req") ?>">Calls/req</a></th>
248 <th><a href="<?php echo makeurl(false, "time_per_call") ?>">ms/call</a></th>
249 <th><a href="<?php echo makeurl(false, "memory_per_call") ?>">kb/call</a></th>
250 <th><a href="<?php echo makeurl(false, "time_per_req") ?>">ms/req</a></th>
251 <th><a href="<?php echo makeurl(false, "memory_per_req") ?>">kb/req</a></th>
252 </tr>
253 <?php
254 $totaltime = 0.0;
255 $totalcount = 0;
256 $totalmemory = 0.0;
258 function makeurl($_filter = false, $_sort = false, $_expand = false) {
259 global $filter, $sort, $expand;
261 if ($_expand === false)
262 $_expand = $expand;
264 $nfilter = $_filter ? $_filter : $filter;
265 $nsort = $_sort ? $_sort : $sort;
266 $exp = urlencode(implode(',', array_keys($_expand)));
267 return "?filter=$nfilter&amp;sort=$nsort&amp;expand=$exp";
270 $points = array();
271 $queries = array();
272 $sqltotal = 0.0;
274 $last = false;
275 while (($o = mysql_fetch_object($res)) !== false) {
276 $next = new profile_point($o->pf_name, $o->pf_count, $o->pf_time, $o->pf_memory);
277 if( $next->name() == '-total' ) {
278 $totaltime = $next->time();
279 $totalcount = $next->count();
280 $totalmemory = $next->memory();
282 if ($last !== false) {
283 if (preg_match("/^".preg_quote($last->name(), "/")."/", $next->name())) {
284 $last->add_child($next);
285 continue;
288 $last = $next;
289 if (preg_match("/^query: /", $next->name()) || preg_match("/^query-m: /", $next->name())) {
290 $sqltotal += $next->time();
291 $queries[] = $next;
292 } else {
293 $points[] = $next;
297 $s = new profile_point("SQL Queries", 0, $sqltotal, 0, 0);
298 foreach ($queries as $q)
299 $s->add_child($q);
300 $points[] = $s;
302 usort($points, "compare_point");
304 foreach ($points as $point) {
305 if (strlen($filter) && !strstr($point->name(), $filter))
306 continue;
308 $point->display();
311 </table>
313 <p>Total time: <tt><?php printf("%5.02f", $totaltime) ?></tt></p>
314 <p>Total memory: <tt><?php printf("%5.02f", $totalmemory / 1024 ) ?></tt></p>
315 <?php
317 mysql_free_result($res);
318 mysql_close($dbh);
321 </body>
322 </html>