diff --git a/DiSLProject2022/src-profiler/ex11/Profiler.java b/DiSLProject2022/src-profiler/ex11/Profiler.java index f0e0db4..d2bd75d 100644 --- a/DiSLProject2022/src-profiler/ex11/Profiler.java +++ b/DiSLProject2022/src-profiler/ex11/Profiler.java @@ -7,9 +7,10 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.atomic.LongAdder; public final class Profiler { - private static final Map count = new HashMap<>(); + private static final Map count = new HashMap<>(); private static final Path outFile = Path.of("ex11.csv"); @@ -18,11 +19,11 @@ public final class Profiler { static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { stop = true; - try (final OutputStream path = Files.newOutputStream(outFile, StandardOpenOption.WRITE)) { + try (final OutputStream path = Files.newOutputStream(outFile)) { final CallInfoCSVWriter w = new CallInfoCSVWriter(path); for (final var entry : count.entrySet()) { - System.out.println(entry.getKey().toString() + "\n#invokes " + entry.getValue()[0] + "\n"); - w.write(entry.getKey(), entry.getValue()[0]); + System.out.println(entry.getKey().toString() + "\n#invokes " + entry.getValue().longValue() + "\n"); + w.write(entry.getKey(), entry.getValue().longValue()); } System.out.println("Invocations have been written to: " + outFile.toAbsolutePath()); } catch (final IOException e) { @@ -36,7 +37,7 @@ public final class Profiler { public static void registerCall(final CallInfo info) { if (stop) return; - count.computeIfAbsent(info, ignored -> new long[1])[0]++; + count.computeIfAbsent(info, ignored -> new LongAdder()).increment(); } }