Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Result<void> CvdFetchCommandHandler::Handle(const CommandRequest& request) {
std::string log_file = GetFetchLogsFileName(flags.target_directory);
ScopedLogger logger(SeverityTarget::FromFile(log_file), "");

Result<std::vector<FetchResult>> result = FetchCvdMain(flags);
Result<FetchResult> result = FetchCvdMain(flags);
if (flags.build_api_flags.enable_caching) {
VLOG(0) << "Running automatic cache cleanup";
const std::string cache_directory = PerUserCacheDir();
Expand Down
17 changes: 9 additions & 8 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ Result<void> FetchTarget(FetchContext& fetch_context,
return {};
}

Result<std::vector<FetchResult>> Fetch(const FetchFlags& flags,
const std::string& cache_base_path,
const HostToolsTarget& host_target,
std::vector<Target>& targets) {
Result<FetchResult> Fetch(const FetchFlags& flags,
const std::string& cache_base_path,
const HostToolsTarget& host_target,
std::vector<Target>& targets) {
#ifdef __BIONIC__
// TODO(schuffelen): Find a better way to deal with tzdata
setenv("ANDROID_TZDATA_ROOT", "/", /* overwrite */ 0);
Expand Down Expand Up @@ -475,7 +475,7 @@ Result<std::vector<FetchResult>> 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<FetchResult> fetch_results;
FetchResult fetch_result;
for (const auto& target : targets) {
FetcherConfig config;
FetchContext fetch_context(downloaders.AndroidBuild(), target.directories,
Expand All @@ -492,7 +492,7 @@ Result<std::vector<FetchResult>> 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,
});
Expand All @@ -503,9 +503,10 @@ Result<std::vector<FetchResult>> 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
Expand All @@ -514,7 +515,7 @@ std::string GetFetchLogsFileName(const std::string& target_directory) {
return target_directory + "/fetch.log";
}

Result<std::vector<FetchResult>> FetchCvdMain(const FetchFlags& flags) {
Result<FetchResult> FetchCvdMain(const FetchFlags& flags) {
const bool append_subdirectory = ShouldAppendSubdirectory(flags);
std::vector<Target> targets = GetFetchTargets(flags, append_subdirectory);
HostToolsTarget host_target =
Expand Down
12 changes: 10 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <stddef.h>

#include <string>
#include <vector>

Expand All @@ -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<FetchArtifacts> fetch_artifacts;
size_t fetch_size_bytes = 0;
};

std::string GetFetchLogsFileName(const std::string& target_directory);

Result<std::vector<FetchResult>> FetchCvdMain(const FetchFlags& flags);
Result<FetchResult> FetchCvdMain(const FetchFlags& flags);

} // namespace cuttlefish
10 changes: 10 additions & 0 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#pragma once

#include <stddef.h>

#include <memory>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -47,6 +49,7 @@ class FetchTracer {
Trace NewTrace(std::string name);

std::string ToStyledString() const;
size_t TotalSizeBytes() const;

private:
std::vector<std::pair<std::string, std::shared_ptr<TraceImpl>>> traces_;
Expand Down
2 changes: 2 additions & 0 deletions base/cvd/cuttlefish/host/libs/web/android_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> filepath;
};

Expand Down
9 changes: 5 additions & 4 deletions base/cvd/cuttlefish/host/libs/web/android_build_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ Result<Build> 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,
};
}
Expand Down Expand Up @@ -230,7 +231,7 @@ Result<AndroidBuildApi::BuildInfo> AndroidBuildApi::GetBuildInfo(
};
}

Result<void> AndroidBuildApi::BlockUntilTerminalStatus(
Result<bool> 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);
Expand Down Expand Up @@ -259,7 +260,7 @@ Result<void> AndroidBuildApi::BlockUntilTerminalStatus(
"Error retrying build status retrieval");
status = CF_EXPECT(GetValue<std::string>(json, {"buildAttemptStatus"}));
}
return {};
return has_retried;
}

Result<std::vector<std::string>> AndroidBuildApi::Headers() {
Expand Down
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/libs/web/android_build_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AndroidBuildApi : public BuildApi {
};
Result<BuildInfo> GetBuildInfo(std::string_view build_id,
std::string_view target);
Result<void> BlockUntilTerminalStatus(std::string_view initial_status,
Result<bool> BlockUntilTerminalStatus(std::string_view initial_status,
std::string_view build_id,
std::string_view target);
Result<std::vector<std::string>> Headers();
Expand Down
Loading