Skip to content

Commit

Permalink
add flush for trace handler, will need to add for CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
ava-silver committed Dec 30, 2023
1 parent bcc1088 commit ec6d810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/trace/file.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::trace::{CpuTrace, TraceHandler};
use std::{fs::File, io::Write};
use std::{
fs::File,
io::{BufWriter, Write},
};

pub struct FileTraceHandler {
file: File,
file: BufWriter<File>,
}

impl FileTraceHandler {
pub fn new(filename: String) -> Self {
Self {
file: File::create(filename).expect("Invalid filename"),
file: BufWriter::new(File::create(filename).expect("Invalid filename")),
}
}

Check warning on line 16 in src/trace/file.rs

View check run for this annotation

Codecov / codecov/patch

src/trace/file.rs#L12-L16

Added lines #L12 - L16 were not covered by tests
}
Expand All @@ -20,4 +23,8 @@ impl TraceHandler for FileTraceHandler {
.write_all(format!("{:04X}: {:02X}\n", trace.address, trace.opcode).as_bytes())
.unwrap();
}

Check warning on line 25 in src/trace/file.rs

View check run for this annotation

Codecov / codecov/patch

src/trace/file.rs#L20-L25

Added lines #L20 - L25 were not covered by tests

fn flush(&mut self) -> Result<(), &str> {
self.file.flush().map_err(|_| "failed to flush file")
}

Check warning on line 29 in src/trace/file.rs

View check run for this annotation

Codecov / codecov/patch

src/trace/file.rs#L27-L29

Added lines #L27 - L29 were not covered by tests
}
3 changes: 3 additions & 0 deletions src/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ pub struct CpuTrace {
pub trait TraceHandler {
/// Handle a trace event.
fn handle(&mut self, trace: &CpuTrace);

/// Flush any existing resource buffers.
fn flush(&mut self) -> Result<(), &str>{ Ok(())}

Check warning on line 16 in src/trace/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/trace/mod.rs#L16

Added line #L16 was not covered by tests
}

0 comments on commit ec6d810

Please sign in to comment.