5c826090e06e05bd5d1103ff3706f358994dba18
[lhc/web/wiklou.git] / includes / profiler / ProfilerStub.php
1 <?php
2 /**
3 * Stub profiling functions
4 * @file
5 * @ingroup Profiler
6 */
7 class ProfilerStub extends Profiler {
8
9 /**
10 * is setproctitle function available?
11 * @var bool
12 */
13 private $haveProctitle;
14 private $hackWhere = array();
15
16 /**
17 * Constructor. Check for proctitle.
18 */
19 public function __construct() {
20 $this->haveProctitle = function_exists( 'setproctitle' );
21 }
22
23 public function isStub() {
24 return true;
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 }