Added more profiling markers

This commit is contained in:
Antoine Gersant 2020-01-19 00:44:24 -08:00
parent f71a8320e9
commit 2b30307488
2 changed files with 54 additions and 24 deletions

View file

@ -45,10 +45,18 @@ pub fn read(path: &Path) -> Option<SongTags> {
#[cfg_attr(feature = "profile-index", flame)] #[cfg_attr(feature = "profile-index", flame)]
fn read_id3(path: &Path) -> Result<SongTags> { fn read_id3(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_path(&path)?; let tag = {
let duration = mp3_duration::from_path(&path) #[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) .map(|d| d.as_secs() as u32)
.ok(); .ok()
};
let artist = tag.artist().map(|s| s.to_string()); let artist = tag.artist().map(|s| s.to_string());
let album_artist = tag.album_artist().map(|s| s.to_string()); let album_artist = tag.album_artist().map(|s| s.to_string());

View file

@ -102,19 +102,31 @@ impl IndexUpdater {
#[cfg_attr(feature = "profile-index", flame)] #[cfg_attr(feature = "profile-index", flame)]
fn populate_directory(&mut self, parent: Option<&Path>, path: &Path) -> Result<()> { fn populate_directory(&mut self, parent: Option<&Path>, path: &Path) -> Result<()> {
// Find artwork // 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 // Extract path and parent path
let parent_string = parent.and_then(|p| p.to_str()).map(|s| s.to_owned()); 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"))?; let path_string = path.to_str().ok_or(anyhow!("Invalid directory path"))?;
// Find date added // Find date added
let metadata = fs::metadata(path_string)?; let metadata = {
let created = 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() .created()
.or_else(|_| metadata.modified())? .or_else(|_| metadata.modified())?
.duration_since(time::UNIX_EPOCH)? .duration_since(time::UNIX_EPOCH)?
.as_secs() as i32; .as_secs() as i32
};
let mut directory_album = None; let mut directory_album = None;
let mut directory_year = 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(file_path_string) = file_path.to_str() {
if let Some(tags) = metadata::read(file_path.as_path()) { 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() { if tags.year.is_some() {
inconsistent_directory_year |= inconsistent_directory_year |=
directory_year.is_some() && directory_year != tags.year; directory_year.is_some() && directory_year != tags.year;
@ -187,6 +203,10 @@ impl IndexUpdater {
} }
// Insert directory // Insert directory
let directory = {
#[cfg(feature = "profile-index")]
let _guard = flame::start_guard("create_directory");
if inconsistent_directory_year { if inconsistent_directory_year {
directory_year = None; directory_year = None;
} }
@ -197,7 +217,7 @@ impl IndexUpdater {
directory_artist = None; directory_artist = None;
} }
let directory = NewDirectory { NewDirectory {
path: path_string.to_owned(), path: path_string.to_owned(),
parent: parent_string, parent: parent_string,
artwork, artwork,
@ -205,7 +225,9 @@ impl IndexUpdater {
artist: directory_artist, artist: directory_artist,
year: directory_year, year: directory_year,
date_added: created, date_added: created,
}
}; };
self.push_directory(directory)?; self.push_directory(directory)?;
// Populate subdirectories // Populate subdirectories