diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/fetch.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/fetch.cpp index 7b9d4f93de1..6e14eb1e948 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/fetch.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/fetch.cpp @@ -59,7 +59,7 @@ Result CvdFetchCommandHandler::Handle(const CommandRequest& request) { std::string log_file = GetFetchLogsFileName(flags.target_directory); ScopedLogger logger(SeverityTarget::FromFile(log_file), ""); - Result> result = FetchCvdMain(flags); + Result result = FetchCvdMain(flags); if (flags.build_api_flags.enable_caching) { VLOG(0) << "Running automatic cache cleanup"; const std::string cache_directory = PerUserCacheDir(); diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc index 6b89e675014..41ae936f53e 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc @@ -443,10 +443,10 @@ Result FetchTarget(FetchContext& fetch_context, return {}; } -Result> Fetch(const FetchFlags& flags, - const std::string& cache_base_path, - const HostToolsTarget& host_target, - std::vector& targets) { +Result Fetch(const FetchFlags& flags, + const std::string& cache_base_path, + const HostToolsTarget& host_target, + std::vector& targets) { #ifdef __BIONIC__ // TODO(schuffelen): Find a better way to deal with tzdata setenv("ANDROID_TZDATA_ROOT", "/", /* overwrite */ 0); @@ -475,7 +475,7 @@ Result> Fetch(const FetchFlags& flags, std::cref(flags.keep_downloaded_archives), std::cref(flags.host_substitutions), tracer.NewTrace("Host Package")); size_t count = 1; - std::vector fetch_results; + FetchResult fetch_result; for (const auto& target : targets) { FetcherConfig config; FetchContext fetch_context(downloaders.AndroidBuild(), target.directories, @@ -492,7 +492,7 @@ Result> Fetch(const FetchFlags& flags, const std::string config_path = CF_EXPECT(SaveConfig(config, target.directories.root)); - fetch_results.emplace_back(FetchResult{ + fetch_result.fetch_artifacts.emplace_back(FetchArtifacts{ .fetcher_config_path = config_path, .builds = target.builds, }); @@ -503,9 +503,10 @@ Result> Fetch(const FetchFlags& flags, VLOG(0) << "Waiting for host package fetch"; CF_EXPECT(host_package_future.get()); VLOG(0) << "Performance stats:\n" << tracer.ToStyledString(); + fetch_result.fetch_size_bytes = tracer.TotalSizeBytes(); LOG(INFO) << "Completed all fetches"; - return fetch_results; + return fetch_result; } } // namespace @@ -514,7 +515,7 @@ std::string GetFetchLogsFileName(const std::string& target_directory) { return target_directory + "/fetch.log"; } -Result> FetchCvdMain(const FetchFlags& flags) { +Result FetchCvdMain(const FetchFlags& flags) { const bool append_subdirectory = ShouldAppendSubdirectory(flags); std::vector targets = GetFetchTargets(flags, append_subdirectory); HostToolsTarget host_target = diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.h b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.h index 43f4c2f4f2e..ad67253a42e 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.h +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.h @@ -15,6 +15,8 @@ #pragma once +#include + #include #include @@ -24,13 +26,19 @@ namespace cuttlefish { -struct FetchResult { +struct FetchArtifacts { std::string fetcher_config_path; + bool status_blocked = false; // blocked fetching waiting on terminal status Builds builds; }; +struct FetchResult { + std::vector fetch_artifacts; + size_t fetch_size_bytes = 0; +}; + std::string GetFetchLogsFileName(const std::string& target_directory); -Result> FetchCvdMain(const FetchFlags& flags); +Result FetchCvdMain(const FetchFlags& flags); } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.cpp b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.cpp index b02d9589900..df5cdb6a563 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.cpp @@ -151,4 +151,14 @@ std::string FetchTracer::ToStyledString() const { return ss.str(); } +size_t FetchTracer::TotalSizeBytes() const { + size_t total = 0; + for (const auto& [name, trace] : traces_) { + for (const auto& phase : trace->phases) { + total += phase.size_bytes.value_or(0); + } + } + return total; +} + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.h b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.h index 4d131257850..28358054513 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.h +++ b/base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.h @@ -15,6 +15,8 @@ #pragma once +#include + #include #include #include @@ -47,6 +49,7 @@ class FetchTracer { Trace NewTrace(std::string name); std::string ToStyledString() const; + size_t TotalSizeBytes() const; private: std::vector>> traces_; diff --git a/base/cvd/cuttlefish/host/libs/web/android_build.h b/base/cvd/cuttlefish/host/libs/web/android_build.h index de7583f9422..2d48740e897 100644 --- a/base/cvd/cuttlefish/host/libs/web/android_build.h +++ b/base/cvd/cuttlefish/host/libs/web/android_build.h @@ -29,6 +29,8 @@ struct DeviceBuild { std::string target; std::string product; bool is_signed = false; + // did retrieving build details block waiting for a terminal status + bool status_blocked = false; std::optional filepath; }; diff --git a/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp b/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp index aeaf0f4fcee..95c7aefff68 100644 --- a/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp +++ b/base/cvd/cuttlefish/host/libs/web/android_build_api.cpp @@ -114,14 +114,15 @@ Result AndroidBuildApi::GetBuild(const DeviceBuildString& build_string) { AndroidBuildApi::BuildInfo build_info = CF_EXPECT(GetBuildInfo(proposed_build_id, *build_string.target)); - CF_EXPECT(BlockUntilTerminalStatus(build_info.status, proposed_build_id, - build_info.target)); + const bool blocked_on_status = CF_EXPECT(BlockUntilTerminalStatus( + build_info.status, proposed_build_id, build_info.target)); return DeviceBuild{ .id = proposed_build_id, .branch = build_info.branch, .target = build_info.target, .product = build_info.product, .is_signed = build_info.is_signed, + .status_blocked = blocked_on_status, .filepath = build_string.filepath, }; } @@ -230,7 +231,7 @@ Result AndroidBuildApi::GetBuildInfo( }; } -Result AndroidBuildApi::BlockUntilTerminalStatus( +Result AndroidBuildApi::BlockUntilTerminalStatus( std::string_view initial_status, std::string_view build_id, std::string_view target) { const std::string url = android_build_url_->GetBuildUrl(build_id, target); @@ -259,7 +260,7 @@ Result AndroidBuildApi::BlockUntilTerminalStatus( "Error retrying build status retrieval"); status = CF_EXPECT(GetValue(json, {"buildAttemptStatus"})); } - return {}; + return has_retried; } Result> AndroidBuildApi::Headers() { diff --git a/base/cvd/cuttlefish/host/libs/web/android_build_api.h b/base/cvd/cuttlefish/host/libs/web/android_build_api.h index 4e99225d3bd..b7d0a9609be 100644 --- a/base/cvd/cuttlefish/host/libs/web/android_build_api.h +++ b/base/cvd/cuttlefish/host/libs/web/android_build_api.h @@ -70,7 +70,7 @@ class AndroidBuildApi : public BuildApi { }; Result GetBuildInfo(std::string_view build_id, std::string_view target); - Result BlockUntilTerminalStatus(std::string_view initial_status, + Result BlockUntilTerminalStatus(std::string_view initial_status, std::string_view build_id, std::string_view target); Result> Headers();