Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
Signed-off-by: Calvin Neo <[email protected]>
  • Loading branch information
CalvinNeo committed Aug 28, 2024
1 parent f2e5fb8 commit 9aa9d0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions proxy_components/proxy_server/src/status_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ where
None => 60,
};

let enable_period = match query_pairs.get("period") {
Some(val) => match val.parse() {
Ok(val) => val,
Err(err) => return Ok(make_response(StatusCode::BAD_REQUEST, err.to_string())),
},
None => 0,
};

if enable_period == 0 {
let msg = "set prof.active = true";
set_prof_active(true);
return Ok(make_response(StatusCode::OK, msg));
}

let interval = Duration::from_secs(interval);
let period = GLOBAL_TIMER_HANDLE
.interval(Instant::now() + interval, interval)
Expand All @@ -226,11 +240,24 @@ where
}

fn deactivate_heap_prof(_req: Request<Body>) -> hyper::Result<Response<Body>> {
let disable_period = match query_pairs.get("period") {
Some(val) => match val.parse() {
Ok(val) => val,
Err(err) => return Ok(make_response(StatusCode::BAD_REQUEST, err.to_string())),
},
None => 1,
};

let body = if deactivate_heap_profile() {
"deactivate heap profile success"
} else {
"no heap profile is running"
};

if disable_period == 1 {
set_prof_active(false);
}

Ok(make_response(StatusCode::OK, body))
}

Expand Down
13 changes: 13 additions & 0 deletions proxy_components/proxy_server/src/status_server/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ where
ProfileGuard::new(on_start, on_end, end.boxed())?.await
}

pub fn set_prof_active(val: bool) -> Result<(), String> {
let activate = has_activate_prof();
if activate == val {
return Ok(());
}
if val {
activate_prof().map_err(|e| format!("activate_prof: {}", e))?;
} else {
deactivate_prof().map_err(|e| format!("deactivate_prof: {}", e))?;
}
Ok(())
}

/// Activate heap profile and call `callback` if successfully.
/// `deactivate_heap_profile` can only be called after it's notified from
/// `callback`.
Expand Down

0 comments on commit 9aa9d0e

Please sign in to comment.