RFR: 7903740: JMH: Perf event validation not working with skid options [v4]
Galder Zamarreño
galder at openjdk.org
Thu Aug 22 12:49:16 UTC 2024
On Thu, 22 Aug 2024 12:09:28 GMT, Galder Zamarreño <galder at openjdk.org> wrote:
>> jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java line 57:
>>
>>> 55:
>>> 56: for (String ev : requestedEventNames) {
>>> 57: String reportCmd = String.format("perf report -i perf-record-validate.data --stdio | grep %s | wc -l", ev);
>>
>> Why can't we just use `perf record --event $requestedEventNames --output $tempdir echo 1`? I think that would be enough to sense if events are supported? There is no need to call into `perf report` then.
>
>> Why can't we just use perf record --event $requestedEventNames --output $tempdir echo 1?
>
> I couldn't find a reliable way that worked bare metal and on CI that would allow me to inspect the output of that and validate whether it worked or not. I've only been able to make it work in all environments by explicitly adding an output file (with `-i`) and then using `perf report` to verify its contents.
>
> What are the issues I had? If you look at the commit series you can see the progression of trial/error.
>
> First I tried to use `perf record` and see if I could just parse its output to see if could find a way to make sure it worked fine. I tried the approach [here](https://github.com/galderz/jmh/blob/2a9380664f9dd667fa10fe08b12d5c7e97c58b95/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java#L58), but that didn't work on [CI run](https://github.com/openjdk/jmh/runs/28853969690) for it. I'm not 100% sure why it didn't work, but I found odd that there was so much additional output in the `perf record` output, see my tests [here](https://github.com/galderz/github-actions/actions/runs/10417234664/job/28851057186).
>
> After some tests I realised that the additional output in `perf record` is the output that normally goes into `perf.data` file but on CI that does not happen. Instead the output goes to standard output.
>
> So, if the output of `perf record` cannot really be used to determine the outcome, I decided to combine it with `perf report`. Also, I explicitly added the `-i` parameter to add an output file and avoid the mangling of the output.
>
> Eventually I narrowed down the solution to the combination of `perf record` and `perf report` commands that you see in this [GH action](https://github.com/galderz/github-actions/actions/runs/10418351274/job/28854335728) of mine. That's the logic I applied to the code here and seems to work as expected.
Also note what happens [here](https://github.com/galderz/github-actions/actions/runs/10418351274/job/28854335728).
The command executed is:
$ perf record --event cycles --output perf-record-validate.data echo 1
And the output contains:
[ perf record: Captured and wrote 0.001 MB perf-record-validate.data (3 samples) ]
So you can't use my logic [here](https://github.com/galderz/jmh/blob/2a9380664f9dd667fa10fe08b12d5c7e97c58b95/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java#L58) to decide whether perf record worked or not by checking if the output has `[ perf record: Captured and wrote 0.000 MB (null) ]`. So, how do you expect to sense that the perf record command worked from that alone?
-------------
PR Review Comment: https://git.openjdk.org/jmh/pull/132#discussion_r1726987732
More information about the jmh-dev
mailing list