@Setup public void setup() { System.setProperty("java.net.preferIPv4Stack", "true"); System.out.println("Create stage"); stage = createStage(); if (profile) { actorProfiler = new ActorProfiler(); scheduledExecutorService = new ScheduledThreadPoolExecutor(2); scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(() -> { try { actorProfiler.collect(); } catch (Exception ex) { ex.printStackTrace(); } }, 1, 1, TimeUnit.MILLISECONDS); } }
@Setup(Level.Iteration) public void setupIteration() { if (profile) { iteration++; if (iteration < 5) { actorProfiler.clear(); } } }
@TearDown public void tearDown() { stage.stop().join(); if (profile) { scheduledFuture.cancel(false); scheduledExecutorService.shutdownNow(); final long collectionCount = actorProfiler.getCollectionCount(); final Map<Object, ProfilerData> profilerSnapshot = actorProfiler.getProfilerSnapshot(); System.out.printf("collectionCount " + collectionCount); for (Map.Entry<Object, ProfilerData> e : profilerSnapshot.entrySet()) { System.out.println("%%%%%%%%%%%%%%%%%%%%"); System.out.println(e.getKey()); System.out.println("%%%%%%%%%%%%%%%%%%%%"); System.out.println(ProfileDump.textMethodInfo(e.getValue(), collectionCount)); System.out.println("%%%%%%%%%%%%%%%%%%%%"); System.out.println(e.getKey()); System.out.println("%%%%%%%%%%%%%%%%%%%%"); System.out.println(ProfileDump.textDumpCallTree(e.getValue().getCallTree(), collectionCount)); System.out.println(); } } }
collectedData.put(key, profilerData); cleanStackTrack(stackTrace); profilerData.collect(stackTrace);