RFR: 7903696: JMH: Add xctrace-based perfasm profiler for macOS

Filipp Zhinkin fzhinkin at openjdk.org
Sat Mar 16 22:33:29 UTC 2024


On Sat, 16 Mar 2024 15:49:18 GMT, Filipp Zhinkin <fzhinkin at openjdk.org> wrote:

> Currently, the only perfasm profiler available on macOS is dtraceasm.
> While it serves its purposes well, there are a few shortcomings: dtrace requires superuser privileges and it can only sample by timer interrupts.
> 
> Xcode comes with a performance-analysis tool called Instruments and it has a command-line tool, called xctrace.
> xctrace allows profiling an app using both timer interrupts and PMI, and it does not require superuser privileges.
> 
> This PR brings JMH profilers that uses xctrace on macOS.
> 
> There are two profilers:
> - XCTraceAsmProfiler, a perfasm profiler based on xctrace that works fine out of the box;
> - XCTraceNormProfiler, a perfnorm profiler that requires mandatory parameter, that has to be setup using Instruments UI.
> 
> The latter is added as a PoC and could be wiped out of this PR.
> 
> Unfortunately, `xctrace` exports data in XML format, thus most of the code is responsible for XML parsing.

jmh-core/src/main/java/org/openjdk/jmh/profile/XCTraceAsmProfiler.java line 2:

> 1: /*
> 2:  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.

I was not sure about the copyright header, so plunked the Oracle's one.

jmh-core/src/main/java/org/openjdk/jmh/profile/XCTraceNormProfiler.java line 67:

> 65:  * using Instruments application. Unfortunately, there is no other way to set it up.
> 66:  * <p>
> 67:  * There's no builtin template that could be used with this profiler, thus the template had to be configured and saved

Well, there's a way to make it work almost like `perf stat`, but it involves building a temporary Instruments package, so I didn't dare to post the solution (it lives in a separate branch: https://github.com/openjdk/jmh/commit/ff07cfaf76236486354b51550d50a285df08d7e7) .

jmh-core/src/main/java/org/openjdk/jmh/profile/XCTraceTableHandler.java line 38:

> 36: 
> 37: /**
> 38:  * Base class for SAX handlers responsible for xctrace exported table parsing.

I tried to unleash XSLT to reduce amount of newly added code, but XSLT processing was extremely slow (due to referenced nodes lookup).

-------------

PR Review Comment: https://git.openjdk.org/jmh/pull/130#discussion_r1527192314
PR Review Comment: https://git.openjdk.org/jmh/pull/130#discussion_r1527193129
PR Review Comment: https://git.openjdk.org/jmh/pull/130#discussion_r1527192668


More information about the jmh-dev mailing list