diff --git a/Packages/app-server/Cargo.toml b/Packages/app-server/Cargo.toml index b8138d2f..e95f2785 100644 --- a/Packages/app-server/Cargo.toml +++ b/Packages/app-server/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" edition = "2021" publish = false +# dependencies specific to linux +[target.'cfg(unix)'.dependencies] +pyroscope = "0.5.7" +pyroscope_pprofrs = "0.2.7" + [dependencies] #log = "0.4.16" tracing = "0.1" # todo: remove this (since part of rust_shared now) @@ -26,8 +31,6 @@ dyn-clone = "1.0.4" oauth2 = "4.4.2" dotenv = "0.15.0" lexicon_fractional_index = "0.0.3" -pyroscope = "0.5.7" -pyroscope_pprofrs = "0.2.7" # temp-fix for https://github.com/tikv/pprof-rs/issues/232 #pprof = {git = "https://github.com/Erigara/pprof-rs", branch = "fix-pointer-align"} diff --git a/Packages/app-server/src/globals.rs b/Packages/app-server/src/globals.rs index e3a982c5..1484b3c5 100644 --- a/Packages/app-server/src/globals.rs +++ b/Packages/app-server/src/globals.rs @@ -1,7 +1,10 @@ -use std::{alloc::System, panic, backtrace::Backtrace}; +#[cfg(unix)] +use { + pyroscope::{pyroscope::PyroscopeAgentReady, PyroscopeAgent}, + pyroscope_pprofrs::{pprof_backend, PprofConfig} +}; -use pyroscope::{pyroscope::PyroscopeAgentReady, PyroscopeAgent}; -use pyroscope_pprofrs::{pprof_backend, PprofConfig}; +use std::{alloc::System, panic, backtrace::Backtrace}; use rust_shared::{domains::{get_env, is_prod}, flume, links::app_server_to_monitor_backend::Message_ASToMB, once_cell::sync::OnceCell, sentry::{self, ClientInitGuard}, tokio, utils::{errors_::backtrace_simplifier::{simplify_backtrace_str}, mtx::mtx::{MtxData, MtxDataWithExtraInfo, MtxGlobalMsg, MTX_GLOBAL_MESSAGE_SENDER_AND_RECEIVER}, type_aliases::{FReceiver, FSender}}}; use tracing::{info, error}; use dotenv::dotenv; @@ -11,7 +14,7 @@ use crate::{utils::general::{mem_alloc::Trallocator, logging::set_up_logging, da #[global_allocator] pub static GLOBAL: Trallocator = Trallocator::new(System); -pub fn set_up_globals() -> (Option, PyroscopeAgent) { +pub fn set_up_globals() -> Option { //panic::always_abort(); panic::set_hook(Box::new(|info| { // do a simple println! first, to confirm our handler started running @@ -33,16 +36,22 @@ pub fn set_up_globals() -> (Option, PyroscopeAgent PyroscopeAgent { // configure pprof (profiling backend) + pyroscope let pprof_config = PprofConfig::new().sample_rate(100); let backend_impl = pprof_backend(pprof_config); let agent = PyroscopeAgent::builder("http://pyroscope.monitoring.svc.cluster.local:4040/", "app-server").backend(backend_impl).build().unwrap(); - - GLOBAL.reset(); - info!("Memory used: {} bytes", GLOBAL.get()); - - (sentry_guard, agent) + agent } +#[cfg(not(unix))] +pub fn set_up_globals_linux() -> Option { None } fn set_up_sentry() -> Option { if is_prod() { diff --git a/Packages/app-server/src/main.rs b/Packages/app-server/src/main.rs index 4b85397a..c1bad33c 100644 --- a/Packages/app-server/src/main.rs +++ b/Packages/app-server/src/main.rs @@ -40,7 +40,7 @@ use rust_shared::{tokio, sentry, domains::{DomainsConstants, get_env}}; use store::storage::AppStateArc; use tracing::{error}; -use crate::{links::{pgclient::{self, start_pgclient_with_restart}, db_live_cache::start_db_live_cache}, globals::{set_up_globals}, router::start_router, store::storage::AppState, utils::general::data_anchor::DataAnchorFor1}; +use crate::{links::{pgclient::{self, start_pgclient_with_restart}, db_live_cache::start_db_live_cache}, globals::{set_up_globals, set_up_globals_linux}, router::start_router, store::storage::AppState, utils::general::data_anchor::DataAnchorFor1}; // folders (we only use "folder_x/mod.rs" files one-layer deep; keeps the mod-tree structure out of main.rs, while avoiding tons of mod.rs files littering the codebase) mod db; @@ -55,8 +55,9 @@ mod router; //#[tokio::main(flavor = "multi_thread", worker_threads = 7)] #[tokio::main] async fn main() { - let (_sentry_guard, agent) = set_up_globals(); - let agent_running = agent.start().unwrap(); + let _sentry_guard = set_up_globals(); + #[cfg(unix)] let agent = set_up_globals_linux(); + #[cfg(unix)] let agent_running = agent.start().unwrap(); println!("Setup of globals completed."); // have one regular print-line, in case logger has issues let app_state = AppState::new_in_arc(); @@ -70,6 +71,8 @@ async fn main() { // start router; this handles all "external web requests" start_router(app_state).await; - let agent_ready = agent_running.stop().unwrap(); - agent_ready.shutdown(); + #[cfg(unix)] { + let agent_ready = agent_running.stop().unwrap(); + agent_ready.shutdown(); + } } \ No newline at end of file