0 follower

Abstract Class Yiisoft\Profiler\Target\AbstractTarget

InheritanceYiisoft\Profiler\Target\AbstractTarget
ImplementsYiisoft\Profiler\Target\TargetInterface
SubclassesYiisoft\Profiler\Target\FileTarget, Yiisoft\Profiler\Target\LogTarget

Target is the base class for all profiling target classes.

A profile target object will filter the messages stored by \Yiisoft\Profiler\Target\Profiler according to its Yiisoft\Profiler\Target\AbstractTarget::include() and Yiisoft\Profiler\Target\AbstractTarget::exclude().

Protected Methods

Hide inherited methods

Method Description Defined By
filterMessages() Filters the given messages according to their categories. Yiisoft\Profiler\Target\AbstractTarget

Method Details

Hide inherited methods

collect() public method

Processes the given log messages.

This method will filter the given messages with include() and exclude(). And if requested, it will also export the filtering result to specific medium (e.g. email).

public collect( array $messages ): void
$messages array

Profiling messages to be processed.

Each message has the following keys:

  • token: string, profiling token.
  • level: string, message category.
  • beginTime: float, profiling begin timestamp obtained by microtime(true).
  • endTime: float, profiling end timestamp obtained by microtime(true).
  • duration: float, profiling block duration in milliseconds.
  • beginMemory: int, memory usage at the beginning of profile block in bytes, obtained by memory_get_usage().
  • endMemory: int, memory usage at the end of profile block in bytes, obtained by memory_get_usage().
  • memoryDiff: int, a diff between 'endMemory' and 'beginMemory'.

                public function collect(array $messages): void
{
    if (!$this->enabled) {
        return;
    }
    $messages = $this->filterMessages($messages);
    if (count($messages) > 0) {
        $this->export($messages);
    }
}

            
enable() public method

Enable or disable target.

public enable( boolean $value true ): void
$value boolean

                public function enable(bool $value = true): void
{
    $this->enabled = $value;
}

            
exclude() public method

public exclude( string[] $exclude ): $this
$exclude string[]

List of message categories that this target is NOT interested in. Defaults to empty, meaning no uninteresting messages.

If this property is not empty, then any category listed here will be excluded from include(). You can use an asterisk at the end of a category so that the category can be used to match those categories sharing the same common prefix. For example, 'Yiisoft\Db**' will match categories starting with 'Yiisoft\Db\', such as Yiisoft\Db\Connection.

                public function exclude(array $exclude): self
{
    $new = clone $this;
    $new->exclude = $exclude;
    return $new;
}

            
export() public abstract method

Exports profiling messages to a specific destination.

Child classes must implement this method.

public abstract export( Yiisoft\Profiler\Message[] $messages ): void
$messages Yiisoft\Profiler\Message[]

Profiling messages to be exported.

                abstract public function export(array $messages): void;

            
filterMessages() protected method

Filters the given messages according to their categories.

protected filterMessages( Yiisoft\Profiler\Message[] $messages ): Yiisoft\Profiler\Message[]
$messages Yiisoft\Profiler\Message[]

Messages to be filtered. The message structure follows that in Yiisoft\Profiler\Target\TargetInterface::collect().

return Yiisoft\Profiler\Message[]

The filtered messages.

                protected function filterMessages(array $messages): array
{
    foreach ($messages as $i => $message) {
        if (!$this->isCategoryMatched($message->level())) {
            unset($messages[$i]);
        }
    }
    return $messages;
}

            
include() public method

See also \Yiisoft\Strings\WildcardPattern.

public include( string[] $include ): $this
$include string[]

List of message categories that this target is interested in. Defaults to empty, meaning all categories.

You can use an asterisk at the end of a category so that the category may be used to match those categories sharing the same common prefix. For example, 'Yiisoft\Db**' will match categories starting with 'Yiisoft\Db\', such as Yiisoft\Db\Connection.

                public function include(array $include): self
{
    $new = clone $this;
    $new->include = $include;
    return $new;
}

            
isEnabled() public method

Returns target is enabled.

public isEnabled( ): boolean

                public function isEnabled(): bool
{
    return $this->enabled;
}