Skip to content

Group-level logs#2529

Open
ser-io wants to merge 2 commits intogoogle:mainfrom
ser-io:assemble-cvd-logs
Open

Group-level logs#2529
ser-io wants to merge 2 commits intogoogle:mainfrom
ser-io:assemble-cvd-logs

Conversation

@ser-io
Copy link
Copy Markdown
Member

@ser-io ser-io commented May 7, 2026

No description provided.

@ser-io ser-io requested a review from jemoreira May 7, 2026 19:19
@ser-io ser-io changed the title Assemble cvd logs Group-level logs May 7, 2026
@ser-io ser-io force-pushed the assemble-cvd-logs branch from 1fa0203 to 02f1b40 Compare May 7, 2026 19:24
@ser-io ser-io force-pushed the assemble-cvd-logs branch from 02f1b40 to 5a23efb Compare May 7, 2026 19:51
return {};
}

Result<std::vector<std::string>> Filter(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please choose a less generic name, one that more clearly conveys what this function does. Consider RemoveInaccessibleFiles.

}

Result<std::vector<std::string>> Filter(
const std::vector<std::string>& filenames) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider accepting the input by value instead of reference. Then you can implement the function such that it modifies and returns the parameter. Something like this:

std::vector<std::string> Filter(std::vector<std::string> files) {
  auto removed_begin = std::remove_if(files.begin(), files.end(), [](const std::string& file){ return !IsAccessible(file);});
  files.erase(removed_begin, files.end());
  return files;
}

That implementation can avoid all copies of the vector if the parameter is moved into it (which is the case where this function is called as it's given a temporary object), otherwise it makes a single copy (at the call site) just like the original. See go/totw/117 for details.

const std::vector<std::string>& filenames) {
std::vector<std::string> result = {};
for (auto& filename : filenames) {
if (access(filename.data(), F_OK) == 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Consider using c_str() instead of data(). While data and c_str do the same thing since C++11, using c_str makes it clear that a null terminated string is required. data is more appropriate when you need to modify the contents of the string or don't care about the null character at the end.

return {};
}

Result<std::vector<std::string>> Filter(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't return Result if the function can't fail

if (opts.print_target.empty()) {
CF_EXPECT(PrintLogsList(logs_dir));
if (logs_filenames.empty()) {
LOG(INFO) << "There are no logs files available";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "log files"

Comment on lines +277 to +283
instance_dir() + "/logs/" + "build_info.log",
instance_dir() + "/logs/" + "crosvm_openwrt_boot.log",
instance_dir() + "/logs/" + "crosvm_openwrt.log",
instance_dir() + "/logs/" + "kernel.log",
instance_dir() + "/logs/" + "launcher.log",
instance_dir() + "/logs/" + "logcat",
instance_dir() + "/logs/" + "modem_simulator.log",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode this list. Use every file from the directory that is not a group log file, otherwise this code will miss any new file added. It's OK to hardcode the group log list though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants