From e92c924b45bffbd6b788cbe38dd6e0ebda3e4cbe Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Wed, 22 Mar 2023 15:02:16 +0100 Subject: [PATCH] log tauri commands execution time --- src-tauri/Cargo.lock | 213 ++++++++++++++++++++++++++++++++++++++++-- src-tauri/Cargo.toml | 1 + src-tauri/src/main.rs | 28 +++++- src/lib/deltas.ts | 8 +- src/lib/sessions.ts | 19 +--- 5 files changed, 233 insertions(+), 36 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 867655895..974b17285 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -64,6 +64,18 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "async-trait" version = "0.1.64" @@ -167,6 +179,17 @@ dependencies = [ "crunchy", ] +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + [[package]] name = "block" version = "0.1.6" @@ -394,6 +417,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "convert_case" version = "0.4.0" @@ -570,6 +599,27 @@ dependencies = [ "syn", ] +[[package]] +name = "csv" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b015497079b9a9d69c02ad25de6c0a6edef051ea6360a327d0bd05802ef64ad" +dependencies = [ + "csv-core", + "itoa 1.0.5", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "ctor" version = "0.1.26" @@ -586,14 +636,38 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + [[package]] name = "darling" version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn", ] [[package]] @@ -606,7 +680,18 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core 0.10.2", + "quote", "syn", ] @@ -616,7 +701,7 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ - "darling_core", + "darling_core 0.13.4", "quote", "syn", ] @@ -654,6 +739,17 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users 0.3.5", + "winapi", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -671,7 +767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ "libc", - "redox_users", + "redox_users 0.4.3", "winapi", ] @@ -720,6 +816,12 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "encoding_rs" version = "0.8.31" @@ -808,7 +910,7 @@ checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "windows-sys 0.42.0", ] @@ -1149,6 +1251,7 @@ dependencies = [ "tauri-plugin-window-state", "tempfile", "thiserror", + "timed", "tokio", "urlencoding", "uuid 1.3.0", @@ -2440,7 +2543,7 @@ checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "windows-sys 0.42.0", ] @@ -2647,6 +2750,20 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "prettytable-rs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e" +dependencies = [ + "atty", + "csv", + "encode_unicode", + "lazy_static", + "term", + "unicode-width", +] + [[package]] name = "proc-macro-crate" version = "1.3.0" @@ -2835,6 +2952,12 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + [[package]] name = "redox_syscall" version = "0.2.16" @@ -2844,6 +2967,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -2851,7 +2985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom 0.2.8", - "redox_syscall", + "redox_syscall 0.2.16", "thiserror", ] @@ -2951,6 +3085,18 @@ dependencies = [ "windows 0.37.0", ] +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64 0.13.1", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rust-stemmers" version = "1.2.0" @@ -3306,7 +3452,7 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" dependencies = [ - "darling", + "darling 0.13.4", "proc-macro2", "quote", "syn", @@ -3481,6 +3627,12 @@ dependencies = [ "quote", ] +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "strsim" version = "0.10.0" @@ -3883,7 +4035,7 @@ dependencies = [ "cfg-if", "fastrand", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "remove_dir_all", "winapi", ] @@ -3899,6 +4051,17 @@ dependencies = [ "utf-8", ] +[[package]] +name = "term" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" +dependencies = [ + "byteorder", + "dirs", + "winapi", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -3961,6 +4124,30 @@ dependencies = [ "time-core", ] +[[package]] +name = "timed" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48906074d8e63c71828fc467e5867ef99b1e32bc8338a6d088cac075ea5a783d" +dependencies = [ + "lazy_static", + "prettytable-rs", + "thiserror", + "timed_proc_macros", +] + +[[package]] +name = "timed_proc_macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2418d1ff5ec1868c462fb3a4b7907b2335791e5425c9b3908326452d3bf166a" +dependencies = [ + "darling 0.10.2", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -4184,6 +4371,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "url" version = "2.3.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index abf6b9834..11318be5a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -38,6 +38,7 @@ tantivy = "0.19.2" similar = "2.2.1" fslock = "0.2.1" tokio = { version = "1.26.0", features = ["sync"] } +timed = "0.2.1" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index aa4361f06..3376e8f60 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,9 +9,11 @@ mod storage; mod users; mod watchers; +#[macro_use] +extern crate log; + use anyhow::{Context, Result}; use deltas::Delta; -use log; use serde::{ser::SerializeMap, Serialize}; use std::{collections::HashMap, ops::Range, sync::Mutex}; use storage::Storage; @@ -21,6 +23,7 @@ use tauri_plugin_log::{ LogTarget, }; use thiserror::Error; +use timed::timed; #[derive(Debug, Error)] pub enum Error { @@ -103,6 +106,7 @@ fn build_asset_url(path: &str) -> String { format!("asset://localhost/{}", urlencoding::encode(path)) } +#[timed(duration(printer = "info!"))] async fn proxy_image(handle: tauri::AppHandle, src: &str) -> Result { if src.starts_with("asset://") { return Ok(src.to_string()); @@ -138,6 +142,7 @@ async fn proxy_image(handle: tauri::AppHandle, src: &str) -> Result { Ok(build_asset_url(&save_to.display().to_string())) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn search( handle: tauri::AppHandle, @@ -172,6 +177,7 @@ async fn search( Ok(deltas) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn list_sessions( handle: tauri::AppHandle, @@ -186,6 +192,7 @@ async fn list_sessions( Ok(sessions) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn get_user(handle: tauri::AppHandle) -> Result, Error> { let app_state = handle.state::(); @@ -215,6 +222,7 @@ async fn get_user(handle: tauri::AppHandle) -> Result, Error } } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn set_user(handle: tauri::AppHandle, user: users::User) -> Result<(), Error> { let app_state = handle.state::(); @@ -229,6 +237,7 @@ async fn set_user(handle: tauri::AppHandle, user: users::User) -> Result<(), Err Ok(()) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn delete_user(handle: tauri::AppHandle) -> Result<(), Error> { let app_state = handle.state::(); @@ -243,6 +252,7 @@ async fn delete_user(handle: tauri::AppHandle) -> Result<(), Error> { Ok(()) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn update_project( handle: tauri::AppHandle, @@ -258,6 +268,7 @@ async fn update_project( Ok(project) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn add_project(handle: tauri::AppHandle, path: &str) -> Result { let app_state = handle.state::(); @@ -303,6 +314,7 @@ async fn add_project(handle: tauri::AppHandle, path: &str) -> Result Result, Error> { let app_state = handle.state::(); @@ -312,6 +324,7 @@ async fn list_projects(handle: tauri::AppHandle) -> Result Result<(), Error> { let app_state = handle.state::(); @@ -334,6 +347,7 @@ async fn delete_project(handle: tauri::AppHandle, id: &str) -> Result<(), Error> } } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn list_session_files( handle: tauri::AppHandle, @@ -346,6 +360,7 @@ async fn list_session_files( Ok(files) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn list_deltas( handle: tauri::AppHandle, @@ -358,6 +373,7 @@ async fn list_deltas( Ok(deltas) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn git_status( handle: tauri::AppHandle, @@ -368,6 +384,7 @@ async fn git_status( Ok(files) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn git_wd_diff( handle: tauri::AppHandle, @@ -380,6 +397,7 @@ async fn git_wd_diff( Ok(diff) } +#[timed(duration(printer = "info!"))] #[tauri::command(async)] async fn git_file_paths(handle: tauri::AppHandle, project_id: &str) -> Result, Error> { let repo = repo_for_project(handle, project_id)?; @@ -390,6 +408,7 @@ async fn git_file_paths(handle: tauri::AppHandle, project_id: &str) -> Result Result, Error> { let repo = repo_for_project(handle, project_id)?; @@ -429,6 +449,7 @@ async fn git_branches(handle: tauri::AppHandle, project_id: &str) -> Result Result { let repo = repo_for_project(handle, project_id)?; @@ -438,6 +459,7 @@ async fn git_branch(handle: tauri::AppHandle, project_id: &str) -> Result { - const start = performance.now(); - const result = await invoke>('list_deltas', params); - log.debug(`list_deltas took ${performance.now() - start}ms`); - return result; -}; +export const list = (params: { projectId: string; sessionId: string; paths?: string[] }) => + invoke>('list_deltas', params); export const subscribe = ( params: { projectId: string; sessionId: string }, diff --git a/src/lib/sessions.ts b/src/lib/sessions.ts index 7b21811b0..996f37982 100644 --- a/src/lib/sessions.ts +++ b/src/lib/sessions.ts @@ -29,23 +29,10 @@ export type Session = { activity: Activity[]; }; -export const listFiles = async (params: { - projectId: string; - sessionId: string; - paths?: string[]; -}) => { - const start = performance.now(); - const result = await invoke>('list_session_files', params); - log.debug(`list_session_files took ${performance.now() - start}ms`); - return result; -}; +export const listFiles = (params: { projectId: string; sessionId: string; paths?: string[] }) => + invoke>('list_session_files', params); -const list = async (params: { projectId: string }) => { - const start = performance.now(); - const result = await invoke('list_sessions', params); - log.debug(`list_sessions took ${performance.now() - start}ms`); - return result; -}; +const list = (params: { projectId: string }) => invoke('list_sessions', params); export default async (params: { projectId: string; earliestTimestampMs?: number }) => { const store = writable([] as Session[]);