Skip to content

Commit 18282fc

Browse files
committed
Reuse metrics code to send more complete metrics messages
Bug: b/446266666
1 parent b60682e commit 18282fc

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,10 @@ cf_cc_library(
400400
"//cuttlefish/host/commands/cvd/instances/lock",
401401
"//cuttlefish/host/commands/cvd/metrics:is_enabled",
402402
"//cuttlefish/host/commands/cvd/utils",
403-
"//cuttlefish/host/commands/metrics:libmetrics_utils",
403+
"//cuttlefish/host/commands/metrics:events",
404404
"//cuttlefish/host/libs/config:config_constants",
405405
"//cuttlefish/host/libs/config:cuttlefish_config",
406+
"//cuttlefish/host/libs/config:vmm_mode",
406407
"//cuttlefish/host/libs/metrics:metrics_headers",
407408
"//external_proto:cf_log_cc_proto",
408409
"//external_proto:clientanalytics_cc_proto",

base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,15 @@
6565
#include "cuttlefish/host/commands/cvd/utils/common.h"
6666
#include "cuttlefish/host/commands/cvd/utils/interrupt_listener.h"
6767
#include "cuttlefish/host/commands/cvd/utils/subprocess_waiter.h"
68-
#include "cuttlefish/host/commands/metrics/utils.h"
68+
#include "cuttlefish/host/commands/metrics/events.h"
6969
#include "cuttlefish/host/libs/config/config_constants.h"
7070
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
71+
#include "cuttlefish/host/libs/config/vmm_mode.h"
7172
#include "cuttlefish/host/libs/metrics/metrics_defs.h"
72-
#include "external_proto/cf_log.pb.h"
73-
#include "external_proto/clientanalytics.pb.h"
74-
#include "external_proto/log_source_enum.pb.h"
7573

7674
namespace cuttlefish {
7775
namespace {
7876

79-
using logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent;
80-
using wireless_android_play_playlog::ClientInfo;
81-
using wireless_android_play_playlog::LogEvent;
82-
using wireless_android_play_playlog::LogRequest;
83-
using wireless_android_play_playlog::LogSourceEnum::LogSource;
84-
8577
std::optional<std::string> GetConfigPath(cvd_common::Args& args) {
8678
std::size_t initial_size = args.size();
8779
std::string config_file;
@@ -635,32 +627,10 @@ Result<void> CvdStartCommandHandler::LaunchDevice(
635627
"Policy (https://policies.google.com/privacy) describes how Google "
636628
"handles information generated as you use Google services.";
637629
if (kEnableCvdMetrics) {
638-
static constexpr LogSource kLogSourceId = LogSource::CUTTLEFISH_METRICS;
639-
static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS";
640-
static constexpr ClientInfo::ClientType kCppClientType =
641-
ClientInfo::CPLUSPLUS;
642-
643630
LOG(INFO) << "This will automatically send diagnostic information to "
644631
"Google, such as crash reports and usage data from the host "
645632
"machine managing the Android Virtual Device.";
646-
CuttlefishLogEvent cf_log_event;
647-
648-
cf_log_event.set_session_id("cvd-todo-session");
649-
650-
LogRequest request_proto;
651-
request_proto.set_log_source(kLogSourceId);
652-
request_proto.set_log_source_name(kLogSourceStr);
653-
654-
ClientInfo& client_info = *request_proto.mutable_client_info();
655-
client_info.set_client_type(kCppClientType);
656-
657-
LogEvent& log_event = *request_proto.add_log_event();
658-
log_event.set_event_time_ms(metrics::GetEpochTimeMs());
659-
log_event.set_source_extension(cf_log_event.SerializeAsString());
660-
661-
std::string request_string = request_proto.SerializeAsString();
662-
MetricsExitCodes reporting_outcome =
663-
metrics::PostRequest(request_string, metrics::ClearcutServer::kProd);
633+
int reporting_outcome = metrics::SendVMStart(VmmMode::kUnknown);
664634
if (reporting_outcome != MetricsExitCodes::kSuccess) {
665635
LOG(ERROR) << "Issue reporting metrics: " << reporting_outcome;
666636
}
@@ -705,6 +675,13 @@ Result<void> CvdStartCommandHandler::LaunchDeviceInterruptible(
705675
return start_res;
706676
}
707677

678+
if (kEnableCvdMetrics) {
679+
int reporting_outcome = metrics::SendDeviceBoot(VmmMode::kUnknown);
680+
if (reporting_outcome != MetricsExitCodes::kSuccess) {
681+
LOG(ERROR) << "Issue reporting metrics: " << reporting_outcome;
682+
}
683+
}
684+
708685
return {};
709686
}
710687

0 commit comments

Comments
 (0)