Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 25.2k
Improve OSS systrace#34252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Improve OSS systrace #34252
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding arguments to the section name makes grouping similar events a lot harder so by default I disable it. I don't really see how else args are useful for systrace in Android Studio. How is that used internally at facebook? | ||
| 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,63 @@ public abstract static class Builder { | ||
| 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) { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we keep this sorted?