2 ini_set( 'zlib.output_compression', 'off' );
4 $wgEnableProfileInfo = $wgProfileToDatabase = false;
6 require_once( './includes/WebStart.php' );
12 Copyright 2005 Kate Turner.
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 <title>Profiling data</title>
36 <style type="text/css">
39 border-bottom: solid 1px black;
47 td.timep, td.memoryp, td.count, td.cpr, td.tpc, td.mpc, td.tpr, td.mpr {
50 td.timep, td.tpc, td.tpr {
51 background-color: #fffff0;
53 td.memoryp, td.mpc, td.mpr {
54 background-color: #f0f8ff;
57 background-color: #f0fff0;
60 background-color: #f9f9f9;
67 if ( !$wgEnableProfileInfo ) {
68 echo "<p>Disabled</p>\n";
69 echo "</body></html>";
74 if ( isset( $_REQUEST['expand'] ) )
75 foreach( explode( ',', $_REQUEST['expand'] ) as $f )
84 function profile_point( $name, $count, $time, $memory ) {
86 $this->count = $count;
88 $this->memory = $memory;
89 $this->children = array();
92 function add_child( $child ) {
93 $this->children[] = $child;
96 function display($indent = 0.0) {
97 global $expand, $totaltime, $totalmemory, $totalcount;
98 usort( $this->children, 'compare_point' );
101 if ( isset( $expand[$this->name()] ) )
105 if ( count( $this->children ) ) {
106 $url = getEscapedProfileUrl( false, false, $expand + array( $this->name() => true ) );
107 $extet = " <a href=\"$url\">[+]</a>";
111 foreach ( $expand as $name => $ep )
112 if ( $name != $this->name() )
113 $e += array( $name => $ep );
115 $extet = " <a href=\"" . getEscapedProfileUrl( false, false, $e ) . "\">[–]</a>";
119 <td class="name" style="padding-left: <?php echo $indent ?>em;">
120 <?php echo htmlspecialchars( $this->name() ) . $extet ?>
122 <td class="timep"><?php echo @wfPercent( $this->time() / $totaltime * 100 ) ?></td>
123 <td class="memoryp"><?php echo @wfPercent( $this->memory() / $totalmemory * 100 ) ?></td>
124 <td class="count"><?php echo $this->count() ?></td>
125 <td class="cpr"><?php echo round( sprintf( '%.2f', $this->callsPerRequest() ), 2 ) ?></td>
126 <td class="tpc"><?php echo round( sprintf( '%.2f', $this->timePerCall() ), 2 ) ?></td>
127 <td class="mpc"><?php echo round( sprintf( '%.2f' ,$this->memoryPerCall() / 1024 ), 2 ) ?></td>
128 <td class="tpr"><?php echo @round( sprintf( '%.2f', $this->time() / $totalcount ), 2 ) ?></td>
129 <td class="mpr"><?php echo @round( sprintf( '%.2f' ,$this->memory() / $totalcount / 1024 ), 2 ) ?></td>
133 foreach ( $this->children as $child ) {
134 $child->display( $indent + 2 );
152 return $this->memory;
155 function timePerCall() {
156 return @( $this->time / $this->count );
159 function memoryPerCall() {
160 return @( $this->memory / $this->count );
163 function callsPerRequest() {
165 return @( $this->count / $totalcount );
168 function timePerRequest() {
170 return @( $this->time / $totalcount );
173 function memoryPerRequest() {
175 return @( $this->memory / $totalcount );
179 return sprintf( "%5.02f", $this->time );
183 function compare_point( $a, $b ) {
187 return strcmp( $a->name(), $b->name() );
189 return $a->time() > $b->time() ? -1 : 1;
191 return $a->memory() > $b->memory() ? -1 : 1;
193 return $a->count() > $b->count() ? -1 : 1;
194 case "time_per_call":
195 return $a->timePerCall() > $b->timePerCall() ? -1 : 1;
196 case "memory_per_call":
197 return $a->memoryPerCall() > $b->memoryPerCall() ? -1 : 1;
198 case "calls_per_req":
199 return $a->callsPerRequest() > $b->callsPerRequest() ? -1 : 1;
201 return $a->timePerRequest() > $b->timePerRequest() ? -1 : 1;
202 case "memory_per_req":
203 return $a->memoryPerRequest() > $b->memoryPerRequest() ? -1 : 1;
207 $sorts = array( 'time', 'memory', 'count', 'calls_per_req', 'name',
208 'time_per_call', 'memory_per_call', 'time_per_req', 'memory_per_req' );
210 if ( isset( $_REQUEST['sort'] ) && in_array( $_REQUEST['sort'], $sorts ) )
211 $sort = $_REQUEST['sort'];
214 $dbr = wfGetDB( DB_SLAVE );
215 $res = $dbr->select( 'profiling', '*', array(), 'profileinfo.php', array( 'ORDER BY' => 'pf_name ASC' ) );
217 if (isset( $_REQUEST['filter'] ) )
218 $filter = $_REQUEST['filter'];
223 <form method="get" action="profileinfo.php">
225 <input type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>"/>
226 <input type="hidden" name="sort" value="<?php echo htmlspecialchars($sort)?>"/>
227 <input type="hidden" name="expand" value="<?php echo htmlspecialchars(implode(",", array_keys($expand)))?>"/>
228 <input type="submit" value="Filter" />
232 <table cellspacing="0" border="1">
234 <th><a href="<?php echo getEscapedProfileUrl( false, 'name' ) ?>">Name</a></th>
235 <th><a href="<?php echo getEscapedProfileUrl( false, 'time' ) ?>">Time (%)</a></th>
236 <th><a href="<?php echo getEscapedProfileUrl( false, 'memory' ) ?>">Memory (%)</a></th>
237 <th><a href="<?php echo getEscapedProfileUrl( false, 'count' ) ?>">Count</a></th>
238 <th><a href="<?php echo getEscapedProfileUrl( false, 'calls_per_req' ) ?>">Calls/req</a></th>
239 <th><a href="<?php echo getEscapedProfileUrl( false, 'time_per_call' ) ?>">ms/call</a></th>
240 <th><a href="<?php echo getEscapedProfileUrl( false, 'memory_per_call' ) ?>">kb/call</a></th>
241 <th><a href="<?php echo getEscapedProfileUrl( false, 'time_per_req' ) ?>">ms/req</a></th>
242 <th><a href="<?php echo getEscapedProfileUrl( false, 'memory_per_req' ) ?>">kb/req</a></th>
249 function getEscapedProfileUrl( $_filter = false, $_sort = false, $_expand = false ) {
250 global $filter, $sort, $expand;
252 if ( $_expand === false )
255 return htmlspecialchars(
258 'filter' => $_filter ? $_filter : $filter,
259 'sort' => $_sort ? $_sort : $sort,
260 'expand' => implode( ',', array_keys( $_expand ) )
270 foreach( $res as $o ) {
271 $next = new profile_point( $o->pf_name, $o->pf_count, $o->pf_time, $o->pf_memory );
272 if( $next->name() == '-total' ) {
273 $totaltime = $next->time();
274 $totalcount = $next->count();
275 $totalmemory = $next->memory();
277 if ( $last !== false ) {
278 if ( preg_match( "/^".preg_quote( $last->name(), "/" )."/", $next->name() ) ) {
279 $last->add_child($next);
284 if ( preg_match( "/^query: /", $next->name() ) || preg_match( "/^query-m: /", $next->name() ) ) {
285 $sqltotal += $next->time();
292 $s = new profile_point( "SQL Queries", 0, $sqltotal, 0, 0 );
293 foreach ( $queries as $q )
297 usort( $points, "compare_point" );
299 foreach ( $points as $point ) {
300 if ( strlen( $filter ) && !strstr( $point->name(), $filter ) )
308 <p>Total time: <tt><?php printf("%5.02f", $totaltime) ?></tt></p>
309 <p>Total memory: <tt><?php printf("%5.02f", $totalmemory / 1024 ) ?></tt></p>