mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
118 lines
2.6 KiB
Java
118 lines
2.6 KiB
Java
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
package com.facebook.systrace;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public final class SystraceMessage {
|
|
|
|
public static Boolean INCLUDE_ARGS = false;
|
|
|
|
public static Builder beginSection(long tag, String sectionName) {
|
|
return new StartSectionBuilder(tag, sectionName);
|
|
}
|
|
|
|
public static Builder endSection(long tag) {
|
|
return new EndSectionBuilder(tag);
|
|
}
|
|
|
|
public abstract static class Builder {
|
|
|
|
public abstract void flush();
|
|
|
|
public abstract Builder arg(String key, Object value);
|
|
|
|
public abstract Builder arg(String key, int value);
|
|
|
|
public abstract Builder arg(String key, long value);
|
|
|
|
public abstract Builder arg(String key, double value);
|
|
}
|
|
|
|
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 EndSectionBuilder extends Builder {
|
|
private long mTag;
|
|
|
|
public EndSectionBuilder(long tag) {
|
|
mTag = tag;
|
|
}
|
|
|
|
@Override
|
|
public void flush() {
|
|
Systrace.endSection(mTag);
|
|
}
|
|
|
|
@Override
|
|
public Builder arg(String key, Object value) {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public Builder arg(String key, int value) {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public Builder arg(String key, long value) {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public Builder arg(String key, double value) {
|
|
return this;
|
|
}
|
|
}
|
|
}
|