From 618230b958d7822985e2702cd9528f1b4567e59c Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 4 Sep 2022 10:53:06 +0100 Subject: Improve debug output when JFR parsing fails --- .../spark/common/sampler/async/AsyncSampler.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'spark-common/src/main/java/me/lucko/spark') diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java index d8288da..dae3852 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncSampler.java @@ -185,8 +185,19 @@ public class AsyncSampler extends AbstractSampler { // read the jfr file produced by async-profiler try (JfrReader reader = new JfrReader(this.outputFile)) { readSegments(reader, threadFilter); - } catch (IOException e) { - throw new RuntimeException("Read error", e); + } catch (Exception e) { + boolean fileExists; + try { + fileExists = Files.exists(this.outputFile) && Files.size(this.outputFile) != 0; + } catch (IOException ex) { + fileExists = false; + } + + if (fileExists) { + throw new JfrParsingException("Error parsing JFR data from profiler output", e); + } else { + throw new JfrParsingException("Error parsing JFR data from profiler output - file " + this.outputFile + " does not exist!", e); + } } // delete the output file after reading @@ -268,4 +279,10 @@ public class AsyncSampler extends AbstractSampler { reader.stackFrames.put(methodId, result); return result; } + + private static final class JfrParsingException extends RuntimeException { + public JfrParsingException(String message, Throwable cause) { + super(message, cause); + } + } } -- cgit