void (String activityName, boolean withSpan) { myActivityName = activityName; myStartTime = System.currentTimeMillis(); myLongestDelay = new LongAccumulator(Math::max, 0); myHighestCPULoad = 0; myHighestRAMUsage = 0; myTotalRAMUsage.set(0); myTotalCPULoad.set(0); myTotalDelay.set(0); myCounter.set(0); myHWCounter.set(0); executor = ConcurrencyUtil.newSingleScheduledThreadExecutor("Performance plugin timer"); SystemInfo info = new SystemInfo(); int processId = info.getOperatingSystem().getProcessId(); OSProcess process = info.getOperatingSystem().getProcess(processId); executor.scheduleWithFixedDelay(() -> { long before = System.currentTimeMillis(); try { SwingUtilities.invokeAndWait(() -> { }); long after = System.currentTimeMillis(); long delay = after - before; myTotalDelay.addAndGet(delay); myCounter.incrementAndGet(); myLongestDelay.accumulate(delay); } catch (InterruptedException | InvocationTargetException ignored) { } }, 0, 50, TimeUnit.MILLISECONDS); OperatingSystemMXBean bean = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); executor.scheduleWithFixedDelay(() -> { myHWCounter.incrementAndGet(); double cpuLoad = bean.getProcessCpuLoad(); if (cpuLoad > 0 && cpuLoad <= 1) { myTotalCPULoad.addAndGet(Math.round(cpuLoad * 100)); if (myHighestCPULoad < cpuLoad) myHighestCPULoad = cpuLoad; } long ramUsage = process.getResidentSetSize(); myTotalRAMUsage.addAndGet(ramUsage); if (myHighestRAMUsage < ramUsage) myHighestRAMUsage = ramUsage; }, 0, 1, TimeUnit.SECONDS); if(withSpan) { String spanName = activityName.equals("default") ? "timer" : activityName; // We need to set parent or null since it's part of general startup activity //noinspection DataFlowIssue Parent can be null. mySpan = PerformanceTestSpan.TRACER.spanBuilder(spanName).setParent(PerformanceTestSpan.getContext()).startSpan(); } }