From a99d3235a85f444de6afe1b156d8b9730b3c28c8 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 23 Oct 2021 15:02:07 +0200 Subject: [PATCH] Add tracing and optional firechart analysis Signed-off-by: trivernis --- mediarepo-daemon/.gitignore | 2 + mediarepo-daemon/Cargo.lock | 254 ++++++++++++++++-- mediarepo-daemon/Cargo.toml | 2 + mediarepo-daemon/mediarepo-core/Cargo.lock | 38 ++- mediarepo-daemon/mediarepo-core/Cargo.toml | 2 +- .../mediarepo-core/src/image_processing.rs | 2 +- .../mediarepo-database/Cargo.lock | 38 ++- mediarepo-daemon/mediarepo-model/Cargo.lock | 39 ++- mediarepo-daemon/mediarepo-model/Cargo.toml | 1 + mediarepo-daemon/mediarepo-model/src/file.rs | 24 +- mediarepo-daemon/mediarepo-model/src/hash.rs | 9 +- .../mediarepo-model/src/namespace.rs | 9 +- mediarepo-daemon/mediarepo-model/src/repo.rs | 45 +++- .../mediarepo-model/src/storage.rs | 23 +- mediarepo-daemon/mediarepo-model/src/tag.rs | 11 +- .../mediarepo-model/src/thumbnail.rs | 10 +- mediarepo-daemon/mediarepo-socket/Cargo.lock | 151 +++++++++-- mediarepo-daemon/mediarepo-socket/Cargo.toml | 4 + mediarepo-daemon/mediarepo-socket/src/lib.rs | 1 + .../mediarepo-socket/src/namespaces/files.rs | 6 + .../mediarepo-socket/src/namespaces/tags.rs | 2 + mediarepo-daemon/src/main.rs | 33 ++- 22 files changed, 615 insertions(+), 91 deletions(-) diff --git a/mediarepo-daemon/.gitignore b/mediarepo-daemon/.gitignore index 167268c..5511304 100644 --- a/mediarepo-daemon/.gitignore +++ b/mediarepo-daemon/.gitignore @@ -2,3 +2,5 @@ test-local .idea .env +tracing.folded +tracing*.svg \ No newline at end of file diff --git a/mediarepo-daemon/Cargo.lock b/mediarepo-daemon/Cargo.lock index feaf9b8..6eea433 100644 --- a/mediarepo-daemon/Cargo.lock +++ b/mediarepo-daemon/Cargo.lock @@ -43,6 +43,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "arrayref" version = "0.3.6" @@ -181,7 +190,7 @@ dependencies = [ "arrayref", "arrayvec 0.7.1", "cc", - "cfg-if", + "cfg-if 1.0.0", "constant_time_eq", ] @@ -231,6 +240,12 @@ version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -257,7 +272,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim", @@ -330,7 +345,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -339,8 +354,8 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", ] [[package]] @@ -349,9 +364,9 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils", + "crossbeam-utils 0.8.5", ] [[package]] @@ -360,8 +375,8 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", "lazy_static", "memoffset", "scopeguard", @@ -373,8 +388,19 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", + "lazy_static", ] [[package]] @@ -383,7 +409,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "lazy_static", ] @@ -482,6 +508,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" + [[package]] name = "futures" version = "0.3.17" @@ -603,7 +635,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -721,7 +753,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -801,7 +833,16 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", +] + +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", ] [[package]] @@ -823,6 +864,8 @@ dependencies = [ "structopt", "tokio", "toml", + "tracing-flame", + "tracing-subscriber", ] [[package]] @@ -830,7 +873,7 @@ name = "mediarepo-core" version = "0.1.0" dependencies = [ "base64", - "futures", + "futures 0.3.17", "image", "multibase", "multihash", @@ -866,6 +909,7 @@ dependencies = [ "sea-orm", "serde", "tokio", + "tracing", "typemap_rev", ] @@ -878,6 +922,8 @@ dependencies = [ "mediarepo-model", "serde", "tokio", + "tracing", + "tracing-futures", ] [[package]] @@ -1119,7 +1165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -1162,7 +1208,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", @@ -1176,6 +1222,26 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pin-project" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -1378,7 +1444,7 @@ checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" dependencies = [ "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils", + "crossbeam-utils 0.8.5", "lazy_static", "num_cpus", ] @@ -1403,6 +1469,15 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.25" @@ -1430,16 +1505,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -1502,7 +1577,7 @@ dependencies = [ "async-stream", "async-trait", "chrono", - "futures", + "futures 0.3.17", "futures-util", "rust_decimal", "sea-orm-macros", @@ -1637,7 +1712,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", "opaque-debug", @@ -1655,6 +1730,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.4" @@ -1703,7 +1787,7 @@ dependencies = [ "crc", "crossbeam-channel", "crossbeam-queue", - "crossbeam-utils", + "crossbeam-utils 0.8.5", "either", "futures-channel", "futures-core", @@ -1848,7 +1932,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "rand", "redox_syscall", @@ -1894,6 +1978,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + [[package]] name = "tiff" version = "0.6.1" @@ -1948,6 +2041,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "tokio-executor" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" +dependencies = [ + "crossbeam-utils 0.7.2", + "futures 0.1.31", +] + [[package]] name = "tokio-macros" version = "1.4.1" @@ -1989,6 +2092,103 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-flame" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd520fe41c667b437952383f3a1ec14f1fa45d653f719a77eedd6e6a02d8fa54" +dependencies = [ + "lazy_static", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tokio-executor", + "tracing", +] + +[[package]] +name = "tracing-log" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "ansi_term 0.12.1", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + [[package]] name = "typemap_rev" version = "0.1.5" @@ -2107,7 +2307,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] diff --git a/mediarepo-daemon/Cargo.toml b/mediarepo-daemon/Cargo.toml index e1b915c..0525002 100644 --- a/mediarepo-daemon/Cargo.toml +++ b/mediarepo-daemon/Cargo.toml @@ -20,6 +20,8 @@ structopt = {version="0.3.23", optional=true} pretty_env_logger = {version="0.4.0", optional=true} glob = {version="0.3.0", optional=true} log = "0.4.14" +tracing-flame = "0.1.0" +tracing-subscriber = "0.2.3" [dependencies.mediarepo-core] path = "./mediarepo-core" diff --git a/mediarepo-daemon/mediarepo-core/Cargo.lock b/mediarepo-daemon/mediarepo-core/Cargo.lock index aabf245..91e1845 100644 --- a/mediarepo-daemon/mediarepo-core/Cargo.lock +++ b/mediarepo-daemon/mediarepo-core/Cargo.lock @@ -1034,16 +1034,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -1374,6 +1374,38 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + [[package]] name = "typemap_rev" version = "0.1.5" diff --git a/mediarepo-daemon/mediarepo-core/Cargo.toml b/mediarepo-daemon/mediarepo-core/Cargo.toml index e7f41a5..d069dad 100644 --- a/mediarepo-daemon/mediarepo-core/Cargo.toml +++ b/mediarepo-daemon/mediarepo-core/Cargo.toml @@ -12,7 +12,7 @@ multibase = "0.9.1" base64 = "0.13.0" toml = "0.5.8" serde = "1.0.130" -rmp-ipc = "0.7.0" +rmp-ipc = "0.7.2" typemap_rev = "0.1.5" image = "0.23.14" futures = "0.3.17" diff --git a/mediarepo-daemon/mediarepo-core/src/image_processing.rs b/mediarepo-daemon/mediarepo-core/src/image_processing.rs index 5d7222d..e17e148 100644 --- a/mediarepo-daemon/mediarepo-core/src/image_processing.rs +++ b/mediarepo-daemon/mediarepo-core/src/image_processing.rs @@ -8,7 +8,7 @@ use tokio::fs::OpenOptions; use tokio::io::{AsyncRead, AsyncReadExt, BufReader}; /// Represents the different sizes of a thumbnail -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] pub enum ThumbnailSize { Small, Medium, diff --git a/mediarepo-daemon/mediarepo-database/Cargo.lock b/mediarepo-daemon/mediarepo-database/Cargo.lock index 9c15ef6..3c71dac 100644 --- a/mediarepo-daemon/mediarepo-database/Cargo.lock +++ b/mediarepo-daemon/mediarepo-database/Cargo.lock @@ -1267,16 +1267,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -1765,6 +1765,38 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + [[package]] name = "typemap_rev" version = "0.1.5" diff --git a/mediarepo-daemon/mediarepo-model/Cargo.lock b/mediarepo-daemon/mediarepo-model/Cargo.lock index 8355c3e..95bcf21 100644 --- a/mediarepo-daemon/mediarepo-model/Cargo.lock +++ b/mediarepo-daemon/mediarepo-model/Cargo.lock @@ -778,6 +778,7 @@ dependencies = [ "sea-orm", "serde", "tokio", + "tracing", "typemap_rev", ] @@ -1298,16 +1299,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -1797,6 +1798,38 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + [[package]] name = "typemap_rev" version = "0.1.5" diff --git a/mediarepo-daemon/mediarepo-model/Cargo.toml b/mediarepo-daemon/mediarepo-model/Cargo.toml index 32f17e2..5fd98be 100644 --- a/mediarepo-daemon/mediarepo-model/Cargo.toml +++ b/mediarepo-daemon/mediarepo-model/Cargo.toml @@ -11,6 +11,7 @@ typemap_rev = "0.1.5" serde = "1.0.130" mime_guess = "2.0.3" mime = "0.3.16" +tracing = "0.1.29" [dependencies.mediarepo-core] path = "../mediarepo-core" diff --git a/mediarepo-daemon/mediarepo-model/src/file.rs b/mediarepo-daemon/mediarepo-model/src/file.rs index 739f5a7..abed53b 100644 --- a/mediarepo-daemon/mediarepo-model/src/file.rs +++ b/mediarepo-daemon/mediarepo-model/src/file.rs @@ -18,6 +18,7 @@ use sea_orm::prelude::*; use sea_orm::sea_query::{Expr, Query}; use sea_orm::{Condition, DatabaseConnection, Set}; use sea_orm::{JoinType, QuerySelect}; +use std::fmt::Debug; use tokio::io::BufReader; #[derive(Clone)] @@ -28,11 +29,13 @@ pub struct File { } impl File { + #[tracing::instrument(level = "trace")] pub(crate) fn new(db: DatabaseConnection, model: file::Model, hash: hash::Model) -> Self { Self { db, model, hash } } /// Returns a list of all known stored files + #[tracing::instrument(level = "debug", skip(db))] pub async fn all(db: DatabaseConnection) -> RepoResult> { let files: Vec<(file::Model, Option)> = file::Entity::find() .find_also_related(hash::Entity) @@ -50,6 +53,7 @@ impl File { } /// Fetches the file by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { if let Some((model, Some(hash))) = file::Entity::find_by_id(id) .find_also_related(hash::Entity) @@ -64,7 +68,8 @@ impl File { } /// Finds the file by hash - pub async fn by_hash>( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_hash + Debug>( db: DatabaseConnection, hash: S, ) -> RepoResult> { @@ -81,6 +86,8 @@ impl File { } } + /// Finds the file by tags + #[tracing::instrument(level = "debug", skip(db))] pub(crate) async fn find_by_tags( db: DatabaseConnection, tag_ids: Vec, @@ -113,6 +120,7 @@ impl File { } /// Adds a file with its hash to the database + #[tracing::instrument(level = "debug", skip(db))] pub(crate) async fn add( db: DatabaseConnection, storage_id: i64, @@ -199,11 +207,13 @@ impl File { } /// Returns a list of thumbnails for the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn thumbnails(&self) -> RepoResult> { Thumbnail::for_file_id(self.db.clone(), self.model.id).await } /// Returns the list of tags of the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn tags(&self) -> RepoResult> { let tags: Vec<(tag::Model, Option)> = tag::Entity::find() .find_also_related(namespace::Entity) @@ -221,7 +231,8 @@ impl File { } /// Changes the name of the file - pub async fn set_name(&mut self, name: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_name(&mut self, name: S) -> RepoResult<()> { let mut active_file = self.get_active_model(); active_file.name = Set(Some(name.to_string())); let active_file = active_file.update(&self.db).await?; @@ -231,7 +242,8 @@ impl File { } /// Changes the comment of the file - pub async fn set_comment(&mut self, comment: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_comment(&mut self, comment: S) -> RepoResult<()> { let mut active_file = self.get_active_model(); active_file.comment = Set(Some(comment.to_string())); let active_file = active_file.update(&self.db).await?; @@ -241,6 +253,7 @@ impl File { } /// Changes the type of the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn set_file_type(&mut self, file_type: FileType) -> RepoResult<()> { let mut active_file = self.get_active_model(); active_file.file_type = Set(file_type as u32); @@ -251,6 +264,7 @@ impl File { } /// Adds a single tag to the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_tag(&mut self, tag_id: i64) -> RepoResult<()> { let hash_id = self.hash.id; let active_model = hash_tag::ActiveModel { @@ -262,6 +276,7 @@ impl File { } /// Adds multiple tags to the file at once + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_tags(&self, tag_ids: Vec) -> RepoResult<()> { let hash_id = self.hash.id; let models: Vec = tag_ids @@ -277,6 +292,7 @@ impl File { } /// Returns the reader for the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn get_reader(&self) -> RepoResult> { let storage = self.storage().await?; @@ -284,6 +300,7 @@ impl File { } /// Creates a thumbnail for the file + #[tracing::instrument(level = "debug", skip(self))] pub async fn create_thumbnail( &self, size: ThumbnailSize, @@ -297,6 +314,7 @@ impl File { } /// Creates a thumbnail for an image + #[tracing::instrument(level = "debug", skip(self))] async fn create_image_thumbnail( &self, size: ThumbnailSize, diff --git a/mediarepo-daemon/mediarepo-model/src/hash.rs b/mediarepo-daemon/mediarepo-model/src/hash.rs index a33e59d..79ce5d8 100644 --- a/mediarepo-daemon/mediarepo-model/src/hash.rs +++ b/mediarepo-daemon/mediarepo-model/src/hash.rs @@ -6,6 +6,7 @@ use mediarepo_database::entities::hash; use mediarepo_database::entities::thumbnail; use sea_orm::prelude::*; use sea_orm::{DatabaseConnection, Set}; +use std::fmt::Debug; pub struct Hash { db: DatabaseConnection, @@ -13,11 +14,13 @@ pub struct Hash { } impl Hash { + #[tracing::instrument(level = "trace")] pub(crate) fn new(db: DatabaseConnection, model: hash::Model) -> Self { Self { db, model } } /// Searches for the hash by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { let hash = hash::Entity::find_by_id(id) .one(&db) @@ -28,7 +31,8 @@ impl Hash { } /// Returns the hash by value - pub async fn by_value>( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_value + Debug>( db: DatabaseConnection, value: S, ) -> RepoResult> { @@ -42,6 +46,7 @@ impl Hash { } /// Adds a new hash to the database + #[tracing::instrument(level = "debug", skip(db))] pub async fn add(db: DatabaseConnection, value: String) -> RepoResult { let active_model = hash::ActiveModel { value: Set(value), @@ -64,6 +69,7 @@ impl Hash { } /// Returns the file associated with the hash + #[tracing::instrument(level = "debug", skip(self))] pub async fn file(&self) -> RepoResult> { let file = self .model @@ -76,6 +82,7 @@ impl Hash { } /// Returns the the thumbnail associated with the hash + #[tracing::instrument(level = "debug", skip(self))] pub async fn thumbnail(&self) -> RepoResult> { let thumbnail = self .model diff --git a/mediarepo-daemon/mediarepo-model/src/namespace.rs b/mediarepo-daemon/mediarepo-model/src/namespace.rs index 041e4be..087b817 100644 --- a/mediarepo-daemon/mediarepo-model/src/namespace.rs +++ b/mediarepo-daemon/mediarepo-model/src/namespace.rs @@ -2,6 +2,7 @@ use mediarepo_core::error::RepoResult; use mediarepo_database::entities::namespace; use sea_orm::prelude::*; use sea_orm::{DatabaseConnection, Set}; +use std::fmt::Debug; #[derive(Clone)] pub struct Namespace { @@ -10,11 +11,13 @@ pub struct Namespace { } impl Namespace { + #[tracing::instrument(level = "trace")] pub(crate) fn new(db: DatabaseConnection, model: namespace::Model) -> Self { Self { db, model } } /// Retrieves the namespace by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { let namespace = namespace::Entity::find_by_id(id) .one(&db) @@ -25,7 +28,8 @@ impl Namespace { } /// Retrieves a namespace by its name - pub async fn by_name>( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_name + Debug>( db: DatabaseConnection, name: S, ) -> RepoResult> { @@ -39,7 +43,8 @@ impl Namespace { } /// Adds a namespace to the database - pub async fn add(db: DatabaseConnection, name: S) -> RepoResult { + #[tracing::instrument(level = "debug", skip(db))] + pub async fn add(db: DatabaseConnection, name: S) -> RepoResult { let active_model = namespace::ActiveModel { name: Set(name.to_string()), ..Default::default() diff --git a/mediarepo-daemon/mediarepo-model/src/repo.rs b/mediarepo-daemon/mediarepo-model/src/repo.rs index 67ff58d..782b6a9 100644 --- a/mediarepo-daemon/mediarepo-model/src/repo.rs +++ b/mediarepo-daemon/mediarepo-model/src/repo.rs @@ -9,6 +9,7 @@ use mediarepo_core::image_processing::ThumbnailSize; use mediarepo_core::utils::parse_namespace_and_tag; use mediarepo_database::get_database; use sea_orm::DatabaseConnection; +use std::fmt::Debug; use std::io::Cursor; use std::path::PathBuf; use tokio::fs::OpenOptions; @@ -31,35 +32,44 @@ impl Repo { } /// Connects to the database with the given uri - pub async fn connect>(uri: S) -> RepoResult { + #[tracing::instrument(level = "debug")] + pub async fn connect + Debug>(uri: S) -> RepoResult { let db = get_database(uri).await?; Ok(Self::new(db)) } /// Returns all available storages + #[tracing::instrument(level = "debug", skip(self))] pub async fn storages(&self) -> RepoResult> { Storage::all(self.db.clone()).await } /// Returns a storage by path - pub async fn storage_by_path(&self, path: S) -> RepoResult> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn storage_by_path( + &self, + path: S, + ) -> RepoResult> { Storage::by_path(self.db.clone(), path).await } /// Sets the main storage - pub async fn set_main_storage(&mut self, path: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_main_storage(&mut self, path: S) -> RepoResult<()> { self.main_storage = Storage::by_path(self.db.clone(), path).await?; Ok(()) } /// Sets the default thumbnail storage - pub async fn set_thumbnail_storage(&mut self, path: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_thumbnail_storage(&mut self, path: S) -> RepoResult<()> { self.thumbnail_storage = Storage::by_path(self.db.clone(), path).await?; Ok(()) } /// Adds a storage to the repository - pub async fn add_storage( + #[tracing::instrument(level = "debug", skip(self))] + pub async fn add_storage( &self, name: S1, path: S2, @@ -68,21 +78,25 @@ impl Repo { } /// Returns a file by its mapped hash - pub async fn file_by_hash>(&self, hash: S) -> RepoResult> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn file_by_hash + Debug>(&self, hash: S) -> RepoResult> { File::by_hash(self.db.clone(), hash).await } /// Returns a file by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn file_by_id(&self, id: i64) -> RepoResult> { File::by_id(self.db.clone(), id).await } /// Returns a list of all stored files + #[tracing::instrument(level = "debug", skip(self))] pub async fn files(&self) -> RepoResult> { File::all(self.db.clone()).await } /// Finds all files by a list of tags + #[tracing::instrument(level = "debug", skip(self))] pub async fn find_files_by_tags(&self, tags: Vec) -> RepoResult> { let tags = self.find_all_tags(tags).await?; let tag_ids = tags.into_iter().map(|tag| tag.id()).collect(); @@ -91,6 +105,7 @@ impl Repo { } /// Adds a file to the database by its readable path in the file system + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_file_by_path(&self, path: PathBuf) -> RepoResult { let mime_match = mime_guess::from_path(&path).first(); @@ -115,11 +130,16 @@ impl Repo { } /// Returns a thumbnail by its hash - pub async fn thumbnail_by_hash>(&self, hash: S) -> RepoResult> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn thumbnail_by_hash + Debug>( + &self, + hash: S, + ) -> RepoResult> { Thumbnail::by_hash(self.db.clone(), hash).await } /// Creates thumbnails of all sizes for a file + #[tracing::instrument(level = "debug", skip(self, file))] pub async fn create_thumbnails_for_file(&self, file: File) -> RepoResult<()> { let thumb_storage = self.get_thumbnail_storage()?; for size in [ @@ -145,11 +165,13 @@ impl Repo { } /// Returns all tags stored in the database + #[tracing::instrument(level = "debug", skip(self))] pub async fn tags(&self) -> RepoResult> { Tag::all(self.db.clone()).await } /// Finds all tags by name + #[tracing::instrument(level = "debug", skip(self))] pub async fn find_all_tags(&self, tags: Vec) -> RepoResult> { let tags: Vec<(Option, String)> = tags.into_iter().map(parse_namespace_and_tag).collect(); @@ -157,7 +179,8 @@ impl Repo { } /// Adds or finds a tag - pub async fn add_or_find_tag(&self, tag: S) -> RepoResult { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn add_or_find_tag(&self, tag: S) -> RepoResult { let (namespace, name) = parse_namespace_and_tag(tag.to_string()); if let Some(namespace) = namespace { self.add_or_find_namespaced_tag(name, namespace).await @@ -167,6 +190,7 @@ impl Repo { } /// Adds or finds an unnamespaced tag + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_or_find_unnamespaced_tag(&self, name: String) -> RepoResult { if let Some(tag) = Tag::by_name(self.db.clone(), &name, None).await? { Ok(tag) @@ -176,11 +200,13 @@ impl Repo { } /// Adds an unnamespaced tag + #[tracing::instrument(level = "debug", skip(self))] async fn add_unnamespaced_tag(&self, name: String) -> RepoResult { Tag::add(self.db.clone(), name, None).await } /// Adds or finds a namespaced tag + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_or_find_namespaced_tag( &self, name: String, @@ -194,6 +220,7 @@ impl Repo { } /// Adds a namespaced tag + #[tracing::instrument(level = "debug", skip(self))] async fn add_namespaced_tag(&self, name: String, namespace: String) -> RepoResult { let namespace = if let Some(namespace) = Namespace::by_name(self.db.clone(), &namespace).await? { @@ -204,6 +231,7 @@ impl Repo { Tag::add(self.db.clone(), name, Some(namespace.id())).await } + #[tracing::instrument(level = "trace", skip(self))] fn get_main_storage(&self) -> RepoResult<&Storage> { if let Some(storage) = &self.main_storage { Ok(storage) @@ -212,6 +240,7 @@ impl Repo { } } + #[tracing::instrument(level = "trace", skip(self))] fn get_thumbnail_storage(&self) -> RepoResult<&Storage> { if let Some(storage) = &self.thumbnail_storage { Ok(storage) diff --git a/mediarepo-daemon/mediarepo-model/src/storage.rs b/mediarepo-daemon/mediarepo-model/src/storage.rs index 4afc89a..7c7594b 100644 --- a/mediarepo-daemon/mediarepo-model/src/storage.rs +++ b/mediarepo-daemon/mediarepo-model/src/storage.rs @@ -6,6 +6,7 @@ use mediarepo_database::entities::storage::ActiveModel as ActiveStorage; use mediarepo_database::entities::storage::Model as StorageModel; use sea_orm::prelude::*; use sea_orm::{DatabaseConnection, Set, Unset}; +use std::fmt::Debug; use std::path::PathBuf; use tokio::fs; use tokio::io::{AsyncRead, BufReader}; @@ -18,6 +19,7 @@ pub struct Storage { } impl Storage { + #[tracing::instrument(level = "trace")] fn new(db: DatabaseConnection, model: StorageModel) -> Self { let path = PathBuf::from(&model.path); Self { @@ -28,6 +30,7 @@ impl Storage { } /// Returns all available storages + #[tracing::instrument(level = "debug", skip(db))] pub async fn all(db: DatabaseConnection) -> RepoResult> { let storages: Vec = storage::Entity::find().all(&db).await?; let storages = storages @@ -39,6 +42,7 @@ impl Storage { } /// Returns the storage by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { if let Some(model) = storage::Entity::find_by_id(id).one(&db).await? { let storage = Self::new(db, model); @@ -49,7 +53,11 @@ impl Storage { } /// Returns the storage by path - pub async fn by_path(db: DatabaseConnection, path: S) -> RepoResult> { + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_path( + db: DatabaseConnection, + path: S, + ) -> RepoResult> { if let Some(model) = storage::Entity::find() .filter(storage::Column::Path.eq(path.to_string())) .one(&db) @@ -64,7 +72,8 @@ impl Storage { /// Creates a new active storage and also creates the associated directory /// if it doesn't exist yet. - pub async fn create( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn create( db: DatabaseConnection, name: S1, path: S2, @@ -106,7 +115,8 @@ impl Storage { } /// Sets a new name for the storage - pub async fn set_name(&self, name: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_name(&self, name: S) -> RepoResult<()> { let mut active_storage: ActiveStorage = self.get_active_model(); active_storage.name = Set(name.to_string()); active_storage.update(&self.db).await?; @@ -116,7 +126,8 @@ impl Storage { /// Sets a new path for the storage. This will only update the database record /// so if the physical part of the storage is already created it needs to be migrated first - pub async fn set_path(&mut self, path: S) -> RepoResult<()> { + #[tracing::instrument(level = "debug", skip(self))] + pub async fn set_path(&mut self, path: S) -> RepoResult<()> { let mut active_storage: ActiveStorage = self.get_active_model(); active_storage.path = Set(path.to_string()); let storage: ActiveStorage = active_storage.update(&self.db).await?; @@ -133,6 +144,7 @@ impl Storage { } /// Adds a thumbnail + #[tracing::instrument(level = "debug", skip(self, reader))] pub async fn store_entry(&self, reader: R) -> RepoResult { let hash = self.store.add_file(reader, None).await?; if let Some(hash) = Hash::by_value(self.db.clone(), &hash).await? { @@ -143,7 +155,8 @@ impl Storage { } /// Returns the buf reader to the given hash - pub async fn get_file_reader( + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_file_reader( &self, hash: S, ) -> RepoResult> { diff --git a/mediarepo-daemon/mediarepo-model/src/tag.rs b/mediarepo-daemon/mediarepo-model/src/tag.rs index d5fd3c5..634a577 100644 --- a/mediarepo-daemon/mediarepo-model/src/tag.rs +++ b/mediarepo-daemon/mediarepo-model/src/tag.rs @@ -5,6 +5,7 @@ use mediarepo_database::entities::tag; use sea_orm::prelude::*; use sea_orm::sea_query::Expr; use sea_orm::{Condition, DatabaseConnection, Set}; +use std::fmt::Debug; #[derive(Clone)] pub struct Tag { @@ -14,6 +15,7 @@ pub struct Tag { } impl Tag { + #[tracing::instrument(level = "trace")] pub(crate) fn new( db: DatabaseConnection, model: tag::Model, @@ -27,6 +29,7 @@ impl Tag { } /// Returns all tags stored in the database + #[tracing::instrument(level = "debug", skip(db))] pub async fn all(db: DatabaseConnection) -> RepoResult> { let tags: Vec = tag::Entity::find() .inner_join(namespace::Entity) @@ -41,6 +44,7 @@ impl Tag { } /// Returns the tag by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { let tag = tag::Entity::find_by_id(id) .find_also_related(namespace::Entity) @@ -52,7 +56,8 @@ impl Tag { } /// Returns one tag by name and namespace - pub async fn by_name( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_name( db: DatabaseConnection, name: S1, namespace: Option, @@ -63,6 +68,7 @@ impl Tag { } /// Retrieves the namespaced tags by name and namespace + #[tracing::instrument(level = "debug", skip(db))] pub async fn all_by_name( db: DatabaseConnection, namespaces_with_names: Vec<(Option, String)>, @@ -93,7 +99,8 @@ impl Tag { } /// Adds a new tag to the database - pub async fn add( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn add( db: DatabaseConnection, name: S, namespace_id: Option, diff --git a/mediarepo-daemon/mediarepo-model/src/thumbnail.rs b/mediarepo-daemon/mediarepo-model/src/thumbnail.rs index d8a7d12..9c34871 100644 --- a/mediarepo-daemon/mediarepo-model/src/thumbnail.rs +++ b/mediarepo-daemon/mediarepo-model/src/thumbnail.rs @@ -4,6 +4,7 @@ use mediarepo_database::entities::hash; use mediarepo_database::entities::thumbnail; use sea_orm::prelude::*; use sea_orm::{DatabaseConnection, Set}; +use std::fmt::Debug; use tokio::fs::File; use tokio::io::BufReader; @@ -14,11 +15,13 @@ pub struct Thumbnail { } impl Thumbnail { + #[tracing::instrument(level = "trace")] pub(crate) fn new(db: DatabaseConnection, model: thumbnail::Model, hash: hash::Model) -> Self { Self { db, model, hash } } /// Returns the thumbnail by id + #[tracing::instrument(level = "debug", skip(db))] pub async fn by_id(db: DatabaseConnection, id: i64) -> RepoResult> { let model: Option<(thumbnail::Model, Option)> = thumbnail::Entity::find_by_id(id) @@ -34,7 +37,8 @@ impl Thumbnail { } /// Returns a thumbnail by hash - pub async fn by_hash>( + #[tracing::instrument(level = "debug", skip(db))] + pub async fn by_hash + Debug>( db: DatabaseConnection, hash: S, ) -> RepoResult> { @@ -51,6 +55,7 @@ impl Thumbnail { } /// Inserts a thumbnail into the database + #[tracing::instrument(level = "debug", skip(db))] pub async fn add( db: DatabaseConnection, hash_id: i64, @@ -78,6 +83,7 @@ impl Thumbnail { } /// Returns all thumbnails for a given file + #[tracing::instrument(level = "debug", skip(db))] pub async fn for_file_id(db: DatabaseConnection, file_id: i64) -> RepoResult> { let thumb_models: Vec<(thumbnail::Model, Option)> = thumbnail::Entity::find() .filter(thumbnail::Column::FileId.eq(file_id)) @@ -112,6 +118,7 @@ impl Thumbnail { } /// Returns the storage for the thumbnail + #[tracing::instrument(level = "debug", skip(self))] pub async fn storage(&self) -> RepoResult { let storage = Storage::by_id(self.db.clone(), self.model.storage_id) .await? @@ -121,6 +128,7 @@ impl Thumbnail { } /// Returns the reader of the thumbnail file + #[tracing::instrument(level = "debug", skip(self))] pub async fn get_reader(&self) -> RepoResult> { let storage = self.storage().await?; storage.get_file_reader(self.hash()).await diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.lock b/mediarepo-daemon/mediarepo-socket/Cargo.lock index bcd6b99..f5d1e75 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.lock +++ b/mediarepo-daemon/mediarepo-socket/Cargo.lock @@ -152,7 +152,7 @@ dependencies = [ "arrayref", "arrayvec 0.7.1", "cc", - "cfg-if", + "cfg-if 1.0.0", "constant_time_eq", ] @@ -202,6 +202,12 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -286,7 +292,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -295,8 +301,8 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", ] [[package]] @@ -305,9 +311,9 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "crossbeam-epoch", - "crossbeam-utils", + "crossbeam-utils 0.8.5", ] [[package]] @@ -316,8 +322,8 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", "lazy_static", "memoffset", "scopeguard", @@ -329,8 +335,19 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" dependencies = [ - "cfg-if", - "crossbeam-utils", + "cfg-if 1.0.0", + "crossbeam-utils 0.8.5", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", + "lazy_static", ] [[package]] @@ -339,7 +356,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "lazy_static", ] @@ -425,6 +442,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" + [[package]] name = "futures" version = "0.3.17" @@ -546,7 +569,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -649,7 +672,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -729,7 +752,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -743,7 +766,7 @@ name = "mediarepo-core" version = "0.1.0" dependencies = [ "base64", - "futures", + "futures 0.3.17", "image", "multibase", "multihash", @@ -779,6 +802,7 @@ dependencies = [ "sea-orm", "serde", "tokio", + "tracing", "typemap_rev", ] @@ -791,6 +815,8 @@ dependencies = [ "mediarepo-model", "serde", "tokio", + "tracing", + "tracing-futures", ] [[package]] @@ -1032,7 +1058,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" dependencies = [ "bitflags", - "cfg-if", + "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", @@ -1075,7 +1101,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "instant", "libc", "redox_syscall", @@ -1089,6 +1115,26 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pin-project" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.7" @@ -1275,7 +1321,7 @@ checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" dependencies = [ "crossbeam-channel", "crossbeam-deque", - "crossbeam-utils", + "crossbeam-utils 0.8.5", "lazy_static", "num_cpus", ] @@ -1310,16 +1356,16 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17765aa8bd4d19dd81c53c0707192115f36ec200aea9f4557526932ac1f418e0" +checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" dependencies = [ "lazy_static", - "log", "rmp-serde", "serde", "thiserror", "tokio", + "tracing", "typemap_rev", ] @@ -1382,7 +1428,7 @@ dependencies = [ "async-stream", "async-trait", "chrono", - "futures", + "futures 0.3.17", "futures-util", "rust_decimal", "sea-orm-macros", @@ -1517,7 +1563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" dependencies = [ "block-buffer", - "cfg-if", + "cfg-if 1.0.0", "cpufeatures", "digest", "opaque-debug", @@ -1583,7 +1629,7 @@ dependencies = [ "crc", "crossbeam-channel", "crossbeam-queue", - "crossbeam-utils", + "crossbeam-utils 0.8.5", "either", "futures-channel", "futures-core", @@ -1698,7 +1744,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "rand", "redox_syscall", @@ -1779,6 +1825,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "tokio-executor" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb2d1b8f4548dbf5e1f7818512e9c406860678f29c300cdf0ebac72d1a3a1671" +dependencies = [ + "crossbeam-utils 0.7.2", + "futures 0.1.31", +] + [[package]] name = "tokio-native-tls" version = "0.3.0" @@ -1809,6 +1865,49 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tokio-executor", + "tracing", +] + [[package]] name = "typemap_rev" version = "0.1.5" @@ -1915,7 +2014,7 @@ version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "wasm-bindgen-macro", ] diff --git a/mediarepo-daemon/mediarepo-socket/Cargo.toml b/mediarepo-daemon/mediarepo-socket/Cargo.toml index 480d55d..20ba9f6 100644 --- a/mediarepo-daemon/mediarepo-socket/Cargo.toml +++ b/mediarepo-daemon/mediarepo-socket/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] serde = "1.0.130" +tracing = "0.1.29" [dependencies.mediarepo-core] path = "../mediarepo-core" @@ -22,3 +23,6 @@ features = ["net"] version = "0.4.19" features = ["serde"] +[dependencies.tracing-futures] +version = "0.2.5" +features = ["tokio-executor"] \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-socket/src/lib.rs b/mediarepo-daemon/mediarepo-socket/src/lib.rs index ba46489..8e2e902 100644 --- a/mediarepo-daemon/mediarepo-socket/src/lib.rs +++ b/mediarepo-daemon/mediarepo-socket/src/lib.rs @@ -9,6 +9,7 @@ pub fn get_builder(address: &str) -> IPCBuilder { namespaces::build_namespaces(IPCBuilder::new().address(address)).on("info", callback!(info)) } +#[tracing::instrument(skip_all)] async fn info(ctx: &Context, event: Event) -> IPCResult<()> { let response = InfoResponse { name: env!("CARGO_PKG_NAME").to_string(), diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs index dea6964..92de96d 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/files.rs @@ -29,6 +29,7 @@ impl NamespaceProvider for FilesNamespace { impl FilesNamespace { /// Returns a list of all files + #[tracing::instrument(skip_all)] async fn all_files(ctx: &Context, event: Event) -> IPCResult<()> { let repo = get_repo_from_context(ctx).await; let files = repo.files().await?; @@ -42,6 +43,7 @@ impl FilesNamespace { } /// Searches for files by tags + #[tracing::instrument(skip_all)] async fn find_files(ctx: &Context, event: Event) -> IPCResult<()> { let tags = event.data::()?; let repo = get_repo_from_context(ctx).await; @@ -54,6 +56,7 @@ impl FilesNamespace { } /// Adds a file to the repository + #[tracing::instrument(skip_all)] async fn add_file(ctx: &Context, event: Event) -> IPCResult<()> { let request = event.data::()?; let path = PathBuf::from(request.path); @@ -73,6 +76,7 @@ impl FilesNamespace { } /// Reads the binary contents of a file + #[tracing::instrument(skip_all)] async fn read_file(ctx: &Context, event: Event) -> IPCResult<()> { let request = event.data::()?; @@ -90,6 +94,7 @@ impl FilesNamespace { } /// Returns a list of available thumbnails of a file + #[tracing::instrument(skip_all)] async fn thumbnails(ctx: &Context, event: Event) -> IPCResult<()> { let request = event.data::()?; let repo = get_repo_from_context(ctx).await; @@ -108,6 +113,7 @@ impl FilesNamespace { } /// Reads a thumbnail for the given thumbnail hash + #[tracing::instrument(skip_all)] async fn read_thumbnail(ctx: &Context, event: Event) -> IPCResult<()> { let hash = event.data::()?; let repo = get_repo_from_context(ctx).await; diff --git a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs index ddf6bba..248f794 100644 --- a/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs +++ b/mediarepo-daemon/mediarepo-socket/src/namespaces/tags.rs @@ -20,6 +20,7 @@ impl NamespaceProvider for TagsNamespace { impl TagsNamespace { /// Returns a list of all tags in the database + #[tracing::instrument(skip_all)] async fn all_tags(ctx: &Context, event: Event) -> IPCResult<()> { let repo = get_repo_from_context(ctx).await; let tags: Vec = repo @@ -36,6 +37,7 @@ impl TagsNamespace { } /// Returns all tags for a single file + #[tracing::instrument(skip_all)] async fn tags_for_file(ctx: &Context, event: Event) -> IPCResult<()> { let repo = get_repo_from_context(ctx).await; let request = event.data::()?; diff --git a/mediarepo-daemon/src/main.rs b/mediarepo-daemon/src/main.rs index d5d90fb..14f6485 100644 --- a/mediarepo-daemon/src/main.rs +++ b/mediarepo-daemon/src/main.rs @@ -8,7 +8,7 @@ use mediarepo_core::error::RepoResult; use mediarepo_core::settings::Settings; use mediarepo_core::type_keys::SettingsKey; use mediarepo_core::utils::parse_tags_file; -use mediarepo_model::file::File; +use mediarepo_model::file::File as RepoFile; use mediarepo_model::repo::Repo; use mediarepo_model::type_keys::RepoKey; use mediarepo_socket::get_builder; @@ -21,6 +21,8 @@ use structopt::StructOpt; use tokio::fs; use tokio::runtime; use tokio::runtime::Runtime; +use tracing_flame::FlameLayer; +use tracing_subscriber::{fmt, prelude::*}; #[derive(Debug, StructOpt)] #[structopt(name = "mediarepo", about = "A multimedia repository")] @@ -29,6 +31,9 @@ struct Opt { #[structopt(long, short, parse(from_os_str), default_value = ".")] repo: PathBuf, + #[structopt(long, short)] + profile: bool, + /// The subcommand to invoke #[structopt(subcommand)] cmd: SubCommand, @@ -56,8 +61,13 @@ enum SubCommand { } fn main() -> RepoResult<()> { - build_logger(); let opt: Opt = Opt::from_args(); + let mut _guard = None; + if opt.profile { + _guard = Some(init_tracing_flame()); + } else { + build_logger(); + } match opt.cmd.clone() { SubCommand::Init { force } => get_single_thread_runtime().block_on(init(opt, force)), @@ -97,12 +107,21 @@ fn build_logger() { .unwrap_or(LevelFilter::Info), ) .write_style(WriteStyle::Always) - //.filter_module("sqlx", log::LevelFilter::Warn) + .filter_module("sqlx", log::LevelFilter::Warn) .filter_module("tokio", log::LevelFilter::Info) - .filter_module("tracing", log::LevelFilter::Warn) .init(); } +fn init_tracing_flame() -> impl Drop { + let fmt_layer = fmt::Layer::default(); + let (flame_layer, _guard) = FlameLayer::with_file("./tracing.folded").unwrap(); + tracing_subscriber::registry() + .with(fmt_layer) + .with(flame_layer) + .init(); + _guard +} + async fn init_repo(opt: &Opt) -> RepoResult<(Settings, Repo)> { let settings = load_settings(&opt.repo.join(SETTINGS_PATH)).await?; let mut repo = get_repo(&opt.repo.join(&settings.database_path).to_str().unwrap()).await?; @@ -192,7 +211,11 @@ async fn import_single_image(path: PathBuf, repo: &Repo) -> RepoResult<()> { Ok(()) } -async fn add_tags_from_tags_file(tags_path: PathBuf, repo: &Repo, file: File) -> RepoResult<()> { +async fn add_tags_from_tags_file( + tags_path: PathBuf, + repo: &Repo, + file: RepoFile, +) -> RepoResult<()> { log::info!("Adding tags"); if tags_path.exists() { let tags = parse_tags_file(tags_path).await?;