diff options
| -rw-r--r-- | core/java/android/tracing/transition/TransitionDataSource.java | 24 | ||||
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/transition/tracing/PerfettoTransitionTracer.java | 41 |
2 files changed, 17 insertions, 48 deletions
diff --git a/core/java/android/tracing/transition/TransitionDataSource.java b/core/java/android/tracing/transition/TransitionDataSource.java index 82559dab0e5b..744f4469bc75 100644 --- a/core/java/android/tracing/transition/TransitionDataSource.java +++ b/core/java/android/tracing/transition/TransitionDataSource.java @@ -16,7 +16,6 @@ package android.tracing.transition; -import android.tracing.perfetto.CreateTlsStateArgs; import android.tracing.perfetto.DataSource; import android.tracing.perfetto.DataSourceInstance; import android.tracing.perfetto.FlushCallbackArguments; @@ -24,23 +23,17 @@ import android.tracing.perfetto.StartCallbackArguments; import android.tracing.perfetto.StopCallbackArguments; import android.util.proto.ProtoInputStream; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * @hide */ public class TransitionDataSource - extends DataSource<DataSourceInstance, TransitionDataSource.TlsState, Void> { + extends DataSource<DataSourceInstance, Void, Void> { public static String DATA_SOURCE_NAME = "com.android.wm.shell.transition"; private final Runnable mOnStartStaticCallback; private final Runnable mOnFlushStaticCallback; private final Runnable mOnStopStaticCallback; - private final ConcurrentHashMap<Integer, ConcurrentHashMap<String, Integer>> mHandlerMappings = - new ConcurrentHashMap<>(); - public TransitionDataSource(Runnable onStart, Runnable onFlush, Runnable onStop) { super(DATA_SOURCE_NAME); this.mOnStartStaticCallback = onStart; @@ -49,20 +42,6 @@ public class TransitionDataSource } @Override - protected TlsState createTlsState(CreateTlsStateArgs<DataSourceInstance> args) { - return new TlsState(args.getDataSourceInstanceLocked().getInstanceIndex()); - } - - public class TlsState { - public final Map<String, Integer> handlerMapping; - - public TlsState(int instanceIndex) { - handlerMapping = mHandlerMappings - .computeIfAbsent(instanceIndex, index -> new ConcurrentHashMap<>()); - } - } - - @Override public DataSourceInstance createInstance(ProtoInputStream configStream, int instanceIndex) { return new DataSourceInstance(this, instanceIndex) { @Override @@ -78,7 +57,6 @@ public class TransitionDataSource @Override protected void onStop(StopCallbackArguments args) { mOnStopStaticCallback.run(); - mHandlerMappings.remove(instanceIndex); } }; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/tracing/PerfettoTransitionTracer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/tracing/PerfettoTransitionTracer.java index 0c25f27854bd..b3e8bd9bd23c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/tracing/PerfettoTransitionTracer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/tracing/PerfettoTransitionTracer.java @@ -19,16 +19,15 @@ package com.android.wm.shell.transition.tracing; import android.internal.perfetto.protos.PerfettoTrace; import android.os.SystemClock; import android.os.Trace; -import android.tracing.perfetto.DataSourceInstance; import android.tracing.perfetto.DataSourceParams; import android.tracing.perfetto.InitArguments; import android.tracing.perfetto.Producer; -import android.tracing.perfetto.TracingContext; import android.tracing.transition.TransitionDataSource; import android.util.proto.ProtoOutputStream; import com.android.wm.shell.transition.Transitions; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; @@ -41,6 +40,7 @@ public class PerfettoTransitionTracer implements TransitionTracer { mActiveTraces::incrementAndGet, this::onFlush, mActiveTraces::decrementAndGet); + private final Map<String, Integer> mHandlerMapping = new HashMap<>(); public PerfettoTransitionTracer() { Producer.init(InitArguments.DEFAULTS); @@ -69,7 +69,7 @@ public class PerfettoTransitionTracer implements TransitionTracer { private void doLogDispatched(int transitionId, Transitions.TransitionHandler handler) { mDataSource.trace(ctx -> { - final int handlerId = getHandlerId(handler, ctx); + final int handlerId = getHandlerId(handler); final ProtoOutputStream os = ctx.newTracePacket(); final long token = os.start(PerfettoTrace.TracePacket.SHELL_TRANSITION); @@ -81,17 +81,16 @@ public class PerfettoTransitionTracer implements TransitionTracer { }); } - private static int getHandlerId(Transitions.TransitionHandler handler, - TracingContext<DataSourceInstance, TransitionDataSource.TlsState, Void> ctx) { - final Map<String, Integer> handlerMapping = - ctx.getCustomTlsState().handlerMapping; + private int getHandlerId(Transitions.TransitionHandler handler) { final int handlerId; - if (handlerMapping.containsKey(handler.getClass().getName())) { - handlerId = handlerMapping.get(handler.getClass().getName()); - } else { - // + 1 to avoid 0 ids which can be confused with missing value when dumped to proto - handlerId = handlerMapping.size() + 1; - handlerMapping.put(handler.getClass().getName(), handlerId); + synchronized (mHandlerMapping) { + if (mHandlerMapping.containsKey(handler.getClass().getName())) { + handlerId = mHandlerMapping.get(handler.getClass().getName()); + } else { + // + 1 to avoid 0 ids which can be confused with missing value when dumped to proto + handlerId = mHandlerMapping.size() + 1; + mHandlerMapping.put(handler.getClass().getName(), handlerId); + } } return handlerId; } @@ -194,22 +193,14 @@ public class PerfettoTransitionTracer implements TransitionTracer { } private void onFlush() { - Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "onFlush"); - try { - doOnFlush(); - } finally { - Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER); - } - } - - private void doOnFlush() { mDataSource.trace(ctx -> { final ProtoOutputStream os = ctx.newTracePacket(); - final Map<String, Integer> handlerMapping = ctx.getCustomTlsState().handlerMapping; - for (String handler : handlerMapping.keySet()) { + for (Map.Entry<String, Integer> entry : mHandlerMapping.entrySet()) { + final String handler = entry.getKey(); + final int handlerId = entry.getValue(); final long token = os.start(PerfettoTrace.TracePacket.SHELL_HANDLER_MAPPINGS); - os.write(PerfettoTrace.ShellHandlerMapping.ID, handlerMapping.get(handler)); + os.write(PerfettoTrace.ShellHandlerMapping.ID, handlerId); os.write(PerfettoTrace.ShellHandlerMapping.NAME, handler); os.end(token); } |