Skip to content

Commit

Permalink
* Fixed cargo-check on windows. (due to recent addition of pyroscope …
Browse files Browse the repository at this point in the history
…continuous profiler, which only works on linux -- had to use os-specific conditional deps + code-blocks)
  • Loading branch information
Venryx committed May 19, 2024
1 parent ba25150 commit 57d23a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
7 changes: 5 additions & 2 deletions Packages/app-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"}
Expand Down
27 changes: 18 additions & 9 deletions Packages/app-server/src/globals.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +14,7 @@ use crate::{utils::general::{mem_alloc::Trallocator, logging::set_up_logging, da
#[global_allocator]
pub static GLOBAL: Trallocator<System> = Trallocator::new(System);

pub fn set_up_globals() -> (Option<ClientInitGuard>, PyroscopeAgent<PyroscopeAgentReady>) {
pub fn set_up_globals() -> Option<ClientInitGuard> {
//panic::always_abort();
panic::set_hook(Box::new(|info| {
// do a simple println! first, to confirm our handler started running
Expand All @@ -33,16 +36,22 @@ pub fn set_up_globals() -> (Option<ClientInitGuard>, PyroscopeAgent<PyroscopeAge
set_up_logging();
set_up_mtx_handler();

GLOBAL.reset();
info!("Memory used: {} bytes", GLOBAL.get());

sentry_guard
}

#[cfg(unix)]
pub fn set_up_globals_linux() -> PyroscopeAgent<PyroscopeAgentReady> {
// 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<bool> { None }

fn set_up_sentry() -> Option<ClientInitGuard> {
if is_prod() {
Expand Down
13 changes: 8 additions & 5 deletions Packages/app-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
}
}

0 comments on commit 57d23a4

Please sign in to comment.