Remove string copies in Skia tracing macros

ATRACE_ANDROID_FRAMEWORK_ALWAYS and TRACE_EVENT0_ALWAYS create a
SkAndroidFrameworkTraceUtilAlways, which formats the input, requiring a
string copy. Mimic the split in SkAndroidFrameworkTraceUtil, which has
two constructors; one for formatting, and one for static strings. This
allows skipping the copy when it's unnecessary.

Make TRACE_EVENT0_ALWAYS call the cheaper constructor, since it never
has formatted input. ATRACE_ANDROID_FRAMEWORK_ALWAYS has few callers;
only one of them forces an unnecessary copy.

Bug: b/224677119
Test: perfetto
Change-Id: I8e699ae1496c94e08e6f7fce3616254b1a627a7f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539896
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Leon Scroggins III 2022-05-12 12:13:27 -04:00 committed by SkCQ
parent c54e3aecfd
commit e3772d2cae

View File

@ -128,7 +128,11 @@ private:
class SkAndroidFrameworkTraceUtilAlways {
public:
SkAndroidFrameworkTraceUtilAlways(const char* fmt, ...) {
SkAndroidFrameworkTraceUtilAlways(const char* name) {
ATRACE_BEGIN(name);
}
SkAndroidFrameworkTraceUtilAlways(bool, const char* fmt, ...) {
if (!ATRACE_ENABLED()) return;
const int BUFFER_SIZE = 256;
@ -147,7 +151,7 @@ public:
};
#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) SkAndroidFrameworkTraceUtil __trace(true, fmt, ##__VA_ARGS__)
#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) SkAndroidFrameworkTraceUtilAlways __trace_always(fmt, ##__VA_ARGS__)
#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) SkAndroidFrameworkTraceUtilAlways __trace_always(true, fmt, ##__VA_ARGS__)
// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
// associated arguments. In the framework, the arguments are ignored.