Skip to content

Commit c56e183

Browse files
committed
opcache JIT: Adds initial support for macOs Instruments performance measurement.
By default, it is based on the perf_event Linux api, here we add the proprietary Apple's format using directly its api. Closes #8914.
1 parent d6fc165 commit c56e183

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PHP NEWS
2222
. Added access.suppress_path pool option to filter access log entries.
2323
(Mark Gallagher)
2424

25+
- Opcache:
26+
. Added initial support for JIT performance profiling generatio
27+
for macOs Instrument. (David Carlier)
28+
2529
- PCRE:
2630
. Updated bundled libpcre to 10.40. (cmb)
2731

ext/opcache/jit/zend_jit_perf_dump.c

+43
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/stat.h>
2727
#include <fcntl.h>
2828

29+
#if !defined(__APPLE__)
2930
#if defined(__linux__)
3031
#include <sys/syscall.h>
3132
#elif defined(__darwin__)
@@ -274,3 +275,45 @@ static void zend_jit_perf_map_register(const char *name, void *start, size_t siz
274275
}
275276
fprintf(fp, "%zx %zx %s\n", (size_t)(uintptr_t)start, size, name);
276277
}
278+
#else
279+
#include <os/log.h>
280+
#include <os/signpost.h>
281+
282+
static os_log_t jitdump_fd;
283+
static os_signpost_id_t jitdump_sp = OS_SIGNPOST_ID_NULL;
284+
285+
static void zend_jit_perf_jitdump_open(void)
286+
{
287+
/**
288+
* The `os_log_t` list per namespace is maintained by the os
289+
* and are not deallocated by (and not deallocatable)
290+
* but are reusable.
291+
*/
292+
jitdump_fd = os_log_create("net.php.opcache.jit", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
293+
jitdump_sp = os_signpost_id_generate(jitdump_fd);
294+
295+
if (jitdump_sp != OS_SIGNPOST_ID_NULL && jitdump_sp != OS_SIGNPOST_ID_INVALID) {
296+
os_signpost_interval_begin(jitdump_fd, jitdump_sp, "zend_jitdump");
297+
}
298+
}
299+
300+
static void zend_jit_perf_jitdump_close(void)
301+
{
302+
if (jitdump_sp != OS_SIGNPOST_ID_NULL && jitdump_sp != OS_SIGNPOST_ID_INVALID) {
303+
os_signpost_interval_end(jitdump_fd, jitdump_sp, "zend_jitdump");
304+
}
305+
}
306+
307+
static void zend_jit_perf_jitdump_register(const char *name, void *start, size_t size)
308+
{
309+
}
310+
311+
static void zend_jit_perf_map_register(const char *name, void *start, size_t size)
312+
{
313+
os_signpost_id_t map = os_signpost_id_make_with_pointer(jitdump_fd, start);
314+
if (map != OS_SIGNPOST_ID_NULL && map != OS_SIGNPOST_ID_INVALID) {
315+
os_signpost_event_emit(jitdump_fd, map, "zend_jitdump_name", "%s", name);
316+
os_signpost_event_emit(jitdump_fd, map, "zend_jitdump_size", "%lu", size);
317+
}
318+
}
319+
#endif

0 commit comments

Comments
 (0)