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

Add profiling scopes #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ dependencies = [
"unicode-ident",
]

[[package]]
name = "profiling"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d"
dependencies = [
"profiling-procmacros",
]

[[package]]
name = "profiling-procmacros"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30"
dependencies = [
"quote",
"syn",
]

[[package]]
name = "quote"
version = "1.0.37"
Expand All @@ -104,6 +123,7 @@ dependencies = [
"bytes",
"log",
"num-rational",
"profiling",
"serde",
"serde_json",
"thiserror",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ byteorder = "1"
bytes = "1.1.0"
log = "0.4.17"
num-rational = { version = "0.4.0", features = ["serde"] }
profiling = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "^1.0"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! * ISO/IEC 14496-14 - MP4 file format
//! * ISO/IEC 14496-17 - Streaming text format
//!
//! The top-level type you wanna look at is [`Mp4`].

mod error;
pub use error::Error;
Expand Down
1 change: 1 addition & 0 deletions src/mp4box/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl BoxHeader {
}

// TODO: if size is 0, then this box is the last one in the file
#[profiling::function]
pub fn read<R: Read>(reader: &mut R) -> Result<Self> {
// Create and read to buf.
let mut buf = [0u8; 8]; // 8 bytes for box header.
Expand Down
6 changes: 6 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ impl Mp4 {
/// Process each `trak` box to obtain a list of samples for each track.
///
/// Note that the list will be incomplete if the file is fragmented.
#[profiling::function]
fn build_tracks(&mut self) -> BTreeMap<TrackId, Track> {
let mut tracks = BTreeMap::new();

Expand Down Expand Up @@ -272,6 +273,7 @@ impl Mp4 {

/// In case the input file is fragmented, it will contain one or more `moof` boxes,
/// which must be processed to obtain the full list of samples for each track.
#[profiling::function]
fn update_sample_list(&mut self, tracks: &mut BTreeMap<TrackId, Track>) -> Result<()> {
let mut last_run_position = 0;

Expand Down Expand Up @@ -412,17 +414,21 @@ impl Mp4 {
/// This also updates sample offsets and the track duration if needed.
///
/// After this function is called, each track's [`Track::data`] may only be indexed by one of its samples' [`Sample::offset`]s.
#[profiling::function]
fn load_track_data<R: Read + Seek>(&mut self, reader: &mut R) -> Result<()> {
for track in self.tracks.values_mut() {
profiling::scope!("track");
for sample in &mut track.samples {
let data_offset = track.data.len();

// Allocating memory for each sample is what takes up most time in this function.
track
.data
.resize(track.data.len() + sample.size as usize, 0);

// at this point, `sample.offset` is the offset of the first byte of the sample in the file
reader.seek(SeekFrom::Start(sample.offset))?;

reader
.read_exact(&mut track.data[data_offset..data_offset + sample.size as usize])?;

Expand Down
Loading