Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qemu] Make logging code terser #3653

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

ricab
Copy link
Collaborator

@ricab ricab commented Aug 30, 2024

Condense code to log mismatches between suspension snapshot and VM state. Just trying to reduce the space that is taken by logging code, which dilutes actual logic for the reader.

This could be further improved by adding a formatter for the State enum to multipass/format.h. That would be useful in other places too, but we should then probably also move the corresponding logic from the CLI formatters, so leaving that for now.

Condense code to log mismatches between suspension snapshot and VM
state.
@ricab ricab requested a review from georgeliao August 30, 2024 11:23
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.88%. Comparing base (1b2ae43) to head (329d131).
Report is 2 commits behind head on force_stop_on_no_suspend_tag.

Additional details and impacted files
@@                       Coverage Diff                        @@
##           force_stop_on_no_suspend_tag    #3653      +/-   ##
================================================================
- Coverage                         88.89%   88.88%   -0.01%     
================================================================
  Files                               254      254              
  Lines                             14258    14230      -28     
================================================================
- Hits                              12675    12649      -26     
+ Misses                             1583     1581       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@georgeliao georgeliao left a comment

Choose a reason for hiding this comment

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

@ricab , it looks good, only comments on the code, no requested change.

fmt::format("{} has the image suspension snapshot, but it is not in the suspended state", vm_name));
}
const auto has_suspend_snapshot = mp::backend::instance_image_has_snapshot(desc.image.image_path, suspend_tag);
if (has_suspend_snapshot != (state == State::suspended)) // clang-format off
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice trick to utilize the symmetry.

if (has_suspend_snapshot != (state == State::suspended)) // clang-format off
mpl::log(mpl::Level::warning, vm_name, fmt::format("Image has {} suspension snapshot, but the state is {}",
has_suspend_snapshot ? "a" : "no",
static_cast<short>(state))); // clang-format on

Copy link
Contributor

Choose a reason for hiding this comment

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

The only problem of this is the integer value returns to us via static_cast<short>(state), however, enum -> string map or a switch statement may not worth it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, this is what my comment above about formatters is about. Ideally, we'd write a Formatter for VM::State... see above.

@georgeliao georgeliao merged commit eca4986 into force_stop_on_no_suspend_tag Aug 30, 2024
14 checks passed
@georgeliao georgeliao deleted the condense-logging-code branch August 30, 2024 12:57
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