From 446ed91f8f6d5eead7d936d8abd129912b1a8549 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Wed, 15 Oct 2025 15:33:30 -0700 Subject: [PATCH 1/5] Remove dependency on host/commands/metrics/utils.h Bug: 452437293 --- base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel | 1 - .../cuttlefish/host/libs/metrics/metrics_conversion.cc | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel index 014e42a52a..cb7e7b5cc7 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel @@ -47,7 +47,6 @@ cf_cc_library( "//cuttlefish/common/libs/utils:host_info", "//cuttlefish/host/commands/metrics:clearcut_protos", "//cuttlefish/host/commands/metrics:events", - "//cuttlefish/host/commands/metrics:utils", "//cuttlefish/host/libs/metrics:event_type", "//external_proto:cf_guest_cc_proto", "//external_proto:cf_host_cc_proto", diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc index ebfcae134c..f69c7b99ea 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc @@ -21,7 +21,6 @@ #include "cuttlefish/common/libs/utils/host_info.h" #include "cuttlefish/host/commands/metrics/clearcut_protos.h" #include "cuttlefish/host/commands/metrics/events.h" -#include "cuttlefish/host/commands/metrics/utils.h" #include "cuttlefish/host/libs/metrics/event_type.h" #include "external_proto/cf_guest.pb.h" #include "external_proto/cf_host.pb.h" @@ -42,6 +41,13 @@ using logs::proto::wireless::android::cuttlefish::events::MetricsEventV2; using wireless_android_play_playlog::LogEvent; using wireless_android_play_playlog::LogRequest; +uint64_t GetEpochTimeMs() { + auto now = std::chrono::system_clock::now().time_since_epoch(); + uint64_t milliseconds_since_epoch = + std::chrono::duration_cast(now).count(); + return milliseconds_since_epoch; +} + CuttlefishGuest_EventType ConvertEventType(EventType event_type) { switch (event_type) { case EventType::DeviceInstantiation: @@ -106,7 +112,7 @@ void PopulateMetricsEvent(EventType event_type, LogRequest ConstructLogRequest(EventType event_type, const HostInfo& host_metrics, std::string_view session_id) { - uint64_t now_ms = metrics::GetEpochTimeMs(); + uint64_t now_ms = GetEpochTimeMs(); CuttlefishLogEvent cf_log_event = metrics::BuildCfLogEvent(now_ms); PopulateMetricsEvent(event_type, cf_log_event, host_metrics, session_id); LogEvent log_event = metrics::BuildLogEvent(now_ms, cf_log_event); From 5c1aa6b50ba12d91eee555a62203009a0d870ce0 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Wed, 15 Oct 2025 15:49:55 -0700 Subject: [PATCH 2/5] Remove host/commands/metrics/events.h dependency Bug: 452437293 --- .../cuttlefish/host/libs/metrics/BUILD.bazel | 2 +- .../host/libs/metrics/metrics_conversion.cc | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel index cb7e7b5cc7..5ad2ed5fa3 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel @@ -45,8 +45,8 @@ cf_cc_library( ], deps = [ "//cuttlefish/common/libs/utils:host_info", + "//cuttlefish/host/commands/cvd/version", "//cuttlefish/host/commands/metrics:clearcut_protos", - "//cuttlefish/host/commands/metrics:events", "//cuttlefish/host/libs/metrics:event_type", "//external_proto:cf_guest_cc_proto", "//external_proto:cf_host_cc_proto", diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc index f69c7b99ea..fd3dc40bc4 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc @@ -19,8 +19,8 @@ #include #include "cuttlefish/common/libs/utils/host_info.h" +#include "cuttlefish/host/commands/cvd/version/version.h" #include "cuttlefish/host/commands/metrics/clearcut_protos.h" -#include "cuttlefish/host/commands/metrics/events.h" #include "cuttlefish/host/libs/metrics/event_type.h" #include "external_proto/cf_guest.pb.h" #include "external_proto/cf_host.pb.h" @@ -31,6 +31,7 @@ namespace cuttlefish { namespace { +using google::protobuf::Timestamp; using logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent; using logs::proto::wireless::android::cuttlefish::events::CuttlefishGuest; using logs::proto::wireless::android::cuttlefish::events:: @@ -48,6 +49,14 @@ uint64_t GetEpochTimeMs() { return milliseconds_since_epoch; } +Timestamp MillisToTimestamp(uint64_t millis) { + Timestamp timestamp; + timestamp.set_nanos((millis % 1000) * 1000000); + timestamp.set_seconds(millis / 1000); + + return timestamp; +} + CuttlefishGuest_EventType ConvertEventType(EventType event_type) { switch (event_type) { case EventType::DeviceInstantiation: @@ -91,11 +100,16 @@ CuttlefishHost_OsType ConvertHostOs(const HostInfo& host_info) { } } -void PopulateMetricsEvent(EventType event_type, - CuttlefishLogEvent& cf_log_event, - const HostInfo& host_metrics, - std::string_view session_id) { +CuttlefishLogEvent BuildCuttlefishLogEvent(const EventType event_type, + const HostInfo& host_metrics, + std::string_view session_id, + uint64_t now_ms) { + CuttlefishLogEvent cf_log_event; + cf_log_event.set_device_type(CuttlefishLogEvent::CUTTLEFISH_DEVICE_TYPE_HOST); cf_log_event.set_session_id(session_id); + cf_log_event.set_cuttlefish_version(GetVersionIds().ToString()); + *cf_log_event.mutable_timestamp_ms() = MillisToTimestamp(now_ms); + MetricsEventV2* metrics_event = cf_log_event.mutable_metrics_event_v2(); CuttlefishGuest* guest = metrics_event->add_guest(); @@ -105,6 +119,8 @@ void PopulateMetricsEvent(EventType event_type, CuttlefishHost* host = metrics_event->mutable_host(); host->set_host_os(ConvertHostOs(host_metrics)); host->set_host_os_version(host_metrics.release); + + return cf_log_event; } } // namespace @@ -113,8 +129,8 @@ LogRequest ConstructLogRequest(EventType event_type, const HostInfo& host_metrics, std::string_view session_id) { uint64_t now_ms = GetEpochTimeMs(); - CuttlefishLogEvent cf_log_event = metrics::BuildCfLogEvent(now_ms); - PopulateMetricsEvent(event_type, cf_log_event, host_metrics, session_id); + CuttlefishLogEvent cf_log_event = + BuildCuttlefishLogEvent(event_type, host_metrics, session_id, now_ms); LogEvent log_event = metrics::BuildLogEvent(now_ms, cf_log_event); return metrics::BuildLogRequest(now_ms, std::move(log_event)); } From ed8dcd4e90f64521cf85d7107e6f28bb8da60f3c Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Wed, 15 Oct 2025 16:15:12 -0700 Subject: [PATCH 3/5] Remove host/commands/metrics/clearcut_protos.h dep Bug: 452437293 --- .../cuttlefish/host/libs/metrics/BUILD.bazel | 2 +- .../host/libs/metrics/metrics_conversion.cc | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel index 5ad2ed5fa3..594af7693f 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel @@ -46,13 +46,13 @@ cf_cc_library( deps = [ "//cuttlefish/common/libs/utils:host_info", "//cuttlefish/host/commands/cvd/version", - "//cuttlefish/host/commands/metrics:clearcut_protos", "//cuttlefish/host/libs/metrics:event_type", "//external_proto:cf_guest_cc_proto", "//external_proto:cf_host_cc_proto", "//external_proto:cf_log_cc_proto", "//external_proto:cf_metrics_event_v2_cc_proto", "//external_proto:clientanalytics_cc_proto", + "//external_proto:log_source_enum_cc_proto", ], ) diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc index fd3dc40bc4..5036045477 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc @@ -20,13 +20,13 @@ #include "cuttlefish/common/libs/utils/host_info.h" #include "cuttlefish/host/commands/cvd/version/version.h" -#include "cuttlefish/host/commands/metrics/clearcut_protos.h" #include "cuttlefish/host/libs/metrics/event_type.h" #include "external_proto/cf_guest.pb.h" #include "external_proto/cf_host.pb.h" #include "external_proto/cf_log.pb.h" #include "external_proto/cf_metrics_event_v2.pb.h" #include "external_proto/clientanalytics.pb.h" +#include "external_proto/log_source_enum.pb.h" namespace cuttlefish { namespace { @@ -39,8 +39,14 @@ using logs::proto::wireless::android::cuttlefish::events:: using logs::proto::wireless::android::cuttlefish::events::CuttlefishHost; using logs::proto::wireless::android::cuttlefish::events::CuttlefishHost_OsType; using logs::proto::wireless::android::cuttlefish::events::MetricsEventV2; +using wireless_android_play_playlog::ClientInfo; using wireless_android_play_playlog::LogEvent; using wireless_android_play_playlog::LogRequest; +using wireless_android_play_playlog::LogSourceEnum::LogSource; + +static constexpr LogSource kLogSourceId = LogSource::CUTTLEFISH_METRICS; +static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS"; +static constexpr ClientInfo::ClientType kCppClientType = ClientInfo::CPLUSPLUS; uint64_t GetEpochTimeMs() { auto now = std::chrono::system_clock::now().time_since_epoch(); @@ -123,6 +129,22 @@ CuttlefishLogEvent BuildCuttlefishLogEvent(const EventType event_type, return cf_log_event; } +LogRequest BuildLogRequest(uint64_t now_ms, + const CuttlefishLogEvent& cf_log_event) { + LogRequest log_request; + log_request.set_request_time_ms(now_ms); + log_request.set_log_source(kLogSourceId); + log_request.set_log_source_name(kLogSourceStr); + + ClientInfo* client_info = log_request.mutable_client_info(); + client_info->set_client_type(kCppClientType); + + LogEvent* log_event = log_request.add_log_event(); + log_event->set_event_time_ms(now_ms); + log_event->set_source_extension(cf_log_event.SerializeAsString()); + return log_request; +} + } // namespace LogRequest ConstructLogRequest(EventType event_type, @@ -131,8 +153,7 @@ LogRequest ConstructLogRequest(EventType event_type, uint64_t now_ms = GetEpochTimeMs(); CuttlefishLogEvent cf_log_event = BuildCuttlefishLogEvent(event_type, host_metrics, session_id, now_ms); - LogEvent log_event = metrics::BuildLogEvent(now_ms, cf_log_event); - return metrics::BuildLogRequest(now_ms, std::move(log_event)); + return BuildLogRequest(now_ms, cf_log_event); } } // namespace cuttlefish From 0291ed2ec26135a9b83d30f6b85c6ab04f87a534 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Wed, 15 Oct 2025 16:20:59 -0700 Subject: [PATCH 4/5] Move data collection logic to orchestration Keeping conversion focused on building the proto from the internal representations. Bug: 452437293 --- .../cuttlefish/host/libs/metrics/BUILD.bazel | 2 +- .../host/libs/metrics/metrics_conversion.cc | 20 +++++++------------ .../host/libs/metrics/metrics_conversion.h | 4 +++- .../libs/metrics/metrics_orchestration.cc | 16 +++++++++++++-- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel index 594af7693f..54179e3ccc 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel @@ -45,7 +45,6 @@ cf_cc_library( ], deps = [ "//cuttlefish/common/libs/utils:host_info", - "//cuttlefish/host/commands/cvd/version", "//cuttlefish/host/libs/metrics:event_type", "//external_proto:cf_guest_cc_proto", "//external_proto:cf_host_cc_proto", @@ -78,6 +77,7 @@ cf_cc_library( "//cuttlefish/common/libs/utils:result", "//cuttlefish/host/commands/cvd/instances", "//cuttlefish/host/commands/cvd/metrics:is_enabled", + "//cuttlefish/host/commands/cvd/version", "//cuttlefish/host/libs/metrics:event_type", "//cuttlefish/host/libs/metrics:metrics_conversion", "//cuttlefish/host/libs/metrics:metrics_transmitter", diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc index 5036045477..343f77a4c8 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc @@ -19,7 +19,6 @@ #include #include "cuttlefish/common/libs/utils/host_info.h" -#include "cuttlefish/host/commands/cvd/version/version.h" #include "cuttlefish/host/libs/metrics/event_type.h" #include "external_proto/cf_guest.pb.h" #include "external_proto/cf_host.pb.h" @@ -48,13 +47,6 @@ static constexpr LogSource kLogSourceId = LogSource::CUTTLEFISH_METRICS; static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS"; static constexpr ClientInfo::ClientType kCppClientType = ClientInfo::CPLUSPLUS; -uint64_t GetEpochTimeMs() { - auto now = std::chrono::system_clock::now().time_since_epoch(); - uint64_t milliseconds_since_epoch = - std::chrono::duration_cast(now).count(); - return milliseconds_since_epoch; -} - Timestamp MillisToTimestamp(uint64_t millis) { Timestamp timestamp; timestamp.set_nanos((millis % 1000) * 1000000); @@ -109,11 +101,12 @@ CuttlefishHost_OsType ConvertHostOs(const HostInfo& host_info) { CuttlefishLogEvent BuildCuttlefishLogEvent(const EventType event_type, const HostInfo& host_metrics, std::string_view session_id, + std::string_view cf_common_version, uint64_t now_ms) { CuttlefishLogEvent cf_log_event; cf_log_event.set_device_type(CuttlefishLogEvent::CUTTLEFISH_DEVICE_TYPE_HOST); cf_log_event.set_session_id(session_id); - cf_log_event.set_cuttlefish_version(GetVersionIds().ToString()); + cf_log_event.set_cuttlefish_version(cf_common_version); *cf_log_event.mutable_timestamp_ms() = MillisToTimestamp(now_ms); MetricsEventV2* metrics_event = cf_log_event.mutable_metrics_event_v2(); @@ -149,10 +142,11 @@ LogRequest BuildLogRequest(uint64_t now_ms, LogRequest ConstructLogRequest(EventType event_type, const HostInfo& host_metrics, - std::string_view session_id) { - uint64_t now_ms = GetEpochTimeMs(); - CuttlefishLogEvent cf_log_event = - BuildCuttlefishLogEvent(event_type, host_metrics, session_id, now_ms); + std::string_view session_id, + std::string_view cf_common_version, + uint64_t now_ms) { + CuttlefishLogEvent cf_log_event = BuildCuttlefishLogEvent( + event_type, host_metrics, session_id, cf_common_version, now_ms); return BuildLogRequest(now_ms, cf_log_event); } diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h index 78510bf4f4..29da95dcdf 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include "cuttlefish/common/libs/utils/host_info.h" @@ -26,6 +27,7 @@ namespace cuttlefish { wireless_android_play_playlog::LogRequest ConstructLogRequest( EventType event_type, const HostInfo& host_metrics, - std::string_view session_id); + std::string_view session_id, std::string_view cf_common_version, + uint64_t now_ms); } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc index e3cbc7ff82..11afaf148f 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc @@ -16,6 +16,8 @@ #include "cuttlefish/host/libs/metrics/metrics_orchestration.h" +#include +#include #include #include @@ -26,6 +28,7 @@ #include "cuttlefish/common/libs/utils/result.h" #include "cuttlefish/host/commands/cvd/instances/instance_group_record.h" #include "cuttlefish/host/commands/cvd/metrics/is_enabled.h" +#include "cuttlefish/host/commands/cvd/version/version.h" #include "cuttlefish/host/libs/metrics/event_type.h" #include "cuttlefish/host/libs/metrics/metrics_conversion.h" #include "cuttlefish/host/libs/metrics/metrics_transmitter.h" @@ -46,6 +49,13 @@ constexpr char kReadmeText[] = "step" " when it does>"; +uint64_t GetEpochTimeMs() { + auto now = std::chrono::system_clock::now().time_since_epoch(); + uint64_t milliseconds_since_epoch = + std::chrono::duration_cast(now).count(); + return milliseconds_since_epoch; +} + std::string GetMetricsDirectoryFilepath( const LocalInstanceGroup& instance_group) { return instance_group.HomeDir() + "/metrics"; @@ -63,9 +73,11 @@ Result GatherAndWriteMetrics(EventType event_type, const std::string session_id = CF_EXPECT(ReadSessionIdFile(metrics_directory)); const HostInfo host_metrics = GetHostInfo(); + const std::string cf_common_version = GetVersionIds().ToString(); + uint64_t now_ms = GetEpochTimeMs(); // TODO: chadreynolds - gather the rest of the data (guest/flag information) - const LogRequest log_request = - ConstructLogRequest(event_type, host_metrics, session_id); + const LogRequest log_request = ConstructLogRequest( + event_type, host_metrics, session_id, cf_common_version, now_ms); CF_EXPECT(WriteMetricsEvent(event_type, metrics_directory, log_request)); if (kEnableCvdMetrics) { From 67bfd5006b958776a1bf50bd977c3c1dba1db061 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Tue, 21 Oct 2025 11:30:11 -0700 Subject: [PATCH 5/5] Convert uint64_t to std::chrono::milliseconds Better to use a more semantically accurate type. --- .../host/libs/metrics/metrics_conversion.cc | 27 ++++++++++--------- .../host/libs/metrics/metrics_conversion.h | 4 +-- .../libs/metrics/metrics_orchestration.cc | 11 +++----- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc index 343f77a4c8..f86ed65782 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.cc @@ -16,7 +16,9 @@ #include "cuttlefish/host/libs/metrics/metrics_conversion.h" -#include +#include +#include +#include #include "cuttlefish/common/libs/utils/host_info.h" #include "cuttlefish/host/libs/metrics/event_type.h" @@ -47,11 +49,10 @@ static constexpr LogSource kLogSourceId = LogSource::CUTTLEFISH_METRICS; static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS"; static constexpr ClientInfo::ClientType kCppClientType = ClientInfo::CPLUSPLUS; -Timestamp MillisToTimestamp(uint64_t millis) { +Timestamp ToTimestamp(std::chrono::milliseconds ms) { Timestamp timestamp; - timestamp.set_nanos((millis % 1000) * 1000000); - timestamp.set_seconds(millis / 1000); - + timestamp.set_nanos((ms.count() % 1000) * 1000000); + timestamp.set_seconds(ms.count() / 1000); return timestamp; } @@ -102,12 +103,12 @@ CuttlefishLogEvent BuildCuttlefishLogEvent(const EventType event_type, const HostInfo& host_metrics, std::string_view session_id, std::string_view cf_common_version, - uint64_t now_ms) { + std::chrono::milliseconds now) { CuttlefishLogEvent cf_log_event; cf_log_event.set_device_type(CuttlefishLogEvent::CUTTLEFISH_DEVICE_TYPE_HOST); cf_log_event.set_session_id(session_id); cf_log_event.set_cuttlefish_version(cf_common_version); - *cf_log_event.mutable_timestamp_ms() = MillisToTimestamp(now_ms); + *cf_log_event.mutable_timestamp_ms() = ToTimestamp(now); MetricsEventV2* metrics_event = cf_log_event.mutable_metrics_event_v2(); @@ -122,10 +123,10 @@ CuttlefishLogEvent BuildCuttlefishLogEvent(const EventType event_type, return cf_log_event; } -LogRequest BuildLogRequest(uint64_t now_ms, +LogRequest BuildLogRequest(std::chrono::milliseconds now, const CuttlefishLogEvent& cf_log_event) { LogRequest log_request; - log_request.set_request_time_ms(now_ms); + log_request.set_request_time_ms(now.count()); log_request.set_log_source(kLogSourceId); log_request.set_log_source_name(kLogSourceStr); @@ -133,7 +134,7 @@ LogRequest BuildLogRequest(uint64_t now_ms, client_info->set_client_type(kCppClientType); LogEvent* log_event = log_request.add_log_event(); - log_event->set_event_time_ms(now_ms); + log_event->set_event_time_ms(now.count()); log_event->set_source_extension(cf_log_event.SerializeAsString()); return log_request; } @@ -144,10 +145,10 @@ LogRequest ConstructLogRequest(EventType event_type, const HostInfo& host_metrics, std::string_view session_id, std::string_view cf_common_version, - uint64_t now_ms) { + std::chrono::milliseconds now) { CuttlefishLogEvent cf_log_event = BuildCuttlefishLogEvent( - event_type, host_metrics, session_id, cf_common_version, now_ms); - return BuildLogRequest(now_ms, cf_log_event); + event_type, host_metrics, session_id, cf_common_version, now); + return BuildLogRequest(now, cf_log_event); } } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h index 29da95dcdf..531a034340 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_conversion.h @@ -16,7 +16,7 @@ #pragma once -#include +#include #include #include "cuttlefish/common/libs/utils/host_info.h" @@ -28,6 +28,6 @@ namespace cuttlefish { wireless_android_play_playlog::LogRequest ConstructLogRequest( EventType event_type, const HostInfo& host_metrics, std::string_view session_id, std::string_view cf_common_version, - uint64_t now_ms); + std::chrono::milliseconds now); } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc index 11afaf148f..ef6eb9ceb4 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc @@ -17,7 +17,6 @@ #include "cuttlefish/host/libs/metrics/metrics_orchestration.h" #include -#include #include #include @@ -49,11 +48,9 @@ constexpr char kReadmeText[] = "step" " when it does>"; -uint64_t GetEpochTimeMs() { +std::chrono::milliseconds GetEpochTime() { auto now = std::chrono::system_clock::now().time_since_epoch(); - uint64_t milliseconds_since_epoch = - std::chrono::duration_cast(now).count(); - return milliseconds_since_epoch; + return std::chrono::duration_cast(now); } std::string GetMetricsDirectoryFilepath( @@ -74,10 +71,10 @@ Result GatherAndWriteMetrics(EventType event_type, CF_EXPECT(ReadSessionIdFile(metrics_directory)); const HostInfo host_metrics = GetHostInfo(); const std::string cf_common_version = GetVersionIds().ToString(); - uint64_t now_ms = GetEpochTimeMs(); + std::chrono::milliseconds now = GetEpochTime(); // TODO: chadreynolds - gather the rest of the data (guest/flag information) const LogRequest log_request = ConstructLogRequest( - event_type, host_metrics, session_id, cf_common_version, now_ms); + event_type, host_metrics, session_id, cf_common_version, now); CF_EXPECT(WriteMetricsEvent(event_type, metrics_directory, log_request)); if (kEnableCvdMetrics) {