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

Read/write records #1117

Merged
merged 16 commits into from
Apr 28, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix
raviqqe committed Apr 28, 2024
commit 87f351d94fcb73c21337d64c7c37d34fb1ff607d
1 change: 1 addition & 0 deletions profiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ pub use collapse::collapse_stacks;
pub use duration::calculate_durations;
pub use error::Error;
pub use flamegraph::calculate_flamegraph;
pub use read::read_records;
pub use record::{
DurationRecord, ProcedureOperation, ProcedureRecord, Record, Stack, StackedRecord,
};
28 changes: 24 additions & 4 deletions profiler/src/read.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use crate::Record;
use core::str::FromStr;
use std::io::BufRead;
use std::io::{self, BufRead};

pub fn read_records<R: Record>(
reader: impl BufRead,
) -> impl Iterator<Item = Result<R, <R as FromStr>::Err>> {
) -> impl Iterator<Item = Result<R, <R as FromStr>::Err>>
where
<R as FromStr>::Err: From<io::Error>,
{
reader.lines().map(|line| line?.parse())
}

#[cfg(test)]
mod tests {
use super::*;
use crate::ProcedureRecord;
use crate::{ProcedureOperation, ProcedureRecord};
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::BufReader;

#[test]
@@ -29,7 +33,23 @@ mod tests {
.as_bytes()
))
.collect::<Vec<_>>(),
vec![]
vec![
ProcedureRecord::new(
ProcedureOperation::Call,
Stack::new(vec![Some("baz".into())]),
0
),
ProcedureRecord::new(
ProcedureOperation::Return,
Stack::new(vec![Some("baz".into())]),
42
),
ProcedureRecord::new(
ProcedureOperation::ReturnCall,
Stack::new(vec![None; 3]),
2045
)
]
);
}
}