ts3phpframework
Loading...
Searching...
No Matches
Timer.php
Go to the documentation of this file.
1
<?php
2
3
namespace
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler
;
4
11
class
Timer
12
{
18
protected
bool
$running
=
false
;
19
25
protected
float
$started
= 0;
26
32
protected
string
$name
;
33
39
protected
array
$data
= [];
40
46
public
function
__construct
(
string
$name
)
47
{
48
$this->name =
$name
;
49
50
$this->data[
"runtime"
] = 0;
51
$this->data[
"realmem"
] = 0;
52
$this->data[
"emalloc"
] = 0;
53
54
$this->
start
();
55
}
56
62
public
function
start
(): void
63
{
64
if
($this->
isRunning
()) {
65
return
;
66
}
67
68
$this->data[
"realmem_start"
] = memory_get_usage(
true
);
69
$this->data[
"emalloc_start"
] = memory_get_usage();
70
71
$this->started = microtime(
true
);
72
$this->running =
true
;
73
}
74
80
public
function
stop
(): void
81
{
82
if
(!$this->
isRunning
()) {
83
return
;
84
}
85
86
$this->data[
"runtime"
] += microtime(
true
) -
$this->started
;
87
$this->data[
"realmem"
] += memory_get_usage(
true
) - $this->data[
"realmem_start"
];
88
$this->data[
"emalloc"
] += memory_get_usage() - $this->data[
"emalloc_start"
];
89
90
$this->started = 0;
91
$this->running =
false
;
92
}
93
99
public
function
getRuntime
(): float
100
{
101
if
($this->
isRunning
()) {
102
$this->
stop
();
103
$this->
start
();
104
}
105
106
return
$this->data[
"runtime"
];
107
}
108
115
public
function
getMemUsage
(
bool
$realmem =
false
): int
116
{
117
if
($this->
isRunning
()) {
118
$this->
stop
();
119
$this->
start
();
120
}
121
122
return
($realmem !==
false
) ? $this->data[
"realmem"
] : $this->data[
"emalloc"
];
123
}
124
130
public
function
isRunning
(): bool
131
{
132
return
$this->running
;
133
}
134
}
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer
Helper class providing profiler timers.
Definition
Timer.php:12
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\getMemUsage
getMemUsage(bool $realmem=false)
Definition
Timer.php:115
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\$running
bool $running
Definition
Timer.php:18
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\__construct
__construct(string $name)
Definition
Timer.php:46
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\isRunning
isRunning()
Definition
Timer.php:130
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\stop
stop()
Definition
Timer.php:80
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\getRuntime
getRuntime()
Definition
Timer.php:99
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\$started
float $started
Definition
Timer.php:25
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\$data
array $data
Definition
Timer.php:39
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\$name
string $name
Definition
Timer.php:32
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler\Timer\start
start()
Definition
Timer.php:62
PlanetTeamSpeak\TeamSpeak3Framework\Helper\Profiler
Definition
Timer.php:3
src
Helper
Profiler
Timer.php
Generated by
1.14.0