Skip to content

Commit

Permalink
[Structured Metrics] Add Event when Sturctured Metrics is initialized.
Browse files Browse the repository at this point in the history
This is to monitor whether the client is properly initialized and the
event flows through end to end.

Bug: 1238197
Change-Id: Ieec2a418671e45063adbf53dfa9ed70d98e8565f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3191757
Commit-Queue: Jong Ahn <[email protected]>
Reviewed-by: Tony Yeoman <[email protected]>
Cr-Commit-Position: refs/heads/main@{#928471}
  • Loading branch information
Jonghyun Ahn authored and Chromium LUCI CQ committed Oct 6, 2021
1 parent bf99d99 commit f6a424f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/browser/metrics/structured/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static_library("structured") {
"//build:chromeos_buildflags",
"//chromeos/crosapi/mojom",
"//components/metrics/structured",
"//components/metrics/structured:structured_events",
]

if (is_chromeos_ash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "chrome/browser/metrics/structured/chrome_structured_metrics_recorder.h"

#include <stdint.h>

#include "base/feature_list.h"
#include "build/chromeos_buildflags.h"
#include "components/metrics/structured/histogram_util.h"
Expand All @@ -19,6 +21,23 @@
#endif
namespace metrics {
namespace structured {
namespace {

// Platforms for which the StructuredMetricsClient will be initialized for.
enum class StructuredMetricsPlatform {
kUninitialized = 0,
kAshChrome = 1,
kLacrosChrome = 2,
};

// Logs initialization of Structured Metrics as a record.
void LogInitializationInStructuredMetrics(StructuredMetricsPlatform platform) {
events::v2::structured_metrics::Initialization()
.SetPlatform(static_cast<int64_t>(platform))
.Record();
}

} // namespace

ChromeStructuredMetricsRecorder::ChromeStructuredMetricsRecorder() {
// TODO(jongahn): Make a static factory class and pass it into ctor.
Expand Down Expand Up @@ -53,6 +72,7 @@ void ChromeStructuredMetricsRecorder::Initialize() {
auto* ash_recorder =
static_cast<AshStructuredMetricsRecorder*>(delegate_.get());
ash_recorder->Initialize();
LogInitializationInStructuredMetrics(StructuredMetricsPlatform::kAshChrome);

#elif BUILDFLAG(IS_CHROMEOS_LACROS)
// Should only be enabled on Lacros if feature is enabled.
Expand All @@ -66,6 +86,12 @@ void ChromeStructuredMetricsRecorder::Initialize() {
// Ensure that the sequence is the ui thread.
DCHECK(is_current_ui_thread_set);
lacros_recorder->SetSequence(base::SequencedTaskRunnerHandle::Get());
LogClientInitializationSuccessful(true);
LogInitializationInStructuredMetrics(
StructuredMetricsPlatform::kLacrosChrome);
} else {
LogInitializationInStructuredMetrics(
StructuredMetricsPlatform::kUninitialized);
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include "components/metrics/structured/event.h"
#include "components/metrics/structured/event_base.h"
#include "components/metrics/structured/structured_metrics_client.h"
#include "components/metrics/structured/structured_mojo_events.h"

namespace metrics {
namespace structured {

namespace {
using RecordingDelegate = StructuredMetricsClient::RecordingDelegate;
}
} // namespace

// Singleton to record structured metrics on Chrome.
//
Expand Down
25 changes: 25 additions & 0 deletions tools/metrics/structured/structured.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,31 @@
</event>
</project>

<project name="StructuredMetrics">
<owner>[email protected]</owner>
<owner>[email protected]</owner>
<id>per-project</id>
<scope>device</scope>
<summary>
Structured Metrics is a logging framework for events. This project is used
for monitoring the framework itself.
</summary>

<event name="Initialization">
<summary>
Records metadata about initialization of Structured Metrics and will be
recorded immediately after initialization is successful. Will be sent once
per initialization during browser process initialization.
</summary>
<metric name="Platform" type="int">
<summary>
The platform for which the client is initialized on. 0: Uninitialized, 1:
ASH_CHROME, 2: LACROS_CHROME.
</summary>
</metric>
</event>
</project>

<project name="TestProjectOne">
<owner>[email protected]</owner>
<id>per-project</id>
Expand Down

0 comments on commit f6a424f

Please sign in to comment.