Skip to content

Commit eed3764

Browse files
committed
Profiler v2
1 parent 69c93d7 commit eed3764

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,32 +103,32 @@ Example of output:
103103

104104
1. Using timers tool
105105
```php
106-
\SimpleProfiler\Profiler::start('someName');
106+
\SimpleProfiler\Profiler::startTimer('someName');
107107

108108
// some code
109109

110-
\SimpleProfiler\Profiler::stop('someName');
110+
\SimpleProfiler\Profiler::stopTimer('someName');
111111
```
112112

113113
For grouping times use dot `.` as separator for group and name.
114114
Example of grouping calculation please see above.
115115

116116
```php
117-
\SimpleProfiler\Profiler::start('Group1.someName');
117+
\SimpleProfiler\Profiler::startTimer('Group1.someName');
118118

119119
// some code
120120

121-
\SimpleProfiler\Profiler::stop('Group1.someName');
121+
\SimpleProfiler\Profiler::stopTimer('Group1.someName');
122122
```
123123

124124
2. Using counter tool
125125

126126
For collection count of some event just use next code
127127
```php
128-
\SimpleProfiler\Profiler::count('Counter_of_some_event');
128+
\SimpleProfiler\Profiler::counter('Counter_of_some_event');
129129

130130
// second paramenet is count of increment
131-
\SimpleProfiler\Profiler::count('Counter_of_some_event', 3);
131+
\SimpleProfiler\Profiler::counter('Counter_of_some_event', 3);
132132
```
133133

134134
### Composer

src/SimpleProfiler/Profiler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function clear() {
5555
/**
5656
* @param string $name
5757
*/
58-
public static function start($name) {
58+
public static function startTimer($name) {
5959
self::$timerNames[] = $name;
6060
$time = microtime(true);
6161

@@ -72,7 +72,7 @@ public static function start($name) {
7272
/**
7373
* @param string|null $name
7474
*/
75-
public static function stop($name = null) {
75+
public static function stopTimer($name = null) {
7676
$time = microtime(true);
7777
if (!$name) {
7878
$name = array_pop(self::$timerNames);
@@ -89,7 +89,7 @@ public static function stop($name = null) {
8989
* @param string $name
9090
* @param int $count
9191
*/
92-
public static function count($name, $count = 1) {
92+
public static function counter($name, $count = 1) {
9393
if (isset(self::$counters[$name])) {
9494
self::$counters[$name] += $count;
9595
} else {

src/SimpleProfiler/Timer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Timer {
2121
* @param string $method
2222
*/
2323
public function __construct($method) {
24-
Profiler::start($this->method = $method);
24+
Profiler::startTimer($this->method = $method);
2525
}
2626

2727
public function __destruct() {
28-
Profiler::stop($this->method);
28+
Profiler::stopTimer($this->method);
2929
}
3030
}

tests/Unit/ProfilerTest.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ protected function checkTimer($name, $count, $full_time, $average_time, $actual)
3232
}
3333

3434
public function testCommonSimple() {
35-
Profiler::start('foo');
35+
Profiler::startTimer('foo');
3636
sleep(1);
37-
Profiler::stop();
37+
Profiler::stopTimer();
3838

3939
$result = Profiler::getTimerStat();
4040

@@ -43,17 +43,17 @@ public function testCommonSimple() {
4343
}
4444

4545
public function testCommonSimple2() {
46-
Profiler::start('foo');
46+
Profiler::startTimer('foo');
4747
usleep(300000);
48-
Profiler::stop();
48+
Profiler::stopTimer();
4949

50-
Profiler::start('bar');
50+
Profiler::startTimer('bar');
5151
usleep(200000);
52-
Profiler::stop();
52+
Profiler::stopTimer();
5353

54-
Profiler::start('bar');
54+
Profiler::startTimer('bar');
5555
usleep(100000);
56-
Profiler::stop();
56+
Profiler::stopTimer();
5757

5858
$result = Profiler::getTimerStat();
5959

@@ -64,12 +64,12 @@ public function testCommonSimple2() {
6464

6565
public function testCommonGroups() {
6666
for ($i = 0; $i < 10; ++$i) {
67-
Profiler::start('group.foo');
67+
Profiler::startTimer('group.foo');
6868
usleep(10000);
69-
Profiler::stop();
70-
Profiler::start('group.bar');
69+
Profiler::stopTimer();
70+
Profiler::startTimer('group.bar');
7171
usleep(15000);
72-
Profiler::stop();
72+
Profiler::stopTimer();
7373
}
7474

7575
$result = Profiler::getTimerStat();
@@ -81,12 +81,12 @@ public function testCommonGroups() {
8181

8282
public function testCommonGroups2() {
8383
for ($i = 0; $i < 10; ++$i) {
84-
Profiler::start('foo.one');
84+
Profiler::startTimer('foo.one');
8585
usleep(10000);
86-
Profiler::stop();
87-
Profiler::start('bar.one');
86+
Profiler::stopTimer();
87+
Profiler::startTimer('bar.one');
8888
usleep(15000);
89-
Profiler::stop();
89+
Profiler::stopTimer();
9090
}
9191

9292
$result = Profiler::getTimerStat();
@@ -97,12 +97,12 @@ public function testCommonGroups2() {
9797
}
9898

9999
public function testCounter1() {
100-
Profiler::count('foo');
101-
Profiler::count('bar');
102-
Profiler::count('par');
103-
Profiler::count('foo');
104-
Profiler::count('foo');
105-
Profiler::count('bar', 3);
100+
Profiler::counter('foo');
101+
Profiler::counter('bar');
102+
Profiler::counter('par');
103+
Profiler::counter('foo');
104+
Profiler::counter('foo');
105+
Profiler::counter('bar', 3);
106106

107107
$this->assertSame([
108108
['name' => 'foo', 'count' => 3],
@@ -152,8 +152,6 @@ public function testProfilerCode() {
152152
array_keys($data['Profiler'])
153153
);
154154

155-
print_r(Profiler::getLog());
156-
157155
$this->assertSame(1, $data['Profiler']['SimpleProfiler\Tests\{closure}#1a']['count']);
158156
$this->assertSame(1, $data['Profiler']['SimpleProfiler\Tests\bar']['count']);
159157
$this->assertSame(10, $data['Profiler']['SimpleProfiler\Tests\TestClass::anonymous']['count']);

0 commit comments

Comments
 (0)