Skip to content

Commit 8d7e1a9

Browse files
committed
Add Excimer extension stubs
1 parent 4a38b62 commit 8d7e1a9

File tree

8 files changed

+413
-0
lines changed

8 files changed

+413
-0
lines changed

PhpStormStubsMap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ final class PhpStormStubsMap
537537
'EventSslContext' => 'event/event.php',
538538
'EventUtil' => 'event/event.php',
539539
'Exception' => 'Core/Core_c.php',
540+
'ExcimerLog' => 'excimer/ExcimerLog.php',
541+
'ExcimerLogEntry' => 'excimer/ExcimerLogEntry.php',
542+
'ExcimerProfiler' => 'excimer/ExcimerProfiler.php',
543+
'ExcimerTimer' => 'excimer/ExcimerTimer.php',
540544
'FANNConnection' => 'fann/fann.php',
541545
'FFI' => 'FFI/FFI.php',
542546
'FFI\\CData' => 'FFI/FFI.php',
@@ -2402,6 +2406,7 @@ final class PhpStormStubsMap
24022406
'event_timer_new' => 'libevent/libevent.php',
24032407
'event_timer_pending' => 'libevent/libevent.php',
24042408
'event_timer_set' => 'libevent/libevent.php',
2409+
'excimer_set_timeout' => 'excimer/globals.php',
24052410
'exec' => 'standard/standard_2.php',
24062411
'exif_imagetype' => 'exif/exif.php',
24072412
'exif_read_data' => 'exif/exif.php',
@@ -7602,6 +7607,8 @@ final class PhpStormStubsMap
76027607
'EV_SIGNAL' => 'libevent/libevent.php',
76037608
'EV_TIMEOUT' => 'libevent/libevent.php',
76047609
'EV_WRITE' => 'libevent/libevent.php',
7610+
'EXCIMER_CPU' => 'excimer/globals.php',
7611+
'EXCIMER_REAL' => 'excimer/globals.php',
76057612
'EXIF_USE_MBSTRING' => 'exif/exif.php',
76067613
'EXP_EOF' => 'expect/expect.php',
76077614
'EXP_EXACT' => 'expect/expect.php',

excimer/ExcimerLog.php

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<?php
2+
3+
/**
4+
* A collected series of stack traces and some utility methods to aggregate them.
5+
*
6+
* ExcimerLog acts as a container for ExcimerLogEntry objects. The Iterator or
7+
* ArrayAccess interfaces may be used to access them. For example:
8+
*
9+
* foreach ($profiler->getLog() as $entry) {
10+
* var_dump($entry->getTrace());
11+
* }
12+
*/
13+
class ExcimerLog implements ArrayAccess, Iterator
14+
{
15+
/**
16+
* ExcimerLog is not constructible by user code. Objects of this type
17+
* are available via:
18+
* - ExcimerProfiler::getLog()
19+
* - ExcimerProfiler::flush()
20+
* - The callback to ExcimerProfiler::setFlushCallback()
21+
*/
22+
final private function __construct() {}
23+
24+
/**
25+
* Aggregate the stack traces and convert them to a line-based format
26+
* understood by Brendan Gregg's FlameGraph utility. Each stack trace is
27+
* represented as a series of function names, separated by semicolons.
28+
* After this identifier, there is a single space character, then a number
29+
* giving the number of times the stack appeared. Then there is a line
30+
* break. This is repeated for each unique stack trace.
31+
*
32+
* @return string
33+
*/
34+
public function formatCollapsed() {}
35+
36+
/**
37+
* Produce an array with an element for every function which appears in
38+
* the log. The key is a human-readable unique identifier for the function,
39+
* method or closure. The value is an associative array with the following
40+
* elements:
41+
*
42+
* - self: The number of events in which the function itself was running,
43+
* no other userspace function was being called. This includes time
44+
* spent in internal functions that this function called.
45+
* - inclusive: The number of events in which this function appeared
46+
* somewhere in the stack.
47+
*
48+
* And optionally the following elements, if they are relevant:
49+
*
50+
* - file: The filename in which the function appears
51+
* - line: The exact line number at which the first relevant event
52+
* occurred.
53+
* - class: The class name in which the method is defined
54+
* - function: The name of the function or method
55+
* - closure_line: The line number at which the closure was defined
56+
*
57+
* The event counts in the "self" and "inclusive" fields are adjusted for
58+
* overruns. They represent an estimate of the number of profiling periods
59+
* in which those functions were present.
60+
*
61+
* @return array
62+
*/
63+
public function aggregateByFunction() {}
64+
65+
/**
66+
* Get an array which can be JSON encoded for import into speedscope
67+
*
68+
* @return array
69+
*/
70+
public function getSpeedscopeData() {}
71+
72+
/**
73+
* Get the total number of profiling periods represented by this log.
74+
*
75+
* @return int
76+
*/
77+
public function getEventCount() {}
78+
79+
/**
80+
* Get the current ExcimerLogEntry object. Part of the Iterator interface.
81+
*
82+
* @return ExcimerLogEntry|null
83+
*/
84+
public function current() {}
85+
86+
/**
87+
* Get the current integer key or null. Part of the Iterator interface.
88+
*
89+
* @return int|null
90+
*/
91+
public function key() {}
92+
93+
/**
94+
* Advance to the next log entry. Part of the Iterator interface.
95+
*/
96+
public function next() {}
97+
98+
/**
99+
* Rewind back to the first log entry. Part of the Iterator interface.
100+
*/
101+
public function rewind() {}
102+
103+
/**
104+
* Check if the current position is valid. Part of the Iterator interface.
105+
*
106+
* @return bool
107+
*/
108+
public function valid() {}
109+
110+
/**
111+
* Get the number of log entries contained in this log. This is always less
112+
* than or equal to the number returned by getEventCount(), which includes
113+
* overruns.
114+
*
115+
* @return int
116+
*/
117+
public function count() {}
118+
119+
/**
120+
* Determine whether a log entry exists at the specified array offset.
121+
* Part of the ArrayAccess interface.
122+
*
123+
* @param int $offset
124+
* @return bool
125+
*/
126+
public function offsetExists($offset) {}
127+
128+
/**
129+
* Get the ExcimerLogEntry object at the specified array offset.
130+
*
131+
* @param int $offset
132+
* @return ExcimerLogEntry|null
133+
*/
134+
public function offsetGet($offset) {}
135+
136+
/**
137+
* This function is included for compliance with the ArrayAccess interface.
138+
* It raises a warning and does nothing.
139+
*
140+
* @param int $offset
141+
* @param mixed $value
142+
*/
143+
public function offsetSet($offset, $value) {}
144+
145+
/**
146+
* This function is included for compliance with the ArrayAccess interface.
147+
* It raises a warning and does nothing.
148+
*
149+
* @param int $offset
150+
*/
151+
public function offsetUnset($offset) {}
152+
}

excimer/ExcimerLogEntry.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
class ExcimerLogEntry
4+
{
5+
/**
6+
* ExcimerLogEntry is not constructible by user code.
7+
*/
8+
final private function __construct() {}
9+
10+
/**
11+
* Get the time at which the event occurred. This is the floating point
12+
* number of seconds since the ExcimerProfiler object was constructed.
13+
*
14+
* @return float
15+
*/
16+
public function getTimestamp() {}
17+
18+
/**
19+
* Get the event count represented by this log entry. This will typically
20+
* be 1. If there were overruns, it will be 1 plus the number of overruns.
21+
*
22+
* @return int
23+
*/
24+
public function getEventCount() {}
25+
26+
/**
27+
* Get an array of associative arrays describing the stack trace at the time
28+
* of the event. The first element in the array is the function which was
29+
* executing, the second function is the caller (parent) of that function,
30+
* and so on. Each element is an associative array with the following
31+
* optional fields:
32+
*
33+
* - file: The filename in which the function appears
34+
* - line: The exact line number at which the event occurred.
35+
* - class: The class name in which the method is defined
36+
* - function: The name of the function or method
37+
* - closure_line: The line number at which the closure was defined
38+
*
39+
* @return array
40+
*/
41+
public function getTrace() {}
42+
}

excimer/ExcimerProfiler.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* A sampling profiler.
5+
*
6+
* Collects a stack trace every time a timer event fires.
7+
*/
8+
class ExcimerProfiler
9+
{
10+
/**
11+
* Set the period.
12+
*
13+
* This will take effect the next time start() is called.
14+
*
15+
* If this method is not called, the default period of 0.1 seconds
16+
* will be used.
17+
*
18+
* @param float $period The period in seconds
19+
*/
20+
public function setPeriod($period) {}
21+
22+
/**
23+
* Set the event type. May be either EXCIMER_REAL, for real (wall-clock)
24+
* time, or EXCIMER_CPU, for CPU time. The default is EXCIMER_REAL.
25+
*
26+
* This will take effect the next time start() is called.
27+
*
28+
* @param int $eventType
29+
*/
30+
public function setEventType($eventType) {}
31+
32+
/**
33+
* Set the maximum depth of stack trace collection. If this depth is
34+
* exceeded, the traversal up the stack will be terminated, so the function
35+
* will appear to have no caller.
36+
*
37+
* By default, there is no limit. If this is called with a depth of zero,
38+
* the limit is disabled.
39+
*
40+
* This will take effect immediately.
41+
*
42+
* @param int $maxDepth
43+
*/
44+
public function setMaxDepth($maxDepth) {}
45+
46+
/**
47+
* Set a callback which will be called once the specified number of samples
48+
* has been collected.
49+
*
50+
* When the ExcimerProfiler object is destroyed, the callback will also
51+
* be called, unless no samples have been collected.
52+
*
53+
* The callback will be called with a single argument: the ExcimerLog
54+
* object containing the samples. Before the callback is called, a new
55+
* ExcimerLog object will be created and registered with the
56+
* ExcimerProfiler. So ExcimerProfiler::getLog() should not be used from
57+
* the callback, since it will not return the samples.
58+
*
59+
* @param callable $callback
60+
* @param int $maxSamples
61+
*/
62+
public function setFlushCallback($callback, $maxSamples) {}
63+
64+
/**
65+
* Clear the flush callback. No callback will be called regardless of
66+
* how many samples are collected.
67+
*/
68+
public function clearFlushCallback() {}
69+
70+
/**
71+
* Start the profiler. If the profiler was already running, it will be
72+
* stopped and restarted with new options.
73+
*/
74+
public function start() {}
75+
76+
/**
77+
* Stop the profiler.
78+
*/
79+
public function stop() {}
80+
81+
/**
82+
* Get the current ExcimerLog object.
83+
*
84+
* Note that if the profiler is running, the object thus returned may be
85+
* modified by a timer event at any time, potentially invalidating your
86+
* analysis. Instead, the profiler should be stopped first, or flush()
87+
* should be used.
88+
*
89+
* @return ExcimerLog
90+
*/
91+
public function getLog() {}
92+
93+
/**
94+
* Create and register a new ExcimerLog object, and return the old
95+
* ExcimerLog object.
96+
*
97+
* This will return all accumulated events to this point, and reset the
98+
* log with a new log of zero length.
99+
*
100+
* @return ExcimerLog
101+
*/
102+
public function flush() {}
103+
}

0 commit comments

Comments
 (0)