diff --git a/platform/util/api-dump-unreviewed.txt b/platform/util/api-dump-unreviewed.txt index b4696b138508..b166342f44e4 100644 --- a/platform/util/api-dump-unreviewed.txt +++ b/platform/util/api-dump-unreviewed.txt @@ -54,35 +54,6 @@ f:com.intellij.UtilBundle - sf:installThreadContext(kotlin.coroutines.CoroutineContext,Z):com.intellij.openapi.application.AccessToken - bs:installThreadContext$default(kotlin.coroutines.CoroutineContext,Z,I,java.lang.Object):com.intellij.openapi.application.AccessToken - sf:resetThreadContext():com.intellij.openapi.application.AccessToken -c:com.intellij.diagnostic.tracing.MethodTracer -- s:clearAll():V -- s:getAllData():java.util.List -- getCurrentData():com.intellij.diagnostic.tracing.MethodTracerData -- s:getInstance(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String):com.intellij.diagnostic.tracing.MethodTracer -- s:isEnabled():Z -- onMethodEnter():V -- onMethodExit():V -- s:setEnabled(Z):V -f:com.intellij.diagnostic.tracing.MethodTracer$TracerId -- sf:EMPTY:com.intellij.diagnostic.tracing.MethodTracer$TracerId -- (java.lang.String,java.lang.String,java.lang.String,java.lang.String):V -- equals(java.lang.Object):Z -- hashCode():I -f:com.intellij.diagnostic.tracing.MethodTracerData -- f:className:java.lang.String -- f:countOnEdt:J -- f:id:com.intellij.diagnostic.tracing.MethodTracer$TracerId -- f:invocationCount:J -- f:maxRecursionDepth:I -- f:maxTime:J -- f:maxTimeOnEdt:J -- f:methodName:java.lang.String -- f:nonRecursiveCount:J -- f:timeOnEdt:J -- f:totalTime:J -- (com.intellij.diagnostic.tracing.MethodTracer$TracerId,java.lang.String,java.lang.String,J,J,J,J,J,J,J,I):V -- getAvgTime():D -- getAvgTimeEdt():D f:com.intellij.execution.CommandLineUtil - ():V - s:escapeParameterOnWindows(java.lang.String,Z):java.lang.String diff --git a/platform/util/src/com/intellij/diagnostic/tracing/MethodTracer.java b/platform/util/src/com/intellij/diagnostic/tracing/MethodTracer.java deleted file mode 100644 index c0e72b2a1657..000000000000 --- a/platform/util/src/com/intellij/diagnostic/tracing/MethodTracer.java +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.diagnostic.tracing; - -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.BiFunction; - -public class MethodTracer { - private final @NotNull TracerId myId; - private final String myClassName; - private final String myMethodName; - - private final AtomicLong myInvocationCount = new AtomicLong(0); - private final AtomicLong myNonRecursiveCount = new AtomicLong(0); - private final AtomicLong myTotalTime = new AtomicLong(0); - private final AtomicLong myMaxTime = new AtomicLong(0); - - private final AtomicLong myTimeOnEdt = new AtomicLong(0); - private final AtomicLong myCountOnEdt = new AtomicLong(0); - private final AtomicLong myMaxTimeOnEdt = new AtomicLong(0); - - private final AtomicInteger myMaxRecursionDepth = new AtomicInteger(0); - - private final ThreadLocal currentCalculationStart = ThreadLocal.withInitial(() -> null); - private final ThreadLocal currentRecursionDepth = ThreadLocal.withInitial(() -> 0); - - private MethodTracer(@NotNull TracerId id, @NonNls String className, @NonNls String methodName) { - myId = id; - myClassName = className; - myMethodName = methodName; - } - - public void onMethodEnter() { - myInvocationCount.incrementAndGet(); - Integer recursionOnStart = currentRecursionDepth.get(); - - myMaxRecursionDepth.updateAndGet(old -> Math.max(old, recursionOnStart)); - - if (recursionOnStart == 0) { - currentCalculationStart.set(System.nanoTime()); - myNonRecursiveCount.incrementAndGet(); - } - - currentRecursionDepth.set(recursionOnStart + 1); - } - - public void onMethodExit() { - currentRecursionDepth.set(currentRecursionDepth.get() - 1); - - if (currentRecursionDepth.get() == 0) { - long duration = System.nanoTime() - currentCalculationStart.get(); - currentCalculationStart.set(null); - - myTotalTime.addAndGet(duration); - myMaxTime.updateAndGet(old -> Math.max(old, duration)); - - if (isDispatchThread.get()) { - myCountOnEdt.incrementAndGet(); - myTimeOnEdt.addAndGet(duration); - myMaxTimeOnEdt.updateAndGet(old -> Math.max(old, duration)); - } - } - } - - public MethodTracerData getCurrentData() { - return new MethodTracerData(myId, - myClassName, - myMethodName, - myInvocationCount.get(), - myNonRecursiveCount.get(), - toMillis(myTotalTime.get()), - toMillis(myMaxTime.get()), - myCountOnEdt.get(), - toMillis(myTimeOnEdt.get()), - toMillis(myMaxTimeOnEdt.get()), - myMaxRecursionDepth.get()); - } - - private static long toMillis(long time) { - return TimeUnit.NANOSECONDS.toMillis(time); - } - - private static final MyConcurrentMap tracersMap = new MyConcurrentMap<>(); - - public static MethodTracer getInstance(@NotNull String className, - @NotNull String simpleClassName, - @NotNull String methodName, - @Nullable String methodNameSuffix, - @NotNull String desc) { - TracerId id = new TracerId(className, methodName, methodNameSuffix, desc); - String presentableMethodName = methodName; - if (methodNameSuffix != null) { - presentableMethodName = methodName + "-" + methodNameSuffix; - } - return isEnabled() ? tracersMap.putIfAbsent(id, new MethodTracer(id, simpleClassName, presentableMethodName)) : empty; - } - - private static boolean enabled = true; - - public static boolean isEnabled() { - return enabled; - } - - public static void setEnabled(boolean enabled) { - MethodTracer.enabled = enabled; - } - - public static void clearAll() { - tracersMap.clear(); - } - - public static List getAllData() { - return tracersMap.map((k, v) -> v.getCurrentData()); - } - - private static final MethodTracer empty = new MethodTracer(TracerId.EMPTY, "", "") { - - @Override - public void onMethodEnter() {} - - @Override - public void onMethodExit() {} - - @Override - public MethodTracerData getCurrentData() { - throw new UnsupportedOperationException(); - } - }; - - private static final ThreadLocal isDispatchThread = ThreadLocal.withInitial(() -> SwingUtilities.isEventDispatchThread()); - - //atomic reference to an immutable map, it has better read performance than ConcurrentHashMap - private static final class MyConcurrentMap { - - private final AtomicReference> myReference = new AtomicReference<>(Collections.emptyMap()); - - public V putIfAbsent(K key, V value) { - do { - Map prevMap = myReference.get(); - V existingValue = prevMap.get(key); - - if (existingValue != null) { - return existingValue; - } - - Map newMap = new HashMap<>(prevMap); - newMap.put(key, value); - - if (myReference.compareAndSet(prevMap, Collections.unmodifiableMap(newMap))) { - return value; - } - } while(true); - } - - public void clear() { - myReference.set(Collections.emptyMap()); - } - - public Collection values() { - return myReference.get().values(); - } - - public List map(BiFunction function) { - Map map = myReference.get(); - ArrayList result = new ArrayList<>(map.size()); - - map.forEach((k, v) -> result.add(function.apply(k, v))); - - return result; - } - } - - public static final class TracerId { - - public static final TracerId EMPTY = new TracerId("", "", "", ""); - - private final String myClassName; - private final String myMethodName; - private final String mySuffix; - private final String myDescription; - - public TracerId(@NotNull @NonNls String className, - @NotNull @NonNls String methodName, - @Nullable @NonNls String suffix, - @NotNull @NonNls String description) { - - myClassName = className; - myMethodName = methodName; - mySuffix = suffix; - myDescription = description; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - TracerId id = (TracerId)o; - return myClassName.equals(id.myClassName) && - myMethodName.equals(id.myMethodName) && - Objects.equals(mySuffix, id.mySuffix) && - myDescription.equals(id.myDescription); - } - - @Override - public int hashCode() { - return Objects.hash(myClassName, myMethodName, mySuffix, myDescription); - } - } -} diff --git a/platform/util/src/com/intellij/diagnostic/tracing/MethodTracerData.java b/platform/util/src/com/intellij/diagnostic/tracing/MethodTracerData.java deleted file mode 100644 index cb797f5f9dde..000000000000 --- a/platform/util/src/com/intellij/diagnostic/tracing/MethodTracerData.java +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.diagnostic.tracing; - -import org.jetbrains.annotations.NotNull; - -public final class MethodTracerData { - public final @NotNull MethodTracer.TracerId id; - public final String className; - public final String methodName; - public final long invocationCount; - public final long nonRecursiveCount; - public final long totalTime; - public final long maxTime; - - public final long countOnEdt; - public final long timeOnEdt; - public final long maxTimeOnEdt; - - public final int maxRecursionDepth; - - public MethodTracerData(@NotNull MethodTracer.TracerId id, - String className, - String methodName, - long invocationCount, - long nonRecursiveCount, - long totalTime, - long maxTime, - long countOnEdt, - long timeOnEdt, - long maxTimeOnEdt, - int maxRecursionDepth) { - this.id = id; - this.className = className; - this.methodName = methodName; - this.invocationCount = invocationCount; - this.nonRecursiveCount = nonRecursiveCount; - this.totalTime = totalTime; - this.maxTime = maxTime; - this.maxRecursionDepth = maxRecursionDepth; - this.countOnEdt = countOnEdt; - this.timeOnEdt = timeOnEdt; - this.maxTimeOnEdt = maxTimeOnEdt; - } - - public double getAvgTime() { - return average(totalTime, nonRecursiveCount); - } - - public double getAvgTimeEdt() { - return average(timeOnEdt, countOnEdt); - } - - private static double average(long total, long count) { - if (count == 0) { - return 0; - } - double avg = (double)total / count; - - return (double)(Math.round(avg * 100)) / 100; - } - -}