mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Improve OSS systrace (#34252)
Summary: Implements most of systrace using androidx.tracing, this makes it usable using Android Studio profiler systrace. ## Changelog [Android] [Added] - Improve OSS systrace Pull Request resolved: https://github.com/facebook/react-native/pull/34252 Test Plan: Run a systrace in Android Studio for RN Tester and make sure RN specific sections are there. <img width="1263" alt="image" src="https://user-images.githubusercontent.com/2677334/180593493-fc087b4a-2253-43e1-b246-bed3e7bba7ac.png"> Reviewed By: NickGerleman Differential Revision: D38116890 Pulled By: dmitryrykun fbshipit-source-id: 744bedbf9ad4004488340a5b4e93d936d9a1e582
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0ce4ea2bf5
commit
ccbfdd7167
@@ -1,4 +1,4 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library")
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "systrace",
|
||||
@@ -8,4 +8,7 @@ rn_android_library(
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_dep("third-party/android/androidx:tracing"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package com.facebook.systrace;
|
||||
|
||||
import android.os.Trace;
|
||||
import androidx.tracing.Trace;
|
||||
|
||||
/**
|
||||
* Systrace stub that mostly does nothing but delegates to Trace for beginning/ending sections. The
|
||||
@@ -55,21 +55,35 @@ public class Systrace {
|
||||
Trace.endSection();
|
||||
}
|
||||
|
||||
public static void beginAsyncSection(long tag, final String sectionName, final int cookie) {}
|
||||
public static void beginAsyncSection(long tag, final String sectionName, final int cookie) {
|
||||
Trace.beginAsyncSection(sectionName, cookie);
|
||||
}
|
||||
|
||||
public static void beginAsyncSection(
|
||||
long tag, final String sectionName, final int cookie, final long startNanos) {}
|
||||
long tag, final String sectionName, final int cookie, final long startNanos) {
|
||||
beginAsyncSection(tag, sectionName, cookie);
|
||||
}
|
||||
|
||||
public static void endAsyncSection(long tag, final String sectionName, final int cookie) {}
|
||||
public static void endAsyncSection(long tag, final String sectionName, final int cookie) {
|
||||
Trace.endAsyncSection(sectionName, cookie);
|
||||
}
|
||||
|
||||
public static void endAsyncSection(
|
||||
long tag, final String sectionName, final int cookie, final long endNanos) {}
|
||||
long tag, final String sectionName, final int cookie, final long endNanos) {
|
||||
endAsyncSection(tag, sectionName, cookie);
|
||||
}
|
||||
|
||||
public static void traceCounter(long tag, final String counterName, final int counterValue) {}
|
||||
public static void traceCounter(long tag, final String counterName, final int counterValue) {
|
||||
Trace.setCounter(counterName, counterValue);
|
||||
}
|
||||
|
||||
public static void startAsyncFlow(long tag, final String sectionName, final int cookie) {}
|
||||
public static void startAsyncFlow(long tag, final String sectionName, final int cookie) {
|
||||
beginAsyncSection(tag, sectionName, cookie);
|
||||
}
|
||||
|
||||
public static void stepAsyncFlow(long tag, final String sectionName, final int cookie) {}
|
||||
|
||||
public static void endAsyncFlow(long tag, final String sectionName, final int cookie) {}
|
||||
public static void endAsyncFlow(long tag, final String sectionName, final int cookie) {
|
||||
endAsyncSection(tag, sectionName, cookie);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,19 @@
|
||||
|
||||
package com.facebook.systrace;
|
||||
|
||||
/** Systrace stub. */
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class SystraceMessage {
|
||||
|
||||
private static final Builder NOOP_BUILDER = new NoopBuilder();
|
||||
public static Boolean INCLUDE_ARGS = false;
|
||||
|
||||
public static Builder beginSection(long tag, String sectionName) {
|
||||
return NOOP_BUILDER;
|
||||
return new StartSectionBuilder(tag, sectionName);
|
||||
}
|
||||
|
||||
public static Builder endSection(long tag) {
|
||||
return NOOP_BUILDER;
|
||||
return new EndSectionBuilder(tag);
|
||||
}
|
||||
|
||||
public abstract static class Builder {
|
||||
@@ -33,13 +35,64 @@ public final class SystraceMessage {
|
||||
public abstract Builder arg(String key, double value);
|
||||
}
|
||||
|
||||
private interface Flusher {
|
||||
void flush(StringBuilder builder);
|
||||
private static class StartSectionBuilder extends Builder {
|
||||
private String mSectionName;
|
||||
private long mTag;
|
||||
private List<String> mArgs = new ArrayList<>();
|
||||
|
||||
public StartSectionBuilder(long tag, String sectionName) {
|
||||
mTag = tag;
|
||||
mSectionName = sectionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
Systrace.beginSection(
|
||||
mTag,
|
||||
mSectionName
|
||||
+ (INCLUDE_ARGS && mArgs.size() > 0 ? (" (" + String.join(", ", mArgs) + ")") : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder arg(String key, Object value) {
|
||||
addArg(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder arg(String key, int value) {
|
||||
addArg(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder arg(String key, long value) {
|
||||
addArg(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder arg(String key, double value) {
|
||||
addArg(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addArg(String key, String value) {
|
||||
mArgs.add(key + ": " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static class NoopBuilder extends Builder {
|
||||
private static class EndSectionBuilder extends Builder {
|
||||
private long mTag;
|
||||
|
||||
public EndSectionBuilder(long tag) {
|
||||
mTag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {}
|
||||
public void flush() {
|
||||
Systrace.endSection(mTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder arg(String key, Object value) {
|
||||
|
||||
Reference in New Issue
Block a user