33from pythonbpf import dwarf_constants as dc
44from enum import Enum
55from .maps_utils import MapProcessorRegistry
6+ import logging
7+
8+ logger = logging .getLogger (__name__ )
69
710
811def maps_proc (tree , module , chunks ):
@@ -46,7 +49,7 @@ def create_bpf_map(module, map_name, map_params):
4649 # Generate debug info for BTF
4750 create_map_debug_info (module , map_global , map_name , map_params )
4851
49- print (f"Created BPF map: { map_name } " )
52+ logger . info (f"Created BPF map: { map_name } with params { map_params } " )
5053 return map_global
5154
5255
@@ -182,7 +185,7 @@ def create_map_debug_info(module, map_global, map_name, map_params):
182185@MapProcessorRegistry .register ("HashMap" )
183186def process_hash_map (map_name , rval , module ):
184187 """Process a BPF_HASH map declaration"""
185- print (f"Creating HashMap map : { map_name } " )
188+ logger . info (f"Processing HashMap: { map_name } " )
186189 map_params = {"type" : BPFMapType .HASH }
187190
188191 # Assuming order: key_type, value_type, max_entries
@@ -206,14 +209,14 @@ def process_hash_map(map_name, rval, module):
206209 if isinstance (const_val , (int , str )):
207210 map_params ["max_entries" ] = const_val
208211
209- print (f"Map parameters: { map_params } " )
212+ logger . info (f"Map parameters: { map_params } " )
210213 return create_bpf_map (module , map_name , map_params )
211214
212215
213216@MapProcessorRegistry .register ("PerfEventArray" )
214217def process_perf_event_map (map_name , rval , module ):
215218 """Process a BPF_PERF_EVENT_ARRAY map declaration"""
216- print (f"Creating PerfEventArray map : { map_name } " )
219+ logger . info (f"Processing PerfEventArray: { map_name } " )
217220 map_params = {"type" : BPFMapType .PERF_EVENT_ARRAY }
218221
219222 if len (rval .args ) >= 1 and isinstance (rval .args [0 ], ast .Name ):
@@ -228,14 +231,14 @@ def process_perf_event_map(map_name, rval, module):
228231 isinstance (keyword .value , ast .Name ):
229232 map_params ["value_size" ] = keyword .value .id
230233
231- print (f"Map parameters: { map_params } " )
234+ logger . info (f"Map parameters: { map_params } " )
232235 return create_bpf_map (module , map_name , map_params )
233236
234237
235238def process_bpf_map (func_node , module ):
236239 """Process a BPF map (a function decorated with @map)"""
237240 map_name = func_node .name
238- print (f"Processing BPF map: { map_name } " )
241+ logger . info (f"Processing BPF map: { map_name } " )
239242
240243 # For now, assume single return statement
241244 return_stmt = None
@@ -253,7 +256,8 @@ def process_bpf_map(func_node, module):
253256 if handler :
254257 return handler (map_name , rval , module )
255258 else :
256- print (f"Unknown map type { rval .func .id } , defaulting to HashMap" )
259+ logger .warning (f"Unknown map type {
260+ rval .func .id } , defaulting to HashMap" )
257261 process_hash_map (map_name , rval , module )
258262 else :
259263 raise ValueError ("Function under @map must return a map" )
0 commit comments