@@ -3,6 +3,7 @@ use protocol::Event;
33use serde:: { Deserialize , Serialize } ;
44use std:: path:: Path ;
55use thiserror:: Error ;
6+ use tracing:: debug;
67
78pub mod cpuutil;
89mod perf_event;
@@ -15,9 +16,9 @@ pub use threadtrack::ThreadTrackerConfig;
1516
1617#[ derive( Error , Debug ) ]
1718pub 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
3637impl 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 ( ) ,
0 commit comments