@@ -214,11 +214,17 @@ impl RuntimeMemoryLogController {
214214 & self . config
215215 }
216216
217- pub fn should_write_process_for_event ( & self , now : Instant , event : & RuntimeMemoryLogEvent ) -> bool {
217+ pub fn should_write_process_for_event (
218+ & self ,
219+ now : Instant ,
220+ event : & RuntimeMemoryLogEvent ,
221+ ) -> bool {
218222 event. force_attribution
219223 || self
220224 . last_process_sample_at
221- . map ( |last| now. saturating_duration_since ( last) >= self . config . event_process_min_spacing )
225+ . map ( |last| {
226+ now. saturating_duration_since ( last) >= self . config . event_process_min_spacing
227+ } )
222228 . unwrap_or ( true )
223229 }
224230
@@ -249,7 +255,11 @@ impl RuntimeMemoryLogController {
249255 event : Option < & RuntimeMemoryLogEvent > ,
250256 ) -> RuntimeMemoryLogSampling {
251257 let mut pending_categories = pending_categories ( & self . pending_events ) ;
252- if let Some ( event) = event && !pending_categories. iter ( ) . any ( |value| value == & event. category ) {
258+ if let Some ( event) = event
259+ && !pending_categories
260+ . iter ( )
261+ . any ( |value| value == & event. category )
262+ {
253263 if pending_categories. len ( ) < MAX_PENDING_CATEGORIES {
254264 pending_categories. push ( event. category . clone ( ) ) ;
255265 }
@@ -275,13 +285,19 @@ impl RuntimeMemoryLogController {
275285
276286 let mut threshold_reasons = Vec :: new ( ) ;
277287 let mut forced = false ;
278- if let Some ( event) = event && event. force_attribution {
288+ if let Some ( event) = event
289+ && event. force_attribution
290+ {
279291 forced = true ;
280292 threshold_reasons. push ( format ! ( "event:{}" , event. category) ) ;
281293 }
282294 if !self . pending_events . is_empty ( ) {
283295 threshold_reasons. push ( "pending_events" . to_string ( ) ) ;
284- if self . pending_events . iter ( ) . any ( |value| value. force_attribution ) {
296+ if self
297+ . pending_events
298+ . iter ( )
299+ . any ( |value| value. force_attribution )
300+ {
285301 forced = true ;
286302 }
287303 }
@@ -370,12 +386,14 @@ pub fn server_logging_config() -> RuntimeMemoryLogConfig {
370386 . or_else ( || legacy_interval_secs. map ( |value| value. saturating_mul ( 3 ) ) )
371387 . filter ( |value| * value >= MIN_ATTRIBUTION_INTERVAL_SECS )
372388 . unwrap_or ( DEFAULT_ATTRIBUTION_INTERVAL_SECS ) ;
373- let attribution_min_spacing_secs = env_u64 ( "JCODE_RUNTIME_MEMORY_LOG_ATTRIBUTION_MIN_SPACING_SECS" )
374- . filter ( |value| * value >= MIN_ATTRIBUTION_MIN_SPACING_SECS )
375- . unwrap_or ( DEFAULT_ATTRIBUTION_MIN_SPACING_SECS ) ;
376- let event_process_min_spacing_secs = env_u64 ( "JCODE_RUNTIME_MEMORY_LOG_EVENT_PROCESS_MIN_SPACING_SECS" )
377- . filter ( |value| * value >= MIN_EVENT_PROCESS_MIN_SPACING_SECS )
378- . unwrap_or ( DEFAULT_EVENT_PROCESS_MIN_SPACING_SECS ) ;
389+ let attribution_min_spacing_secs =
390+ env_u64 ( "JCODE_RUNTIME_MEMORY_LOG_ATTRIBUTION_MIN_SPACING_SECS" )
391+ . filter ( |value| * value >= MIN_ATTRIBUTION_MIN_SPACING_SECS )
392+ . unwrap_or ( DEFAULT_ATTRIBUTION_MIN_SPACING_SECS ) ;
393+ let event_process_min_spacing_secs =
394+ env_u64 ( "JCODE_RUNTIME_MEMORY_LOG_EVENT_PROCESS_MIN_SPACING_SECS" )
395+ . filter ( |value| * value >= MIN_EVENT_PROCESS_MIN_SPACING_SECS )
396+ . unwrap_or ( DEFAULT_EVENT_PROCESS_MIN_SPACING_SECS ) ;
379397 let pss_delta_threshold_bytes = env_u64 ( "JCODE_RUNTIME_MEMORY_LOG_PSS_DELTA_THRESHOLD_MB" )
380398 . unwrap_or ( DEFAULT_PSS_DELTA_THRESHOLD_MB )
381399 . saturating_mul ( 1024 * 1024 ) ;
@@ -401,7 +419,9 @@ pub fn install_event_sink(sender: mpsc::UnboundedSender<RuntimeMemoryLogEvent>)
401419}
402420
403421pub fn emit_event ( event : RuntimeMemoryLogEvent ) {
404- if let Ok ( guard) = event_sink ( ) . lock ( ) && let Some ( sender) = guard. as_ref ( ) {
422+ if let Ok ( guard) = event_sink ( ) . lock ( )
423+ && let Some ( sender) = guard. as_ref ( )
424+ {
405425 let _ = sender. send ( event) ;
406426 }
407427}
@@ -503,7 +523,9 @@ fn bytes_to_mb_string(bytes: u64) -> String {
503523fn server_log_path_for ( now : chrono:: DateTime < Utc > ) -> Result < PathBuf > {
504524 let dir = server_logs_dir ( ) ?;
505525 let date = now. format ( "%Y-%m-%d" ) ;
506- Ok ( dir. join ( format ! ( "{SERVER_LOG_FILE_PREFIX}{date}{SERVER_LOG_FILE_SUFFIX}" ) ) )
526+ Ok ( dir. join ( format ! (
527+ "{SERVER_LOG_FILE_PREFIX}{date}{SERVER_LOG_FILE_SUFFIX}"
528+ ) ) )
507529}
508530
509531fn is_server_log_file ( path : & Path ) -> bool {
@@ -646,21 +668,25 @@ mod tests {
646668 } ,
647669 ) ;
648670 let process = crate :: process_memory:: ProcessMemorySnapshot :: default ( ) ;
649- assert ! ( controller
650- . build_sampling_for_attribution(
651- now + Duration :: from_secs( 10 ) ,
652- & process,
653- Some ( & RuntimeMemoryLogEvent :: new( "turn_completed" , "turn" ) . force_attribution( ) ) ,
654- None ,
655- )
656- . is_none( ) ) ;
657- assert ! ( controller
658- . build_sampling_for_attribution(
659- now + Duration :: from_secs( 31 ) ,
660- & process,
661- Some ( & RuntimeMemoryLogEvent :: new( "turn_completed" , "turn" ) . force_attribution( ) ) ,
662- None ,
663- )
664- . is_some( ) ) ;
671+ assert ! (
672+ controller
673+ . build_sampling_for_attribution(
674+ now + Duration :: from_secs( 10 ) ,
675+ & process,
676+ Some ( & RuntimeMemoryLogEvent :: new( "turn_completed" , "turn" ) . force_attribution( ) ) ,
677+ None ,
678+ )
679+ . is_none( )
680+ ) ;
681+ assert ! (
682+ controller
683+ . build_sampling_for_attribution(
684+ now + Duration :: from_secs( 31 ) ,
685+ & process,
686+ Some ( & RuntimeMemoryLogEvent :: new( "turn_completed" , "turn" ) . force_attribution( ) ) ,
687+ None ,
688+ )
689+ . is_some( )
690+ ) ;
665691 }
666692}
0 commit comments