From 8038a849691f6ab8477a5df94cddb4e0af5b670d Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sun, 3 Jul 2022 15:49:18 +0100 Subject: [PATCH] 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. --- ext/opcache/jit/zend_jit_perf_dump.c | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ext/opcache/jit/zend_jit_perf_dump.c b/ext/opcache/jit/zend_jit_perf_dump.c index 32ba5cd934544..bf4cfbf947a28 100644 --- a/ext/opcache/jit/zend_jit_perf_dump.c +++ b/ext/opcache/jit/zend_jit_perf_dump.c @@ -26,6 +26,7 @@ #include #include +#if !defined(__APPLE__) #if defined(__linux__) #include #elif defined(__darwin__) @@ -274,3 +275,45 @@ static void zend_jit_perf_map_register(const char *name, void *start, size_t siz } fprintf(fp, "%zx %zx %s\n", (size_t)(uintptr_t)start, size, name); } +#else +#include +#include + +static os_log_t jitdump_fd; +static os_signpost_id_t jitdump_sp = OS_SIGNPOST_ID_NULL; + +static void zend_jit_perf_jitdump_open(void) +{ + /** + * The `os_log_t` list per namespace is maintained by the os + * and are not deallocated by (and not deallocatable) + * but are reusable. + */ + jitdump_fd = os_log_create("net.php.opcache.jit", OS_LOG_CATEGORY_POINTS_OF_INTEREST); + jitdump_sp = os_signpost_id_generate(jitdump_fd); + + if (jitdump_sp != OS_SIGNPOST_ID_NULL && jitdump_sp != OS_SIGNPOST_ID_INVALID) { + os_signpost_interval_begin(jitdump_fd, jitdump_sp, "zend_jitdump"); + } +} + +static void zend_jit_perf_jitdump_close(void) +{ + if (jitdump_sp != OS_SIGNPOST_ID_NULL && jitdump_sp != OS_SIGNPOST_ID_INVALID) { + os_signpost_interval_end(jitdump_fd, jitdump_sp, "zend_jitdump"); + } +} + +static void zend_jit_perf_jitdump_register(const char *name, void *start, size_t size) +{ +} + +static void zend_jit_perf_map_register(const char *name, void *start, size_t size) +{ + os_signpost_id_t map = os_signpost_id_make_with_pointer(jitdump_fd, start); + if (map != OS_SIGNPOST_ID_NULL && map != OS_SIGNPOST_ID_INVALID) { + os_signpost_event_emit(jitdump_fd, map, "zend_jitdump_name", "%s", name); + os_signpost_event_emit(jitdump_fd, map, "zend_jitdump_size", "%lu", size); + } +} +#endif