mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove unused MethodTrace
GitOrigin-RevId: e2eb3c05aa6106893dd4b75bf6246a7c51249513
This commit is contained in:
committed by
intellij-monorepo-bot
parent
26d65f9a16
commit
a7d86cd539
@@ -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
|
||||
- <init>(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
|
||||
- <init>(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
|
||||
- <init>():V
|
||||
- s:escapeParameterOnWindows(java.lang.String,Z):java.lang.String
|
||||
|
||||
@@ -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<Long> currentCalculationStart = ThreadLocal.withInitial(() -> null);
|
||||
private final ThreadLocal<Integer> 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<TracerId, MethodTracer> 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<MethodTracerData> 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<Boolean> isDispatchThread = ThreadLocal.withInitial(() -> SwingUtilities.isEventDispatchThread());
|
||||
|
||||
//atomic reference to an immutable map, it has better read performance than ConcurrentHashMap
|
||||
private static final class MyConcurrentMap<K, V> {
|
||||
|
||||
private final AtomicReference<Map<K, V>> myReference = new AtomicReference<>(Collections.emptyMap());
|
||||
|
||||
public V putIfAbsent(K key, V value) {
|
||||
do {
|
||||
Map<K, V> prevMap = myReference.get();
|
||||
V existingValue = prevMap.get(key);
|
||||
|
||||
if (existingValue != null) {
|
||||
return existingValue;
|
||||
}
|
||||
|
||||
Map<K, V> 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<V> values() {
|
||||
return myReference.get().values();
|
||||
}
|
||||
|
||||
public <T> List<T> map(BiFunction<? super K, ? super V, ? extends T> function) {
|
||||
Map<K, V> map = myReference.get();
|
||||
ArrayList<T> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user