Reland "Add Perfetto library (gn & bazel) and bare-bones SkPerfTrace class"

This reverts commit d78d52a86f.

That reason this CL was reverted in the first place is that it broke the Android roller - perfetto.h could not be located.
We now disable the use of perfetto for Android in the gn_to_bp.py script, so the roller should be good to go.

Reason for revert: Relanding

Original change's description:
> Revert "Add Perfetto library (gn & bazel) and bare-bones SkPerfTrace class"
>
> This reverts commit bfc9b94840.
>
> Reason for revert: new dependency causing Android build error
>
> Original change's description:
> > Add Perfetto library (gn & bazel) and bare-bones SkPerfTrace class
> >
> > First incremental step to incorporating Perfetto tracing into Skia, more CLs to follow
> >
> > NOTE: The presubmit check is failing. This appears to be due to the known issue where the presubmit check bugs out if the DEPS file is edited, which it was on this CL (modified to include Perfetto).
> >
> > Bug: skia:13303
> > Change-Id: I908be0392b520e8da14b34588b842bf6d955bd93
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/543081
> > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > Commit-Queue: Nicolette Prevost <nicolettep@google.com>
>
> Bug: skia:13303
> Change-Id: Ia2b883bbab1f8fb4f3914b63104a39240cc60e86
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544239
> Reviewed-by: Tyler Denniston <tdenniston@google.com>
> Auto-Submit: Tyler Denniston <tdenniston@google.com>
> Reviewed-by: Nicolette Prevost <nicolettep@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Tyler Denniston <tdenniston@google.com>

Bug: skia:13303
Change-Id: Ibd369b9c8c0e69fc9615fc05cf588ee4440c8ed5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544244
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Nicolette Prevost <nicolettep@google.com>
This commit is contained in:
Nicolette Prevost 2022-06-14 16:42:28 -04:00 committed by SkCQ
parent 06dd185839
commit 29dffe9ba4
10 changed files with 157 additions and 1 deletions

View File

@ -1951,6 +1951,14 @@ if (skia_enable_tools) {
"tools/trace/SkDebugfTracer.cpp",
"tools/trace/SkDebugfTracer.h",
]
if (skia_use_perfetto) {
deps += [ "//third_party/perfetto" ]
sources += [
"tools/trace/SkPerfettoTrace.cpp",
"tools/trace/SkPerfettoTrace.h",
]
defines = [ "SK_USE_PERFETTO" ]
}
}
test_lib("tool_utils") {

1
DEPS
View File

@ -35,6 +35,7 @@ deps = {
"third_party/externals/microhttpd" : "https://android.googlesource.com/platform/external/libmicrohttpd@748945ec6f1c67b7efc934ab0808e1d32f2fb98d",
"third_party/externals/oboe" : "https://chromium.googlesource.com/external/github.com/google/oboe.git@b02a12d1dd821118763debec6b83d00a8a0ee419",
"third_party/externals/opengl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/OpenGL-Registry@14b80ebeab022b2c78f84a573f01028c96075553",
"third_party/externals/perfetto" : "https://android.googlesource.com/platform/external/perfetto@d5b124f8a69f517e91514135e8dfc4c995d34c36",
"third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@bb217acdca1cc0c16b704669dd6f91a1b509c406",
"third_party/externals/rive" : "https://skia.googlesource.com/external/github.com/rive-app/rive-cpp.git@d9a4b488a4b3d622fe8721a3126b248bdc100e37",
"third_party/externals/sfntly" : "https://chromium.googlesource.com/external/github.com/googlei18n/sfntly.git@b55ff303ea2f9e26702b514cf6a3196a2e3e2974",

View File

@ -238,6 +238,13 @@ new_local_repository(
workspace_file_content = "",
)
new_local_repository(
name = "perfetto",
build_file = "bazel/external/perfetto/BUILD.bazel",
path = "third_party/externals/perfetto",
workspace_file_content = "",
)
new_local_repository(
name = "piex",
build_file = "bazel/external/piex/BUILD.bazel",

13
bazel/external/perfetto/BUILD.bazel vendored Normal file
View File

@ -0,0 +1,13 @@
# This file will be copied into //third_party/externals/perfetto via the
# new_local_repository rule in WORKSPACE.bazel, so all files should be relative to that path.
cc_library(
name = "perfetto",
srcs = ["sdk/perfetto.cc"],
hdrs = [
"sdk/perfetto.h",
],
defines = ["SK_USE_PERFETTO"],
includes = ["sdk"],
visibility = ["//visibility:public"],
)

View File

@ -499,6 +499,7 @@ def generate_args(target_os, enable_gpu, renderengine = False):
'skia_include_multiframe_procs': 'false',
# Required for some SKSL tests
'skia_enable_sksl_tracing': 'true',
'skia_use_perfetto': 'false'
}
d['target_os'] = target_os
if target_os == '"android"':

View File

@ -62,6 +62,7 @@ declare_args() {
skia_use_lua = is_skia_dev_build && !is_ios
skia_use_metal = false
skia_use_ndk_images = is_android && defined(ndk_api) && ndk_api >= 30
skia_use_perfetto = is_linux || is_mac || is_android
skia_use_piex = !is_win && !is_wasm
skia_use_sfml = false
skia_use_webgl = is_wasm

17
third_party/perfetto/BUILD.gn vendored Normal file
View File

@ -0,0 +1,17 @@
# Copyright 2022 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../third_party.gni")
third_party("perfetto") {
public_include_dirs = [
".",
"../externals/perfetto/sdk",
]
sources = [
"../externals/perfetto/sdk/perfetto.cc",
"../externals/perfetto/sdk/perfetto.h",
]
}

View File

@ -13,12 +13,16 @@
#include "tools/flags/CommandLineFlags.h"
#include "tools/trace/ChromeTracingTracer.h"
#include "tools/trace/SkDebugfTracer.h"
#if defined(SK_USE_PERFETTO)
#include "tools/trace/SkPerfettoTrace.h"
#endif
static DEFINE_string(trace,
"",
"Log trace events in one of several modes:\n"
" debugf : Show events using SkDebugf\n"
" atrace : Send events to Android ATrace\n"
" perfetto : Send events to Perfetto (Linux, Android, and Mac only)\n"
" <filename> : Any other string is interpreted as a filename. Writes\n"
" trace events to specified file as JSON, for viewing\n"
" with chrome://tracing");
@ -41,7 +45,18 @@ void initializeEventTracingForTools(const char* traceFlag) {
eventTracer = new SkATrace();
} else if (0 == strcmp(traceFlag, "debugf")) {
eventTracer = new SkDebugfTracer();
} else {
}
else if (0 == strcmp(traceFlag, "perfetto")) {
#if defined(SK_USE_PERFETTO)
eventTracer = new SkPerfettoTrace();
#else
SkDebugf("Perfetto is not enabled (SK_USE_PERFETTO is false). "
"Perfetto tracing will not be performed.\n"
"Tracing with Perfetto is only enabled for Linux, Android, and Mac.");
return;
#endif
}
else {
eventTracer = new ChromeTracingTracer(traceFlag);
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkTraceEvent.h"
#include "src/core/SkTraceEventCommon.h"
#include "tools/trace/SkPerfettoTrace.h"
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
SkPerfettoTrace::SkPerfettoTrace() {
}
SkPerfettoTrace::~SkPerfettoTrace() {
}
SkEventTracer::Handle SkPerfettoTrace::addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
uint64_t id,
int numArgs,
const char** argNames,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) {
return 0;
}
void SkPerfettoTrace::updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
const char* name,
SkEventTracer::Handle handle) {
}
const uint8_t* SkPerfettoTrace::getCategoryGroupEnabled(const char* name) {
return fCategories.getCategoryGroupEnabled(name);
}
const char* SkPerfettoTrace::getCategoryGroupName(const uint8_t* categoryEnabledFlag) {
return fCategories.getCategoryGroupName(categoryEnabledFlag);
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPerfettoTrace_DEFINED
#define SkPerfettoTrace_DEFINED
#include "include/utils/SkEventTracer.h"
#include "tools/trace/EventTracingPriv.h"
#include "perfetto.h"
PERFETTO_DEFINE_CATEGORIES();
/**
* This class is used to support Perfetto tracing. It hooks into the SkEventTracer system.
*/
class SkPerfettoTrace : public SkEventTracer {
public:
SkPerfettoTrace();
~SkPerfettoTrace() override;
SkEventTracer::Handle addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
uint64_t id,
int numArgs,
const char** argNames,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) override;
void updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
const char* name,
SkEventTracer::Handle handle) override;
const uint8_t* getCategoryGroupEnabled(const char* name) override;
const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override;
private:
SkPerfettoTrace(const SkPerfettoTrace&) = delete;
SkPerfettoTrace& operator=(const SkPerfettoTrace&) = delete;
SkEventTracingCategories fCategories;
};
#endif