11use super :: GlobalConfig ;
22use crate :: config:: {
3- autotune:: AutotuneLogLevel , compilation:: CompilationLogLevel , profiling :: ProfilingLogLevel ,
4- streaming:: StreamingLogLevel ,
3+ autotune:: AutotuneLogLevel , compilation:: CompilationLogLevel , memory :: MemoryLogLevel ,
4+ profiling :: ProfilingLogLevel , streaming:: StreamingLogLevel ,
55} ;
66use alloc:: { string:: ToString , sync:: Arc , vec:: Vec } ;
77use core:: fmt:: Display ;
@@ -118,6 +118,9 @@ pub struct Logger {
118118 /// Indices of loggers used for streaming logging.
119119 streaming_index : Vec < usize > ,
120120
121+ /// Indices of loggers used for memory logging.
122+ memory_index : Vec < usize > ,
123+
121124 /// Global configuration for logging settings.
122125 pub config : Arc < GlobalConfig > ,
123126}
@@ -142,6 +145,7 @@ impl Logger {
142145 let mut profiling_index = Vec :: new ( ) ;
143146 let mut autotune_index = Vec :: new ( ) ;
144147 let mut streaming_index = Vec :: new ( ) ;
148+ let mut memory_index = Vec :: new ( ) ;
145149
146150 #[ derive( Hash , PartialEq , Eq ) ]
147151 enum LoggerId {
@@ -281,12 +285,25 @@ impl Logger {
281285 )
282286 }
283287
288+ if let MemoryLogLevel :: Disabled = config. memory . logger . level {
289+ } else {
290+ register_logger (
291+ & config. memory . logger ,
292+ config. memory . logger . append ,
293+ config. memory . logger . log ,
294+ & mut memory_index,
295+ & mut loggers,
296+ & mut logger2index,
297+ )
298+ }
299+
284300 Self {
285301 loggers,
286302 compilation_index,
287303 profiling_index,
288304 autotune_index,
289305 streaming_index,
306+ memory_index,
290307 config,
291308 }
292309 }
@@ -305,6 +322,20 @@ impl Logger {
305322 }
306323 }
307324
325+ /// Logs a message for memory, directing it to all configured streaming loggers.
326+ pub fn log_memory < S : Display > ( & mut self , msg : & S ) {
327+ let length = self . memory_index . len ( ) ;
328+ if length > 1 {
329+ let msg = msg. to_string ( ) ;
330+ for i in 0 ..length {
331+ let index = self . memory_index [ i] ;
332+ self . log ( & msg, index)
333+ }
334+ } else if let Some ( index) = self . memory_index . first ( ) {
335+ self . log ( & msg, * index)
336+ }
337+ }
338+
308339 /// Logs a message for compilation, directing it to all configured compilation loggers.
309340 pub fn log_compilation < S : Display > ( & mut self , msg : & S ) {
310341 let length = self . compilation_index . len ( ) ;
0 commit comments