Spaces:
Build error
Build error
use std::sync::Arc; | |
use parking_lot::Mutex; | |
use schemars::JsonSchema; | |
use serde::{Deserialize, Serialize}; | |
use crate::common::pyroscope_state::pyro::PyroscopeState; | |
use crate::settings::Settings; | |
pub struct PyroscopeConfig { | |
pub url: String, | |
pub identifier: String, | |
pub user: Option<String>, | |
pub password: Option<String>, | |
pub sampling_rate: Option<u32>, | |
} | |
pub struct DebuggerConfig { | |
pub pyroscope: Option<PyroscopeConfig>, | |
} | |
pub enum DebugConfigPatch { | |
Pyroscope(Option<PyroscopeConfig>), | |
} | |
pub struct DebuggerState { | |
pub pyroscope: Arc<Mutex<Option<PyroscopeState>>>, | |
} | |
impl DebuggerState { | |
pub fn from_settings(settings: &Settings) -> Self { | |
let pyroscope_config = settings.debugger.pyroscope.clone(); | |
Self { | |
pyroscope: Arc::new(Mutex::new(PyroscopeState::from_config(pyroscope_config))), | |
} | |
} | |
pub fn get_config(&self) -> DebuggerConfig { | |
let pyroscope_config = { | |
{ | |
let pyroscope_state_guard = self.pyroscope.lock(); | |
pyroscope_state_guard.as_ref().map(|s| s.config.clone()) | |
} | |
{ | |
None | |
} | |
}; | |
DebuggerConfig { | |
pyroscope: pyroscope_config, | |
} | |
} | |
pub fn apply_config_patch(&self, patch: DebugConfigPatch) -> bool { | |
{ | |
match patch { | |
DebugConfigPatch::Pyroscope(new_config) => { | |
let mut pyroscope_guard = self.pyroscope.lock(); | |
if let Some(pyroscope_state) = pyroscope_guard.as_mut() { | |
let stopped = pyroscope_state.stop_agent(); | |
if !stopped { | |
return false; | |
} | |
} | |
if let Some(new_config) = new_config { | |
*pyroscope_guard = PyroscopeState::from_config(Some(new_config)); | |
} | |
true | |
} | |
} | |
} | |
{ | |
let _ = patch; // Ignore new_config on non-linux OS | |
false | |
} | |
} | |
} | |