You are here

class Twig_Profiler_Profile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Profiler/Profile.php \Twig_Profiler_Profile

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of Twig_Profiler_Profile

File

vendor/twig/twig/lib/Twig/Profiler/Profile.php, line 15

View source
class Twig_Profiler_Profile implements IteratorAggregate, Serializable {
  const ROOT = 'ROOT';
  const BLOCK = 'block';
  const TEMPLATE = 'template';
  const MACRO = 'macro';
  private $template;
  private $name;
  private $type;
  private $starts = array();
  private $ends = array();
  private $profiles = array();
  public function __construct($template = 'main', $type = self::ROOT, $name = 'main') {
    $this->template = $template;
    $this->type = $type;
    $this->name = 0 === strpos($name, '__internal_') ? 'INTERNAL' : $name;
    $this
      ->enter();
  }
  public function getTemplate() {
    return $this->template;
  }
  public function getType() {
    return $this->type;
  }
  public function getName() {
    return $this->name;
  }
  public function isRoot() {
    return self::ROOT === $this->type;
  }
  public function isTemplate() {
    return self::TEMPLATE === $this->type;
  }
  public function isBlock() {
    return self::BLOCK === $this->type;
  }
  public function isMacro() {
    return self::MACRO === $this->type;
  }
  public function getProfiles() {
    return $this->profiles;
  }
  public function addProfile(Twig_Profiler_Profile $profile) {
    $this->profiles[] = $profile;
  }

  /**
   * Returns the duration in microseconds.
   *
   * @return int
   */
  public function getDuration() {
    if ($this
      ->isRoot() && $this->profiles) {

      // for the root node with children, duration is the sum of all child durations
      $duration = 0;
      foreach ($this->profiles as $profile) {
        $duration += $profile
          ->getDuration();
      }
      return $duration;
    }
    return isset($this->ends['wt']) && isset($this->starts['wt']) ? $this->ends['wt'] - $this->starts['wt'] : 0;
  }

  /**
   * Returns the memory usage in bytes.
   *
   * @return int
   */
  public function getMemoryUsage() {
    return isset($this->ends['mu']) && isset($this->starts['mu']) ? $this->ends['mu'] - $this->starts['mu'] : 0;
  }

  /**
   * Returns the peak memory usage in bytes.
   *
   * @return int
   */
  public function getPeakMemoryUsage() {
    return isset($this->ends['pmu']) && isset($this->starts['pmu']) ? $this->ends['pmu'] - $this->starts['pmu'] : 0;
  }

  /**
   * Starts the profiling.
   */
  public function enter() {
    $this->starts = array(
      'wt' => microtime(true),
      'mu' => memory_get_usage(),
      'pmu' => memory_get_peak_usage(),
    );
  }

  /**
   * Stops the profiling.
   */
  public function leave() {
    $this->ends = array(
      'wt' => microtime(true),
      'mu' => memory_get_usage(),
      'pmu' => memory_get_peak_usage(),
    );
  }
  public function getIterator() {
    return new ArrayIterator($this->profiles);
  }
  public function serialize() {
    return serialize(array(
      $this->template,
      $this->name,
      $this->type,
      $this->starts,
      $this->ends,
      $this->profiles,
    ));
  }
  public function unserialize($data) {
    list($this->template, $this->name, $this->type, $this->starts, $this->ends, $this->profiles) = unserialize($data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Twig_Profiler_Profile::$ends private property
Twig_Profiler_Profile::$name private property
Twig_Profiler_Profile::$profiles private property
Twig_Profiler_Profile::$starts private property
Twig_Profiler_Profile::$template private property
Twig_Profiler_Profile::$type private property
Twig_Profiler_Profile::addProfile public function
Twig_Profiler_Profile::BLOCK constant
Twig_Profiler_Profile::enter public function Starts the profiling.
Twig_Profiler_Profile::getDuration public function Returns the duration in microseconds.
Twig_Profiler_Profile::getIterator public function
Twig_Profiler_Profile::getMemoryUsage public function Returns the memory usage in bytes.
Twig_Profiler_Profile::getName public function
Twig_Profiler_Profile::getPeakMemoryUsage public function Returns the peak memory usage in bytes.
Twig_Profiler_Profile::getProfiles public function
Twig_Profiler_Profile::getTemplate public function
Twig_Profiler_Profile::getType public function
Twig_Profiler_Profile::isBlock public function
Twig_Profiler_Profile::isMacro public function
Twig_Profiler_Profile::isRoot public function
Twig_Profiler_Profile::isTemplate public function
Twig_Profiler_Profile::leave public function Stops the profiling.
Twig_Profiler_Profile::MACRO constant
Twig_Profiler_Profile::ROOT constant
Twig_Profiler_Profile::serialize public function
Twig_Profiler_Profile::TEMPLATE constant
Twig_Profiler_Profile::unserialize public function
Twig_Profiler_Profile::__construct public function