Skip to content

Commit

Permalink
Initial implementation of sample only operation
Browse files Browse the repository at this point in the history
  • Loading branch information
miolad committed Jan 27, 2024
1 parent 5ba3f15 commit 07586dc
Show file tree
Hide file tree
Showing 14 changed files with 680 additions and 1,215 deletions.
420 changes: 290 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ tokio = { version = "1.28", features = ["sync", "macros"] }
metrics-common = { path = "../metrics-common" }
clap = { version = "4.4", features = ["derive"] }
prometheus = "0.13"
reqwest = "0.11"

[build-dependencies]
libbpf-cargo = "0.20"
bindgen = "0.64"

[features]
#default = ["save-traces"]
Expand Down
11 changes: 0 additions & 11 deletions netto/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::path::PathBuf;

const SRC: &str = "src/bpf/prog.bpf.c";
const SRC_H: &str = "src/bpf/prog.bpf.h";

fn main() {
let mut out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
Expand All @@ -13,15 +12,5 @@ fn main() {
.build_and_generate(out_dir)
.unwrap();

bindgen::Builder::default()
.header(SRC_H)
.allowlist_type("per_cpu_data")
.allowlist_type("event_types")
.generate()
.unwrap()
.write_to_file("src/common.rs")
.unwrap();

println!("cargo:rerun-if-changed={SRC}");
println!("cargo:rerun-if-changed={SRC_H}");
}
36 changes: 0 additions & 36 deletions netto/src/actors/file_logger.rs

This file was deleted.

114 changes: 0 additions & 114 deletions netto/src/actors/metrics_collector.rs

This file was deleted.

90 changes: 40 additions & 50 deletions netto/src/actors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,53 @@
use std::collections::HashMap;
use actix::Message;
use std::hash::Hash;

pub mod trace_analyzer;
pub mod metrics_collector;
pub mod websocket_client;
pub mod file_logger;
pub mod prometheus_logger;
pub mod pyroscope_exporter;

use actix::{Message, Addr};
use self::websocket_client::WebsocketClient;
pub type FoldedStackTraces = HashMap<StackTrace, usize>;

/// Signal new client connected to the `MetricsCollector` actor
#[derive(Message)]
#[rtype("()")]
struct ClientConnected {
addr: Addr<WebsocketClient>
#[derive(Eq)]
pub struct StackTrace {
pub frames: Vec<&'static str>
}

/// Signal client disconnected to the `MetricsCollector` actor
#[derive(Message)]
#[rtype("()")]
struct ClientDisconnected {
addr: Addr<WebsocketClient>
// Compare frames' strings by reference as equal symbols would share a reference to the same
// underlying static string
impl PartialEq for StackTrace {
fn eq(&self, other: &Self) -> bool {
self.frames.len() == other.frames.len() &&
self.frames.iter().zip(other.frames.iter()).all(|(&a, &b)| std::ptr::eq(a, b))
}
}

/// Represents an update for a single metric on a single CPU
/// from the `TraceAnalyzer` actor.
#[derive(Message)]
#[rtype("()")]
struct MetricUpdate {
/// This is the hierarchical name of the metric.
/// For example, "RX softirq/Bridging".
name: &'static str,

/// CPU index this metric update is for
cpuid: usize,

/// Fraction of CPU time in the [0, 1] range
cpu_frac: f64
// Also compute the hash against the pointer address of each stack frame
impl Hash for StackTrace {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write_usize(self.frames.len());
for &frame in &self.frames {
(frame as *const str).hash(state);
}
}
}

/// Used to trigger the `MetricsCollector` to submit the update
/// to all the clients.
#[derive(Message, Clone)]
#[derive(Message)]
#[rtype("()")]
struct SubmitUpdate {
/// Power drawn by the CPU in the networking stack
/// as measured.
/// It's None if the RAPL interface isn't available.
net_power_w: Option<f64>,

/// Fraction of the CPU time spent by the user-space tool
user_space_overhead: f64,

/// Metrics acquired from /proc/stat for validation
procfs_metrics: Vec<f64>
pub struct FoldedStackTraceBatch {
pub traces: FoldedStackTraces
}

/// Wrapper around a MessagePack buffer to send to websocket clients.
/// This struct exists solely because Vec<u8> can't implement Message.
#[derive(Message)]
#[rtype("()")]
struct EncodedUpdate {
inner: Vec<u8>
impl FoldedStackTraceBatch {
pub fn join_trace(&mut self, trace: StackTrace) -> Option<StackTrace> {
match self.traces.get_mut(&trace) {
Some(instances) => {
*instances += 1;
Some(trace)
},
None => {
self.traces.insert(trace, 1);
None
}
}
}
}
101 changes: 0 additions & 101 deletions netto/src/actors/prometheus_logger.rs

This file was deleted.

Loading

0 comments on commit 07586dc

Please sign in to comment.