TeamSpeak 3 PHP Framework  1.1.12
TeamSpeak3_Helper_Profiler_Timer Class Reference

Helper class providing profiler timers. More...

List of all members.

Public Member Functions

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

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

The TeamSpeak3_Helper_Profiler_Timer constructor.

Parameters:
string$name
Returns:
TeamSpeak3_Helper_Profiler_Timer

Definition at line 68 of file Timer.php.

References start().

  {
    $this->name = (string) $name;

    $this->data["runtime"] = 0;
    $this->data["realmem"] = 0;
    $this->data["emalloc"] = 0;

    $this->start();
  }

Member Function Documentation

Starts the timer.

Returns:
void

Definition at line 84 of file Timer.php.

References isRunning().

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

  {
    if($this->isRunning()) return;

    $this->data["realmem_start"] = memory_get_usage(TRUE);
    $this->data["emalloc_start"] = memory_get_usage();

    $this->started = microtime(TRUE);
    $this->running = TRUE;
  }

Stops the timer.

Returns:
void

Definition at line 100 of file Timer.php.

References isRunning().

Referenced by getMemUsage(), and getRuntime().

  {
    if(!$this->isRunning()) return;

    $this->data["runtime"] += microtime(TRUE) - $this->started;
    $this->data["realmem"] += memory_get_usage(TRUE) - $this->data["realmem_start"];
    $this->data["emalloc"] += memory_get_usage() - $this->data["emalloc_start"];

    $this->started = 0;
    $this->running = FALSE;
  }

Return the timer runtime.

Returns:
mixed

Definition at line 117 of file Timer.php.

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

  {
    if($this->isRunning())
    {
      $this->stop();
      $this->start();
    }

    return $this->data["runtime"];
  }

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().

  {
    if($this->isRunning())
    {
      $this->stop();
      $this->start();
    }

    return ($realmem !== FALSE) ? $this->data["realmem"] : $this->data["emalloc"];
  }

Returns TRUE if the timer is running.

Returns:
boolean

Definition at line 150 of file Timer.php.

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

  {
    return $this->running;
  }

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables