Commit 131fe11a authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

tracing/keyed_services: Use typed trace event for service lookup

Replaces the KeyedServiceFactory::GetServiceForContext trace event with
a typed trace event.

Corresponding proto buffer definitions for these events were added in
aosp/1180211.

Typed trace events will allow inclusion of the event arguments in slow
reports data in the future. The trace format is protocol-buffer based
under the hood already (see docs.perfetto.dev for details), this patch
adds strong typing for the arguments of the respective event(s) only.

TBR: eseckler@google.com
Bug: 644264
Change-Id: I67c0f8f78caca2db76e201f8f649f84eda53e3fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1950966
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735359}
parent 1acdfe3c
......@@ -42,6 +42,7 @@ component("core") {
"//base",
"//components/pref_registry",
"//components/prefs",
"//services/tracing/public/cpp:cpp",
]
}
......
include_rules = [
"+services/tracing/public/cpp",
"+third_party/perfetto/protos/perfetto/trace/track_event",
# Only for tests.
"+third_party/re2",
]
......@@ -4,6 +4,8 @@
#include "components/keyed_service/core/keyed_service_base_factory.h"
#include <type_traits>
#include "base/supports_user_data.h"
#include "base/trace_event/trace_event.h"
#include "components/keyed_service/core/dependency_manager.h"
......@@ -14,6 +16,15 @@ KeyedServiceBaseFactory::KeyedServiceBaseFactory(const char* service_name,
DependencyManager* manager,
Type type)
: dependency_manager_(manager), service_name_(service_name), type_(type) {
static_assert(
std::is_same<decltype(KeyedServiceBaseFactory::service_name_),
const char*>::value,
"This string is logged in plaintext via UMA trace events uploads, so "
"must be static as a privacy requirement. See //third_party/perfetto/"
"protos/perfetto/trace/track_event/chrome_keyed_service.proto. "
"Contact tracing@chromium.org and base/metrics/OWNERS if this needs to "
"change.");
dependency_manager_->AddComponent(this);
}
......
......@@ -8,9 +8,10 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
#include "components/keyed_service/core/dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h"
#include "services/tracing/public/cpp/perfetto/macros.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_keyed_service.pbzero.h"
KeyedServiceFactory::KeyedServiceFactory(const char* name,
DependencyManager* manager,
......@@ -48,8 +49,10 @@ KeyedService* KeyedServiceFactory::SetTestingFactoryAndUse(
KeyedService* KeyedServiceFactory::GetServiceForContext(void* context,
bool create) {
TRACE_EVENT1("browser,startup", "KeyedServiceFactory::GetServiceForContext",
"service_name", name());
TRACE_EVENT("browser,startup", "KeyedServiceFactory::GetServiceForContext",
[this](perfetto::EventContext ctx) {
ctx.event()->set_chrome_keyed_service()->set_name(name());
});
context = GetContextToUse(context);
if (!context)
return nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment