TeamSpeak 3 PHP Framework  1.1.23
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
TeamSpeak3_Helper_Profiler_Timer Class Reference

Helper class providing profiler timers. More...

Public Member Functions

 __construct ($name)
 The TeamSpeak3_Helper_Profiler_Timer constructor. More...
 
 start ()
 Starts the timer. More...
 
 stop ()
 Stops the timer. More...
 
 getRuntime ()
 Return the timer runtime. More...
 
 getMemUsage ($realmem=FALSE)
 Returns the amount of memory allocated to PHP in bytes. More...
 
 isRunning ()
 Returns TRUE if the timer is running. More...
 

Protected Attributes

 $running = FALSE
 
 $started = 0
 
 $name = null
 
 $data = array()
 

Detailed Description

Helper class providing profiler timers.

Definition at line 32 of file Timer.php.

Constructor & Destructor Documentation

TeamSpeak3_Helper_Profiler_Timer::__construct (   $name)

The TeamSpeak3_Helper_Profiler_Timer constructor.

Parameters
string$name
Returns
TeamSpeak3_Helper_Profiler_Timer

Definition at line 68 of file Timer.php.

References start().

69  {
70  $this->name = (string) $name;
71 
72  $this->data["runtime"] = 0;
73  $this->data["realmem"] = 0;
74  $this->data["emalloc"] = 0;
75 
76  $this->start();
77  }

Member Function Documentation

TeamSpeak3_Helper_Profiler_Timer::start ( )

Starts the timer.

Returns
void

Definition at line 84 of file Timer.php.

References isRunning().

Referenced by __construct(), getMemUsage(), and getRuntime().

85  {
86  if($this->isRunning()) return;
87 
88  $this->data["realmem_start"] = memory_get_usage(TRUE);
89  $this->data["emalloc_start"] = memory_get_usage();
90 
91  $this->started = microtime(TRUE);
92  $this->running = TRUE;
93  }
TeamSpeak3_Helper_Profiler_Timer::stop ( )

Stops the timer.

Returns
void

Definition at line 100 of file Timer.php.

References isRunning().

Referenced by getMemUsage(), and getRuntime().

101  {
102  if(!$this->isRunning()) return;
103 
104  $this->data["runtime"] += microtime(TRUE) - $this->started;
105  $this->data["realmem"] += memory_get_usage(TRUE) - $this->data["realmem_start"];
106  $this->data["emalloc"] += memory_get_usage() - $this->data["emalloc_start"];
107 
108  $this->started = 0;
109  $this->running = FALSE;
110  }
TeamSpeak3_Helper_Profiler_Timer::getRuntime ( )

Return the timer runtime.

Returns
mixed

Definition at line 117 of file Timer.php.

References isRunning(), start(), and stop().

118  {
119  if($this->isRunning())
120  {
121  $this->stop();
122  $this->start();
123  }
124 
125  return $this->data["runtime"];
126  }
TeamSpeak3_Helper_Profiler_Timer::getMemUsage (   $realmem = FALSE)

Returns the amount of memory allocated to PHP in bytes.

Parameters
boolean$realmem
Returns
integer

Definition at line 134 of file Timer.php.

References isRunning(), start(), and stop().

135  {
136  if($this->isRunning())
137  {
138  $this->stop();
139  $this->start();
140  }
141 
142  return ($realmem !== FALSE) ? $this->data["realmem"] : $this->data["emalloc"];
143  }
TeamSpeak3_Helper_Profiler_Timer::isRunning ( )

Returns TRUE if the timer is running.

Returns
boolean

Definition at line 150 of file Timer.php.

Referenced by getMemUsage(), getRuntime(), start(), and stop().

151  {
152  return $this->running;
153  }

The documentation for this class was generated from the following file: