Commit b4a62918 authored by Salvador Guerrero's avatar Salvador Guerrero Committed by Commit Bot

Change trace event in ApplicationStatusListenerImpl to use typed arguments

This CL modifies the Android Application state listener to record the
new status as a strongly typed trace argument

Change-Id: I5491b19eeba73d2af2165441514b163eefb1e37e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523737Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Commit-Queue: Salvador Guerrero <salg@google.com>
Cr-Commit-Position: refs/heads/master@{#826025}
parent 89307256
......@@ -12,6 +12,10 @@
#include "base/observer_list_threadsafe.h"
#include "base/trace_event/base_tracing.h"
#if BUILDFLAG(ENABLE_BASE_TRACING)
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_application_state_info.pbzero.h"
#endif // BUILDFLAG(ENABLE_BASE_TRACING)
namespace base {
namespace android {
......@@ -81,21 +85,37 @@ std::unique_ptr<ApplicationStatusListener> ApplicationStatusListener::New(
// static
void ApplicationStatusListener::NotifyApplicationStateChange(
ApplicationState state) {
TRACE_COUNTER1("browser", "ApplicationState", static_cast<int>(state));
using perfetto::protos::pbzero::ChromeApplicationStateInfo;
ChromeApplicationStateInfo::ChromeApplicationState tracing_state;
switch (state) {
case APPLICATION_STATE_UNKNOWN:
tracing_state = ChromeApplicationStateInfo::APPLICATION_STATE_UNKNOWN;
break;
case APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES:
tracing_state = ChromeApplicationStateInfo::
APPLICATION_STATE_HAS_DESTROYED_ACTIVITIES;
break;
case APPLICATION_STATE_HAS_RUNNING_ACTIVITIES:
tracing_state =
ChromeApplicationStateInfo::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES;
RecordAction(UserMetricsAction("Android.LifeCycle.HasRunningActivities"));
break;
case APPLICATION_STATE_HAS_PAUSED_ACTIVITIES:
tracing_state =
ChromeApplicationStateInfo::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES;
RecordAction(UserMetricsAction("Android.LifeCycle.HasPausedActivities"));
break;
case APPLICATION_STATE_HAS_STOPPED_ACTIVITIES:
tracing_state =
ChromeApplicationStateInfo::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES;
RecordAction(UserMetricsAction("Android.LifeCycle.HasStoppedActivities"));
break;
}
TRACE_EVENT("browser", "ApplicationState", [&](perfetto::EventContext ctx) {
ChromeApplicationStateInfo* app_state_info =
ctx.event()->set_chrome_application_state_info();
app_state_info->set_application_state(tracing_state);
});
g_observers.Get().Notify(FROM_HERE, &ApplicationStatusListenerImpl::Notify,
state);
}
......
......@@ -175,6 +175,11 @@ constexpr int kChromeMojoEventInfoIndices[] = {1, -1};
constexpr MessageInfo kChromeMojoEventInfo = {kChromeMojoEventInfoIndices,
nullptr};
// Proto Message: ChromeApplicationStateInfo
constexpr int kChromeApplicationStateInfoIndices[] = {1, -1};
constexpr MessageInfo kChromeApplicationStateInfo = {
kChromeApplicationStateInfoIndices, nullptr};
// Proto Message: ChromeRendererSchedulerState
constexpr int kChromeRendererSchedulerStateIndices[] = {1, -1};
constexpr MessageInfo kChromeRendererSchedulerState = {
......@@ -188,7 +193,7 @@ constexpr MessageInfo kChromeWindowHandleEventInfo = {
// Proto Message: TrackEvent
constexpr int kTrackEventIndices[] = {1, 2, 3, 5, 6, 9, 10, 11, 12, 16,
17, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 38, 40, 41, 42, -1};
33, 34, 35, 36, 38, 39, 40, 41, 42, -1};
constexpr MessageInfo const* kTrackEventComplexMessages[] = {
nullptr,
nullptr,
......@@ -215,6 +220,7 @@ constexpr MessageInfo const* kTrackEventComplexMessages[] = {
&kChromeMessagePump,
nullptr,
&kChromeMojoEventInfo,
&kChromeApplicationStateInfo,
&kChromeRendererSchedulerState,
&kChromeWindowHandleEventInfo,
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