| Server IP : 62.60.133.156 / Your IP : 216.73.217.51 Web Server : LiteSpeed System : Linux linux24.centraldnserver.com 4.18.0-553.141.2.lve.el8.x86_64 #1 SMP Wed Jul 8 16:10:02 UTC 2026 x86_64 User : mimradmin ( 1166) PHP Version : 7.4.33 Disable Function : show_source, system, shell_exec, passthru, exec, popen, proc_open MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/mimradmin/domains/mimra.ir/mimqadim/wp-content/plugins/1query-monitor/classes/ |
Upload File : |
<?php declare(strict_types = 1);
/**
* Timer that collects timing and memory usage.
*
* @package query-monitor
*/
class QM_Timer {
/**
* @var array<string, mixed>
* @phpstan-var array{
* time: float,
* memory: int,
* data: mixed[]|null,
* }
*/
protected $start;
/**
* @var array<string, mixed>|null
* @phpstan-var array{
* time: float,
* memory: int,
* data: mixed[]|null,
* }|null
*/
protected $end = null;
/**
* @var QM_Backtrace
*/
protected $trace;
/**
* @var array<string, array<string, mixed>>
* @phpstan-var array<string, array{
* time: float,
* memory: int,
* data: mixed[]|null,
* }>
*/
protected $laps = array();
/**
* @param mixed[] $data
* @return self
*/
public function start( ?array $data = null ) {
$this->trace = new QM_Backtrace();
$this->start = array(
'time' => microtime( true ),
'memory' => memory_get_usage(),
'data' => $data,
);
return $this;
}
/**
* @param mixed[] $data
* @return self
*/
public function stop( ?array $data = null ) {
$this->end = array(
'time' => microtime( true ),
'memory' => memory_get_usage(),
'data' => $data,
);
return $this;
}
/**
* @param mixed[] $data
* @param string $name
* @return self
*/
public function lap( ?array $data = null, ?string $name = null ) {
$lap = array(
'time' => microtime( true ),
'memory' => memory_get_usage(),
'data' => $data,
);
if ( ! isset( $name ) ) {
$i = sprintf(
/* translators: %s: Timing lap number */
__( 'Lap %s', 'query-monitor' ),
number_format_i18n( count( $this->laps ) + 1 )
);
} else {
$i = $name;
}
$this->laps[ $i ] = $lap;
return $this;
}
/**
* @return mixed[]
*/
public function get_laps() {
$laps = array();
$prev = $this->start;
foreach ( $this->laps as $lap_id => $lap ) {
$lap['time_used'] = $lap['time'] - $prev['time'];
$lap['memory_used'] = $lap['memory'] - $prev['memory'];
$laps[ $lap_id ] = $lap;
$prev = $lap;
}
return $laps;
}
/**
* @return float
*/
public function get_time() {
return $this->end['time'] - $this->start['time'];
}
/**
* @return int
*/
public function get_memory() {
return $this->end['memory'] - $this->start['memory'];
}
/**
* @return float
*/
public function get_start_time() {
return $this->start['time'];
}
/**
* @return int
*/
public function get_start_memory() {
return $this->start['memory'];
}
/**
* @return float
*/
public function get_end_time() {
return $this->end['time'];
}
/**
* @return int
*/
public function get_end_memory() {
return $this->end['memory'];
}
/**
* @return QM_Backtrace
*/
public function get_trace() {
return $this->trace;
}
/**
* @param mixed[] $data
* @return self
*/
public function end( ?array $data = null ) {
return $this->stop( $data );
}
}