Documentation

Profiling
in package

Performance profiling.

A profile item has several properties:

  • token: a message, usually the thing being profiled
  • category: something to group by
  • trace: stack trace, if enabled (config.max_trace)
  • time: time at which the item was created
  • duration: duration of the profile item
  • memory: memory at the time of capture (end)
  • memory_delta: memory difference over the profile
  • meta: extra user data
  • request.tag: a unique ID (SPROUT_REQUEST_TAG, uuid v4)
  • request.time: when the request began (SPROUT_REQUEST_TIME)
  • request.duration: duration of the whole request (until shutdown)
  • request.ip: remote IP address
  • request.agent: browser user agent
  • request.url: URL request (from Router::current_uri)
  • request.index: the profile item index of the current request

Table of Contents

Constants

DEFAULT  : mixed = [ 'enabled' => false, 'path' => STORAGE_PATH ....
Default config.

Properties

$active  : array<string|int, array<string|int, mixed>>
$logs  : array<string|int, array<string|int, mixed>>
$_config  : null|array<string|int, mixed>
$_enabled  : null|bool
$_registered  : bool

Methods

backtrace()  : string
Displays nice backtrace information.
begin()  : void
Begin a profile section.
clear()  : void
Delete the profiler log.
end()  : void
Commit a profile section.
flush()  : void
Write the log.
getConfig()  : array<string|int, mixed>
Get the profiling config.
isEnabled()  : bool
Is the profiler enabled?
isEnabledForUrl()  : bool
Is the profiler enabled for this URL?
load()  : Generator<string|int, array<string|int, mixed>>
Load the profiler log.
loadItem()  : array<string|int, mixed>|null
Load a single item from the profiler log.
setEnabled()  : bool
Enable or disable the profiler.
setEnabledSession()  : void
Enable profiling for this session.
trim()  : void
Trim the profiler log to the 'max_size' config.
getTrace()  : array<string|int, array<string|int, mixed>>
Get a limited backtrace.
init()  : bool
Initialise things - this registers the flush method on shutdown.

Constants

DEFAULT

Default config.

public mixed DEFAULT = [ 'enabled' => false, 'path' => STORAGE_PATH . 'logs/profile.log', 'max_trace' => 10, 'max_size' => 1024 * 1024 * 20, // 20mb 'url_filter' => '!^admin|dbtools|_media!', ]

Properties

$active

protected static array<string|int, array<string|int, mixed>> $active = []

[ key => array ]

$logs

protected static array<string|int, array<string|int, mixed>> $logs = []

$_config

private static null|array<string|int, mixed> $_config

$_enabled

private static null|bool $_enabled = null

$_registered

private static bool $_registered = false

Methods

backtrace()

Displays nice backtrace information.

public static backtrace(array<string|int, mixed> $trace) : string
Parameters
$trace : array<string|int, mixed>

Generated by an exception or debug_backtrace

Tags
see
http://php.net/debug_backtrace
Return values
string

begin()

Begin a profile section.

public static begin(string $token, string $category[, array<string|int, mixed> $meta = [] ]) : void

The begin/end pair are joined by a common token + category.

Parameters
$token : string
$category : string
$meta : array<string|int, mixed> = []

optional extra data

end()

Commit a profile section.

public static end(string $token, string $category) : void
Parameters
$token : string
$category : string

flush()

Write the log.

public static flush() : void

Note, this is called automatically on shutdown.

Tags
throws
Kohana_Exception

getConfig()

Get the profiling config.

public static getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

isEnabled()

Is the profiler enabled?

public static isEnabled() : bool
Return values
bool

isEnabledForUrl()

Is the profiler enabled for this URL?

public static isEnabledForUrl(string $url) : bool
Parameters
$url : string
Return values
bool

load()

Load the profiler log.

public static load() : Generator<string|int, array<string|int, mixed>>

TODO support for loading items in reverse.

Tags
throws
Kohana_Exception
Return values
Generator<string|int, array<string|int, mixed>>

loadItem()

Load a single item from the profiler log.

public static loadItem(int $index) : array<string|int, mixed>|null

The 'index' is a pointer offset.

Parameters
$index : int
Tags
throws
Kohana_Exception
Return values
array<string|int, mixed>|null

setEnabled()

Enable or disable the profiler.

public static setEnabled(bool $enabled) : bool

Note, this doesn't guarantee that the profiler will be enabled, as it may be disabled by the 'url_filter' config.

Parameters
$enabled : bool
Return values
bool

setEnabledSession()

Enable profiling for this session.

public static setEnabledSession(int $level) : void

This can override config settings to enable per-session profiling in production environments. It does not override URL filter rules.

Parameters
$level : int
Return values
void —
  • 0: disabled
  • 1: enabled
  • other: inherit

trim()

Trim the profiler log to the 'max_size' config.

public static trim() : void

Note, this trims backwards - the new first item will be 100% mangled.

Tags
throws
Kohana_Exception

getTrace()

Get a limited backtrace.

protected static getTrace() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>> —

[ function, class, type, file, line ]

init()

Initialise things - this registers the flush method on shutdown.

protected static init() : bool
Return values
bool —

is profiling enabled?

On this page

Search results