Skip to content

Commit

Permalink
tracing::instrument everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ifd3f committed Nov 10, 2023
1 parent fdec8e0 commit 519a7c3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/burn/state_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ impl ChildState {
ChildState::Burning(Burning::new(now, is_input_compressed, input_file_bytes))
}

#[tracing::instrument(skip_all, fields(now, msg))]
pub fn on_status(mut self, now: Instant, msg: Option<StatusMessage>) -> Self {
match msg {
Some(StatusMessage::TotalBytes { src, dest }) => {
self.on_total_bytes(now, src, dest);
self
}
Some(StatusMessage::FinishedWriting { verifying }) => {
debug!(verifying, "Got FinishedWriting");
match self {
ChildState::Burning(st) => st.into_finished(now, verifying),
c => c,
Expand Down
5 changes: 5 additions & 0 deletions src/ui/ask_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{

use super::cli::{BurnArgs, HashArg, HashOf};

#[tracing::instrument(skip_all, fields(cf))]
pub fn ask_hash(args: &BurnArgs, cf: CompressionFormat) -> anyhow::Result<Option<FileHashInfo>> {
let hash_params = match &args.hash {
HashArg::Skip => None,
Expand Down Expand Up @@ -54,6 +55,7 @@ pub fn ask_hash(args: &BurnArgs, cf: CompressionFormat) -> anyhow::Result<Option
Ok(Some(hash_result))
}

#[tracing::instrument]
fn ask_hash_loop(cf: CompressionFormat) -> anyhow::Result<Option<BeginHashParams>> {
loop {
match ask_hash_once(cf) {
Expand Down Expand Up @@ -118,6 +120,7 @@ fn ask_hash_once(cf: CompressionFormat) -> anyhow::Result<BeginHashParams> {
})
}

#[tracing::instrument]
fn ask_hasher_compression(
cf: CompressionFormat,
hash_of: Option<HashOf>,
Expand All @@ -140,6 +143,7 @@ fn ask_hasher_compression(
})
}

#[tracing::instrument(skip_all, fields(path))]
fn do_hashing(path: &Path, params: &BeginHashParams) -> anyhow::Result<FileHashInfo> {
let mut file = File::open(path)?;

Expand Down Expand Up @@ -170,6 +174,7 @@ fn do_hashing(path: &Path, params: &BeginHashParams) -> anyhow::Result<FileHashI
}
}

#[derive(Debug)]
struct BeginHashParams {
expected_hash: Vec<u8>,
alg: HashAlg,
Expand Down
4 changes: 4 additions & 0 deletions src/ui/ask_outfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{

use super::burn::start::BeginParams;

#[tracing::instrument(skip_all)]
pub fn ask_compression(args: &BurnArgs) -> anyhow::Result<CompressionFormat> {
let cf = match args.compression {
CompressionArg::Auto | CompressionArg::Ask => {
Expand Down Expand Up @@ -53,6 +54,7 @@ pub fn ask_compression(args: &BurnArgs) -> anyhow::Result<CompressionFormat> {
return Ok(format);
}

#[tracing::instrument(skip_all)]
pub fn ask_outfile(args: &BurnArgs) -> anyhow::Result<BurnTarget> {
let mut show_all_disks = args.show_all_disks;

Expand Down Expand Up @@ -83,6 +85,7 @@ pub fn ask_outfile(args: &BurnArgs) -> anyhow::Result<BurnTarget> {
}
}

#[tracing::instrument(skip_all)]
pub fn confirm_write(args: &BurnArgs, begin_params: &BeginParams) -> Result<bool, InquireError> {
if args.force {
debug!("Skipping confirm because of --force");
Expand Down Expand Up @@ -127,6 +130,7 @@ impl fmt::Display for ListOption {
}
}

#[tracing::instrument]
fn enumerate_options(show_all_disks: bool) -> anyhow::Result<Vec<ListOption>> {
let mut burn_targets: Vec<BurnTarget> = enumerate_devices()
.filter(|d| show_all_disks || d.removable == Removable::Yes)
Expand Down
2 changes: 2 additions & 0 deletions src/ui/burn/fancy/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ where
Ok(())
}

#[tracing::instrument(skip_all)]
async fn get_and_handle_events(mut self) -> anyhow::Result<FancyUI<'a, B>> {
let msg = {
if let Some(handle) = &mut self.handle {
Expand All @@ -81,6 +82,7 @@ async fn child_dead(events: &mut EventStream) -> anyhow::Result<UIEvent> {
Ok(UIEvent::RecvTermEvent(events.next().await.unwrap()?))
}

#[tracing::instrument(skip_all)]
async fn child_active(events: &mut EventStream, handle: &mut Handle) -> anyhow::Result<UIEvent> {
let sleep = tokio::time::sleep(time::Duration::from_millis(250));
select! {
Expand Down
3 changes: 3 additions & 0 deletions src/ui/burn/fancy/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl State {
child: ChildState::initial(now, !params.compression.is_identity(), input_file_bytes),
}
}

#[tracing::instrument(skip_all, fields(ev))]
pub fn on_event(self, ev: UIEvent) -> anyhow::Result<Self> {
trace!("Handling {ev:?}");

Expand All @@ -47,6 +49,7 @@ impl State {
})
}

#[tracing::instrument(skip_all, fields(ev))]
fn on_term_event(self, ev: Event) -> anyhow::Result<Self> {
match ev {
Event::Key(KeyEvent {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/burn/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl BeginParams {
}
}

#[tracing::instrument(skip_all, fields(root, interactive))]
pub async fn try_start_burn(
args: &BurnConfig,
root: UseSudo,
Expand Down Expand Up @@ -97,6 +98,7 @@ pub async fn try_start_burn(
Err(dc.into())
}

#[tracing::instrument(skip_all, fields(interactive))]
pub async fn begin_writing(
interactive: Interactive,
params: BeginParams,
Expand Down
1 change: 1 addition & 0 deletions src/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use clap::Parser;
use inquire::InquireError;
use tracing::debug;

#[tracing::instrument]
#[tokio::main]
pub async fn main() {
init_logging_parent();
Expand Down

0 comments on commit 519a7c3

Please sign in to comment.