First step of reorganizing profiling files:
[lhc/web/wiklou.git] / includes / profiler / ProfilerStub.php
1 <?php
2 /**
3 * Stub profiling functions
4 * @file
5 * @ingroup Profiler
6 */
7 if ( !class_exists( 'Profiler' ) ) {
8 require_once( dirname( __FILE__ ) . '/Profiler.php' );
9 }
10
11 class ProfilerStub extends Profiler {
12
13 /**
14 * is setproctitle function available?
15 * @var bool
16 */
17 private $haveProctitle;
18 private $hackWhere = array();
19
20 /**
21 * Constructor. Check for proctitle.
22 */
23 public function __construct() {
24 $this->haveProctitle = function_exists( 'setproctitle' );
25 }
26
27 /**
28 * Begin profiling of a function
29 * @param $fn string
30 */
31 public function profileIn( $fn = '' ) {
32 global $wgDBname;
33 if( $this->haveProctitle ){
34 $this->hackWhere[] = $fn;
35 setproctitle( $fn . " [$wgDBname]" );
36 }
37 }
38
39 /**
40 * Stop profiling of a function
41 * @param $fn string
42 */
43 public function profileOut( $fn = '' ) {
44 global $wgDBname;
45 if( !$this->haveProctitle ) {
46 return;
47 }
48 if( count( $this->hackWhere ) ) {
49 array_pop( $this->hackWhere );
50 }
51 if( count( $this->hackWhere ) ) {
52 setproctitle( $this->hackWhere[count( $this->hackWhere )-1] . " [$wgDBname]" );
53 }
54 }
55
56 /**
57 * Does nothing, just for compatibility
58 */
59 public function getOutput() {}
60 public function close() {}
61 }
62
63 /** backward compatibility */
64 $wgProfiling = false;
65 $wgProfiler = new ProfilerStub();