Added more profiling markers
This commit is contained in:
parent
f71a8320e9
commit
2b30307488
2 changed files with 54 additions and 24 deletions
|
@ -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());
|
||||||
|
|
|
@ -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,25 +203,31 @@ impl IndexUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert directory
|
// Insert directory
|
||||||
if inconsistent_directory_year {
|
let directory = {
|
||||||
directory_year = None;
|
#[cfg(feature = "profile-index")]
|
||||||
}
|
let _guard = flame::start_guard("create_directory");
|
||||||
if inconsistent_directory_album {
|
|
||||||
directory_album = None;
|
|
||||||
}
|
|
||||||
if inconsistent_directory_artist {
|
|
||||||
directory_artist = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let directory = NewDirectory {
|
if inconsistent_directory_year {
|
||||||
path: path_string.to_owned(),
|
directory_year = None;
|
||||||
parent: parent_string,
|
}
|
||||||
artwork,
|
if inconsistent_directory_album {
|
||||||
album: directory_album,
|
directory_album = None;
|
||||||
artist: directory_artist,
|
}
|
||||||
year: directory_year,
|
if inconsistent_directory_artist {
|
||||||
date_added: created,
|
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)?;
|
self.push_directory(directory)?;
|
||||||
|
|
||||||
// Populate subdirectories
|
// Populate subdirectories
|
||||||
|
|
Loading…
Add table
Reference in a new issue