diff --git a/analysis/src/main/java/org/eclipse/jifa/analysis/listener/DefaultProgressListener.java b/analysis/src/main/java/org/eclipse/jifa/analysis/listener/DefaultProgressListener.java index 5e56cc5e..f4f92c96 100644 --- a/analysis/src/main/java/org/eclipse/jifa/analysis/listener/DefaultProgressListener.java +++ b/analysis/src/main/java/org/eclipse/jifa/analysis/listener/DefaultProgressListener.java @@ -70,6 +70,11 @@ public void sendUserMessage(Level level, String message, Throwable throwable) { append(sw.toString()); } + @Override + public void reset() { + this.total = this.done = 0; + } + @Override public String log() { return log.toString(); diff --git a/analysis/thread-dump/src/main/java/org/eclipse/jifa/tda/parser/SerDesParser.java b/analysis/thread-dump/src/main/java/org/eclipse/jifa/tda/parser/SerDesParser.java index 35600573..26a09956 100644 --- a/analysis/thread-dump/src/main/java/org/eclipse/jifa/tda/parser/SerDesParser.java +++ b/analysis/thread-dump/src/main/java/org/eclipse/jifa/tda/parser/SerDesParser.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -46,38 +47,39 @@ public SerDesParser(Parser parser) { this.parser = parser; } - private Path storage(Path from) { - return Paths.get(from.toFile().getAbsoluteFile() + ".kryo"); - } - @Override public Snapshot parse(Path path, ProgressListener listener) { // TODO: multi-threads support - Path storage = storage(path); - if (storage.toFile().exists()) { + Path serializedDataPath = resolveSerializedDataPath(path); + if (Files.exists(serializedDataPath)) { try { - listener.beginTask("Deserializing thread dump snapshot", 100); - Snapshot snapshot = deserialize(storage); + listener.beginTask("Deserializing thread dump", 100); + Snapshot snapshot = deserialize(serializedDataPath); listener.worked(100); return snapshot; } catch (Throwable t) { - log.error("Deserialize thread dump snapshot failed", t); - listener.sendUserMessage(ProgressListener.Level.WARNING, "Deserialize thread dump snapshot failed", t); + log.error("Failed to deserialize thread dump: {}", t.getMessage()); + listener.sendUserMessage(ProgressListener.Level.WARNING, "Deserialize thread dump failed", t); listener.reset(); } } - listener.beginTask(null, 5); Snapshot snapshot = parser.parse(path, listener); try { - serialize(snapshot, storage); - listener.worked(5); + listener.beginTask("Serializing thread dump", 5); + serialize(snapshot, serializedDataPath); } catch (Throwable t) { - log.error("Serialize snapshot failed", t); + log.warn("Failed to serialize thread dump: {}", t.getMessage()); + } finally { + listener.worked(5); } return snapshot; } + private Path resolveSerializedDataPath(Path source) { + return Paths.get(source.toFile().getAbsoluteFile() + ".kryo"); + } + private void serialize(Snapshot snapshot, Path path) throws FileNotFoundException { Kryo kryo = KRYO.get(); try (Output out = new Output(new FileOutputStream(path.toFile()))) {