Sitelet https://github.com/category-labs/manytrace/commit/c10cc6f2bd230df5e8d05bd36b03aadd679a8355
Skip to content

Commit c10cc6f

Browse files
committed
bpf: add debug tracing for config initialization
Add structured debug logging to show which BPF plugins are being initialized and their configuration values.
1 parent 89d022a commit c10cc6f

6 files changed

Lines changed: 52 additions & 13 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
components: rustfmt
3535
skip_deps: true
3636
- name: bpf-root-tests
37-
command: sudo -E env "PATH=$PATH" cargo nextest run -p bpf root_tests --run-ignored
37+
command: sudo -E env "PATH=$PATH" cargo nextest run -p bpf root_tests --run-ignored all
3838
components: ""
3939
install_extras: true
4040

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎agent/src/mpsc.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ mod tests {
108108
tid: 123,
109109
pid: 456,
110110
labels: Cow::Owned(Labels::new()),
111-
unit: None
111+
unit: None,
112112
});
113113

114114
producer.submit(&counter).unwrap();

‎bpf/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ plain = { workspace = true }
2222
serde = { workspace = true }
2323
thiserror = { workspace = true }
2424
toml = { workspace = true }
25+
tracing = { workspace = true }
2526
protocol = { path = "../protocol" }
2627

2728
[dev-dependencies]

‎bpf/src/lib.rs‎

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use protocol::Event;
33
use serde::{Deserialize, Serialize};
44
use std::path::Path;
55
use thiserror::Error;
6+
use tracing::debug;
67

78
pub mod cpuutil;
89
mod perf_event;
@@ -15,9 +16,9 @@ pub use threadtrack::ThreadTrackerConfig;
1516

1617
#[derive(Error, Debug)]
1718
pub enum BpfError {
18-
#[error("Failed to load BPF program: {0}")]
19+
#[error("failed to load BPF program: {0}")]
1920
LoadError(String),
20-
#[error("Failed to attach BPF program: {0}")]
21+
#[error("failed to attach BPF program: {0}")]
2122
AttachError(String),
2223
#[error("BPF map operation failed: {0}")]
2324
MapError(String),
@@ -35,22 +36,58 @@ pub struct BpfConfig {
3536

3637
impl BpfConfig {
3738
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, BpfError> {
39+
let path = path.as_ref();
40+
debug!(path = %path.display(), "loading bpf config");
41+
3842
let content = std::fs::read_to_string(path)
39-
.map_err(|e| BpfError::LoadError(format!("Failed to read config file: {}", e)))?;
43+
.map_err(|e| BpfError::LoadError(format!("failed to read config file: {}", e)))?;
44+
45+
let config = toml::from_str(&content)
46+
.map_err(|e| BpfError::LoadError(format!("failed to parse TOML: {}", e)))?;
4047

41-
toml::from_str(&content)
42-
.map_err(|e| BpfError::LoadError(format!("Failed to parse TOML: {}", e)))
48+
Ok(config)
4349
}
4450

4551
pub fn from_toml_str(content: &str) -> Result<Self, BpfError> {
46-
toml::from_str(content)
47-
.map_err(|e| BpfError::LoadError(format!("Failed to parse TOML: {}", e)))
52+
let config = toml::from_str(content)
53+
.map_err(|e| BpfError::LoadError(format!("failed to parse TOML: {}", e)))?;
54+
55+
Ok(config)
4856
}
4957

5058
pub fn build(self) -> Result<BpfObject, BpfError> {
51-
let threadtrack = self.thread_tracker.map(|_| threadtrack::Object::new());
52-
let cpuutils = self.cpu_util.map(cpuutil::Object::new);
53-
let profiler = self.profiler.map(profiler::Object::new);
59+
let threadtrack = if let Some(_cfg) = self.thread_tracker {
60+
debug!("initializing thread tracker");
61+
Some(threadtrack::Object::new())
62+
} else {
63+
None
64+
};
65+
66+
let cpuutils = if let Some(cfg) = self.cpu_util {
67+
debug!(
68+
module = "cpuutil",
69+
interval_ms = cfg.interval_ms,
70+
pid_filters = ?cfg.pid_filters,
71+
"initializing cpu utilization monitor"
72+
);
73+
Some(cpuutil::Object::new(cfg))
74+
} else {
75+
None
76+
};
77+
78+
let profiler = if let Some(cfg) = self.profiler {
79+
debug!(
80+
module = "profiler",
81+
sample_freq = cfg.sample_freq,
82+
kernel_samples = cfg.kernel_samples,
83+
user_samples = cfg.user_samples,
84+
pid_filters = ?cfg.pid_filters,
85+
"initializing profiler"
86+
);
87+
Some(profiler::Object::new(cfg))
88+
} else {
89+
None
90+
};
5491

5592
Ok(BpfObject {
5693
symbolizer: Symbolizer::new(),

‎protocol/benches/counter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn create_counter_with_labels(num_labels: usize) -> Counter<'static> {
6363
tid: 123,
6464
pid: 456,
6565
labels: Cow::Owned(labels),
66-
unit: Some("unit")
66+
unit: Some("unit"),
6767
}
6868
}
6969

0 commit comments

Comments
 (0)