Merge pull request #47 from agersant/profile-index

Profile index
This commit is contained in:
Antoine Gersant 2019-09-02 15:19:01 -07:00 committed by GitHub
commit d348f15032
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 29 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ test/*.sqlite
tmp
TestConfigLinux.toml
TestConfigWindows.toml
index-flame-graph.html

63
.vscode/tasks.json vendored
View file

@ -1,32 +1,47 @@
{
"version": "0.1.0",
"showOutput": "always",
"tasks": [
// Run test environment
"version": "2.0.0",
"presentation": {
"reveal": "always"
},
"tasks": [
{
"taskName": "Run",
"options": { "cwd": "${workspaceRoot}" },
"label": "Run",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cargo",
"args": ["run", "--", "-c", "./TestConfigWindows.toml", "-d", "test/db.sqlite", "-w", "../polaris-web"]
"args": [
"run",
"--",
"-c",
"./TestConfigWindows.toml",
"-d",
"test/db.sqlite",
"-w",
"../polaris-web"
],
"problemMatcher": []
},
// Run unit tests
{
"isTestCommand": true,
"taskName": "Test",
"options": { "cwd": "${workspaceRoot}" },
"command": "cargo",
"args": ["test"]
},
// Compile
{
"taskName": "Compile",
"options": { "cwd": "${workspaceRoot}" },
"group": "test",
"label": "Test",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cargo",
"args": ["check"]
"args": [
"test"
]
},
{
"label": "Compile",
"options": {
"cwd": "${workspaceRoot}"
},
"command": "cargo",
"args": [
"check"
]
}
]
]
}

49
Cargo.lock generated
View file

@ -576,6 +576,28 @@ dependencies = [
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "flame"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
"thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "flamer"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "flate2"
version = "1.0.9"
@ -924,6 +946,11 @@ name = "language-tags"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.3.0"
@ -1039,7 +1066,7 @@ dependencies = [
[[package]]
name = "metaflac"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "git+https://github.com/agersant/rust-metaflac#1eb01191de4ab591611f0a16b6e36b0cf2ea592f"
dependencies = [
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1458,6 +1485,8 @@ dependencies = [
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"flamer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"id3 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1465,7 +1494,7 @@ dependencies = [
"lewton 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
"libsystemd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"metaflac 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"metaflac 0.1.8 (git+https://github.com/agersant/rust-metaflac)",
"mp3-duration 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2150,6 +2179,16 @@ dependencies = [
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread-id"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.6"
@ -2616,6 +2655,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d"
"checksum flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1fc2706461e1ee94f55cab2ed2e3d34ae9536cfa830358ef80acff1a3dacab30"
"checksum flamer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f2add1a5e84b1ed7b5d00cdc21789a28e0a8f4e427b677313c773880ba3c4dac"
"checksum flate2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "550934ad4808d5d39365e5d61727309bf18b3b02c6c56b729cb92e7dd84bc3d8"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
@ -2654,6 +2695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
"checksum lewton 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8d542c1a317036c45c2aa1cf10cc9d403ca91eb2d333ef1a4917e5cb10628bd0"
@ -2669,7 +2711,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f"
"checksum metaflac 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1839a57e30c651fb9647d1c140dcda407282a2228cddb25a21c1708645621219"
"checksum metaflac 0.1.8 (git+https://github.com/agersant/rust-metaflac)" = "<none>"
"checksum migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8089920229070f914b9ce9b07ef60e175b2b9bc2d35c3edd8bf4433604e863b9"
"checksum migrations_macros 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1664412abf7db2b8a6d58be42a38b099780cc542b5b350383b805d88932833fe"
"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
@ -2783,6 +2825,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
"checksum thread-id 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum tiff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b7c2cfc4742bd8a32f2e614339dd8ce30dbcf676bb262bd63a2327bc5df57d"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"

View file

@ -6,6 +6,7 @@ edition = "2018"
[features]
ui = []
profile-index = ["flame", "flamer"]
[dependencies]
ape = "0.2.0"
@ -14,6 +15,8 @@ base64 = "0.10.0"
diesel = { version = "1.4", features = ["sqlite"] }
diesel_migrations = { version = "1.4", features = ["sqlite"] }
error-chain = "0.12.0"
flame = { version = "0.2.2", optional = true }
flamer = { version = "0.3", optional = true }
getopts = "0.2.15"
hex = "0.3"
id3 = "0.3"
@ -21,7 +24,7 @@ image = "0.22"
rustfm-scrobble = "0.9.2"
lewton = "0.9.1"
log = "0.4.5"
metaflac = "0.1.8"
metaflac = { git = "https://github.com/agersant/rust-metaflac" }
mp3-duration = "0.1.0"
rand = "0.7"
regex = "1.2"

View file

@ -5,6 +5,7 @@ use diesel::prelude::*;
use diesel::sql_types;
use diesel::sqlite::SqliteConnection;
use error_chain::bail;
use flame;
use log::{error, info};
use regex::Regex;
use serde::{Deserialize, Serialize};
@ -169,6 +170,7 @@ struct IndexBuilder<'conn> {
}
impl<'conn> IndexBuilder<'conn> {
#[cfg_attr(feature = "profile-index", flame)]
fn new(
connection: &Mutex<SqliteConnection>,
album_art_pattern: Regex,
@ -185,6 +187,7 @@ impl<'conn> IndexBuilder<'conn> {
})
}
#[cfg_attr(feature = "profile-index", flame)]
fn flush_songs(&mut self) -> Result<(), errors::Error> {
let connection = self.connection.lock().unwrap();
let connection = connection.deref();
@ -198,6 +201,7 @@ impl<'conn> IndexBuilder<'conn> {
Ok(())
}
#[cfg_attr(feature = "profile-index", flame)]
fn flush_directories(&mut self) -> Result<(), errors::Error> {
let connection = self.connection.lock().unwrap();
let connection = connection.deref();
@ -211,6 +215,7 @@ impl<'conn> IndexBuilder<'conn> {
Ok(())
}
#[cfg_attr(feature = "profile-index", flame)]
fn push_song(&mut self, song: NewSong) -> Result<(), errors::Error> {
if self.new_songs.len() >= self.new_songs.capacity() {
self.flush_songs()?;
@ -219,6 +224,7 @@ impl<'conn> IndexBuilder<'conn> {
Ok(())
}
#[cfg_attr(feature = "profile-index", flame)]
fn push_directory(&mut self, directory: NewDirectory) -> Result<(), errors::Error> {
if self.new_directories.len() >= self.new_directories.capacity() {
self.flush_directories()?;
@ -239,6 +245,7 @@ impl<'conn> IndexBuilder<'conn> {
Ok(None)
}
#[cfg_attr(feature = "profile-index", flame)]
fn populate_directory(
&mut self,
parent: Option<&Path>,
@ -271,8 +278,9 @@ impl<'conn> IndexBuilder<'conn> {
// Insert content
for file in fs::read_dir(path)? {
let _guard = flame::start_guard("directory-entry");
let file_path = match file {
Ok(f) => f.path(),
Ok(ref f) => f.path(),
_ => {
error!("File read error within {}", path_string);
break;
@ -358,6 +366,7 @@ impl<'conn> IndexBuilder<'conn> {
}
}
#[cfg_attr(feature = "profile-index", flame)]
fn clean<T>(db: &T) -> Result<(), errors::Error>
where
T: ConnectionSource + VFSSource,
@ -417,6 +426,7 @@ where
Ok(())
}
#[cfg_attr(feature = "profile-index", flame)]
fn populate<T>(db: &T) -> Result<(), errors::Error>
where
T: ConnectionSource + VFSSource,
@ -453,6 +463,8 @@ where
"Library index update took {} seconds",
start.elapsed().as_secs()
);
#[cfg(feature = "profile-index")]
flame::dump_html(&mut fs::File::create("index-flame-graph.html").unwrap()).unwrap();
Ok(())
}
@ -512,6 +524,7 @@ where
}
}
#[cfg_attr(feature = "profile-index", flame)]
pub fn virtualize_song(vfs: &VFS, mut song: Song) -> Option<Song> {
song.path = match vfs.real_to_virtual(Path::new(&song.path)) {
Ok(p) => p.to_string_lossy().into_owned(),
@ -526,6 +539,7 @@ pub fn virtualize_song(vfs: &VFS, mut song: Song) -> Option<Song> {
Some(song)
}
#[cfg_attr(feature = "profile-index", flame)]
fn virtualize_directory(vfs: &VFS, mut directory: Directory) -> Option<Directory> {
directory.path = match vfs.real_to_virtual(Path::new(&directory.path)) {
Ok(p) => p.to_string_lossy().into_owned(),

View file

@ -6,6 +6,8 @@
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[cfg(feature = "profile-index")]
#[macro_use] extern crate flamer;
#[cfg(unix)]
use libsystemd::daemon::{self, NotifyState};

View file

@ -24,6 +24,7 @@ pub struct SongTags {
pub year: Option<i32>,
}
#[cfg_attr(feature = "profile-index", flame)]
pub fn read(path: &Path) -> Result<SongTags> {
match utils::get_audio_format(path) {
Some(AudioFormat::FLAC) => read_flac(path),
@ -34,6 +35,7 @@ pub fn read(path: &Path) -> Result<SongTags> {
}
}
#[cfg_attr(feature = "profile-index", flame)]
fn read_id3(path: &Path) -> Result<SongTags> {
let tag = id3::Tag::read_from_path(&path)?;
let duration = mp3_duration::from_path(&path)
@ -92,6 +94,7 @@ fn read_ape_x_of_y(item: &ape::Item) -> Option<u32> {
}
}
#[cfg_attr(feature = "profile-index", flame)]
fn read_ape(path: &Path) -> Result<SongTags> {
let tag = ape::read(path)?;
let artist = tag.item("Artist").and_then(read_ape_string);
@ -113,6 +116,7 @@ fn read_ape(path: &Path) -> Result<SongTags> {
})
}
#[cfg_attr(feature = "profile-index", flame)]
fn read_vorbis(path: &Path) -> Result<SongTags> {
let file = fs::File::open(path)?;
let source = OggStreamReader::new(file)?;
@ -144,6 +148,7 @@ fn read_vorbis(path: &Path) -> Result<SongTags> {
Ok(tags)
}
#[cfg_attr(feature = "profile-index", flame)]
fn read_flac(path: &Path) -> Result<SongTags> {
let tag = metaflac::Tag::read_from_path(path)?;
let vorbis = tag.vorbis_comments().ok_or("Missing Vorbis comments")?;

View file

@ -34,6 +34,7 @@ pub enum AudioFormat {
OGG,
}
#[cfg_attr(feature = "profile-index", flame)]
pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
let extension = match path.extension() {
Some(e) => e,