Skip to content

Commit

Permalink
Allow changing controller invocation period
Browse files Browse the repository at this point in the history
  • Loading branch information
miolad committed Sep 5, 2023
1 parent 2445d58 commit 623fc54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion main/src/actors/trace_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use std::fs::File;
/// retrieve stack traces from the ring buffer, and analyze them
/// to provide user-facing performance metrics.
pub struct TraceAnalyzer {
/// User-space invocation period in ms
run_interval_ms: u64,

/// libbpf's skeleton
skel: ProgSkel<'static>,

Expand Down Expand Up @@ -66,6 +69,7 @@ impl TraceAnalyzer {
/// to be able to acquire it as an owned `libbpf_rs::Map` and
/// avoid the reference to the lifetime of the main skel.
pub fn new(
run_interval_ms: u64,
skel: ProgSkel<'static>,
num_possible_cpus: usize,
metrics_collector_addr: Addr<MetricsCollector>,
Expand Down Expand Up @@ -93,6 +97,7 @@ impl TraceAnalyzer {
};

Ok(Self {
run_interval_ms,
skel,
stack_traces_ptr,
counts: vec![Counts::default(); num_possible_cpus],
Expand Down Expand Up @@ -347,7 +352,7 @@ impl Actor for TraceAnalyzer {
type Context = Context<Self>;

fn started(&mut self, ctx: &mut Self::Context) {
ctx.run_interval(Duration::from_millis(500), |act, _| {
ctx.run_interval(Duration::from_millis(self.run_interval_ms), |act, _| {
if let Err(e) = act.run_interval() {
act.error_catcher_sender.blocking_send(e).unwrap();
}
Expand Down
9 changes: 7 additions & 2 deletions main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::actors::{metrics_collector::MetricsCollector, websocket_client::Webso
#[command(about = "eBPF-based network diagnosis tool for Linux")]
#[command(version)]
struct Cli {
/// Perf-event's sampling frequency for the NET_RX_SOFTIRQ cost breakdown
/// Perf-event's sampling frequency in Hz for the NET_RX_SOFTIRQ cost breakdown
#[arg(short, long, default_value_t = 1000)]
frequency: u64,

Expand All @@ -36,7 +36,11 @@ struct Cli {

/// Bind port for the web frontend
#[arg(short, long, default_value_t = 8080)]
port: u16
port: u16,

/// User-space controller update period in ms
#[arg(long, default_value_t = 500)]
user_frequency: u64
}

#[actix_web::get("/ws/")]
Expand Down Expand Up @@ -116,6 +120,7 @@ fn main() -> anyhow::Result<()> {
.start();

let _trace_analyzer_actor_addr = TraceAnalyzer::new(
cli.user_frequency,
skel,
num_possible_cpus,
metrics_collector_actor_addr.clone(),
Expand Down

0 comments on commit 623fc54

Please sign in to comment.