From 2b30307488e08c98970906286c9d0acf3c2506cc Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sun, 19 Jan 2020 00:44:24 -0800 Subject: [PATCH] Added more profiling markers --- src/index/metadata.rs | 14 ++++++++-- src/index/update.rs | 64 +++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/index/metadata.rs b/src/index/metadata.rs index b31794b..3642c67 100644 --- a/src/index/metadata.rs +++ b/src/index/metadata.rs @@ -45,10 +45,18 @@ pub fn read(path: &Path) -> Option { #[cfg_attr(feature = "profile-index", flame)] fn read_id3(path: &Path) -> Result { - let tag = id3::Tag::read_from_path(&path)?; - let duration = mp3_duration::from_path(&path) + let tag = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("id3_tag_read"); + id3::Tag::read_from_path(&path)? + }; + let duration = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("mp3_duration"); + mp3_duration::from_path(&path) .map(|d| d.as_secs() as u32) - .ok(); + .ok() + }; let artist = tag.artist().map(|s| s.to_string()); let album_artist = tag.album_artist().map(|s| s.to_string()); diff --git a/src/index/update.rs b/src/index/update.rs index 0baeea5..d9aa7cc 100644 --- a/src/index/update.rs +++ b/src/index/update.rs @@ -102,19 +102,31 @@ impl IndexUpdater { #[cfg_attr(feature = "profile-index", flame)] fn populate_directory(&mut self, parent: Option<&Path>, path: &Path) -> Result<()> { // Find artwork - let artwork = self.get_artwork(path).unwrap_or(None); + let artwork = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("artwork"); + self.get_artwork(path).unwrap_or(None) + }; // Extract path and parent path let parent_string = parent.and_then(|p| p.to_str()).map(|s| s.to_owned()); let path_string = path.to_str().ok_or(anyhow!("Invalid directory path"))?; // Find date added - let metadata = fs::metadata(path_string)?; - let created = metadata + let metadata = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("metadata"); + fs::metadata(path_string)? + }; + let created = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("created_date"); + metadata .created() .or_else(|_| metadata.modified())? .duration_since(time::UNIX_EPOCH)? - .as_secs() as i32; + .as_secs() as i32 + }; let mut directory_album = None; let mut directory_year = None; @@ -145,6 +157,10 @@ impl IndexUpdater { if let Some(file_path_string) = file_path.to_str() { if let Some(tags) = metadata::read(file_path.as_path()) { + + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("process_song"); + if tags.year.is_some() { inconsistent_directory_year |= directory_year.is_some() && directory_year != tags.year; @@ -187,25 +203,31 @@ impl IndexUpdater { } // Insert directory - if inconsistent_directory_year { - directory_year = None; - } - if inconsistent_directory_album { - directory_album = None; - } - if inconsistent_directory_artist { - directory_artist = None; - } + let directory = { + #[cfg(feature = "profile-index")] + let _guard = flame::start_guard("create_directory"); - let directory = NewDirectory { - path: path_string.to_owned(), - parent: parent_string, - artwork, - album: directory_album, - artist: directory_artist, - year: directory_year, - date_added: created, + if inconsistent_directory_year { + directory_year = None; + } + if inconsistent_directory_album { + directory_album = None; + } + if inconsistent_directory_artist { + directory_artist = None; + } + + NewDirectory { + path: path_string.to_owned(), + parent: parent_string, + artwork, + album: directory_album, + artist: directory_artist, + year: directory_year, + date_added: created, + } }; + self.push_directory(directory)?; // Populate subdirectories