From 6da60b9165b29396f87eb3f2295af072f4897022 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Aug 2022 10:24:47 +0200 Subject: [PATCH] Improve output --- src/main/java/de/steamwar/Sampler.java | 21 ++++----------------- src/main/java/de/steamwar/Trace.java | 4 ++-- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/main/java/de/steamwar/Sampler.java b/src/main/java/de/steamwar/Sampler.java index d6fd002..b740049 100644 --- a/src/main/java/de/steamwar/Sampler.java +++ b/src/main/java/de/steamwar/Sampler.java @@ -10,7 +10,7 @@ import java.util.concurrent.locks.LockSupport; public class Sampler { public static final long SAMPLING_SPEED = 1000000; - public static final double FILTER = 0.01; + public static final int FILTER = 10; private static final Set waitingMethods = new HashSet<>(); static { @@ -38,14 +38,9 @@ public class Sampler { omittedMethods.add("java.lang.Iterable.forEach"); omittedMethods.add("java.util.ArrayList.forEach"); omittedMethods.add("java.util.Map.forEach"); - - //TODO: Rework to concrete functions - omittedMethods.add("jdk.internal"); - omittedMethods.add("java.util.stream"); - omittedMethods.add("java.util.Spliterators"); - omittedMethods.add("java.util.ArrayList$ArrayListSpliterator"); - omittedMethods.add("java.util.AbstractList$RandomAccessSpliterator"); - omittedMethods.add("java.util.concurrent"); + omittedMethods.add("java.util.concurrent.ThreadPoolExecutor$Worker.run"); + omittedMethods.add("java.util.concurrent.ThreadPoolExecutor.runWorker"); + omittedMethods.add("java.util.concurrent.CompletableFuture$Completion.run"); } private final Map traces = new HashMap<>(); @@ -93,8 +88,6 @@ public class Sampler { } private void run() { - Thread autoStopper = new Thread(this::stop, "SamplerStop"); - Runtime.getRuntime().addShutdownHook(autoStopper); long lastTime = System.nanoTime(); while(!shutdown) { sample(); @@ -103,12 +96,6 @@ public class Sampler { LockSupport.parkNanos(SAMPLING_SPEED - currentTime + lastTime); lastTime = currentTime; } - - try { - Runtime.getRuntime().removeShutdownHook(autoStopper); - } catch (IllegalStateException e) { - // ignored - } } private void sample() { diff --git a/src/main/java/de/steamwar/Trace.java b/src/main/java/de/steamwar/Trace.java index db0c2ce..5da7fc7 100644 --- a/src/main/java/de/steamwar/Trace.java +++ b/src/main/java/de/steamwar/Trace.java @@ -30,7 +30,7 @@ public class Trace { } private boolean filtered() { - return Arrays.stream(samples).sum() / (double) sampler.getSampleRuns() < Sampler.FILTER; + return Arrays.stream(samples).sum() < Sampler.FILTER; } public void add(Thread.State state, Trace predecessor) { @@ -62,7 +62,7 @@ public class Trace { writer.append(String.valueOf(id)).append(" [fillcolor=\"#").append(String.format("%02X", r)).append(String.format("%02X", g)).append(String.format("%02X", b)).append(String.format("%02X", a)).append("\",label=\"").append(name).append("\\n").append(percentage(ownSampleRuns())).append("% ").append(df.format(ownSampleRuns() * Sampler.SAMPLING_SPEED / 1e9)).append("s\\nR").append(percentage(runnable)).append("% B").append(percentage(blocked)).append("% W").append(percentage(waiting)).append("%\"];\n"); for (Map.Entry entry : predecessors.entrySet()) { - if (entry.getKey().filtered() || entry.getValue() / (double)sampler.getSampleRuns() < Sampler.FILTER) + if (entry.getKey().filtered() || entry.getValue() < Sampler.FILTER) continue; writer.append(String.valueOf(entry.getKey().id)).append(" -> ").append(String.valueOf(id)).append(" [label=\"").append(percentage(entry.getValue())).append("%\",weight=").append(String.valueOf(entry.getValue())).append("];\n");