Unverified Commit 0802ecd9 authored by Yan Ru Pei's avatar Yan Ru Pei Committed by GitHub
Browse files

feat: recorder graceful drop (#2327)

parent 8291172f
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::io; use std::io;
...@@ -386,6 +374,12 @@ where ...@@ -386,6 +374,12 @@ where
} }
} }
impl<T> Drop for Recorder<T> {
fn drop(&mut self) {
self.cancel.cancel();
}
}
/// Helper function to create a rotated file path with an index suffix /// Helper function to create a rotated file path with an index suffix
fn create_rotated_path(base_path: &Path, index: usize) -> PathBuf { fn create_rotated_path(base_path: &Path, index: usize) -> PathBuf {
let path_str = base_path.to_string_lossy(); let path_str = base_path.to_string_lossy();
...@@ -471,11 +465,11 @@ mod tests { ...@@ -471,11 +465,11 @@ mod tests {
// Check that both events were recorded // Check that both events were recorded
assert_eq!(recorder.event_count().await, 2); assert_eq!(recorder.event_count().await, 2);
// Check that the elapsed time is between 9 and 11 milliseconds // Check that the elapsed time is between 7 and 13 milliseconds
let elapsed_ms = recorder.elapsed_time().await.unwrap().as_millis(); let elapsed_ms = recorder.elapsed_time().await.unwrap().as_millis();
if !(9..=11).contains(&elapsed_ms) { if !(7..=13).contains(&elapsed_ms) {
println!("Actual elapsed time: {} ms", elapsed_ms); println!("Actual elapsed time: {} ms", elapsed_ms);
assert!((9..=11).contains(&elapsed_ms)); assert!((7..=13).contains(&elapsed_ms));
} }
// Force shutdown to flush file // Force shutdown to flush file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment