Skip to content

Commit ed52b58

Browse files
committed
feat(profiler): Use human readable date/time
1 parent fdf33b4 commit ed52b58

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

crates/profiler/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ use std::sync::Arc;
99
use std::thread;
1010
use std::time::{Duration, SystemTime};
1111

12+
use chrono::{DateTime, Utc};
1213
use pprof::protos::Message;
1314

1415
mod error;
1516
pub use error::ProfilerError;
1617

18+
// Time to wait before starting profiling (in seconds)
19+
const WAIT_TIME: u64 = 10;
20+
1721
/// Save a flamegraph to the specified path
1822
fn save_flamegraph(
1923
report: &pprof::Report,
@@ -63,12 +67,14 @@ fn generate_filename(
6367
extension: &str,
6468
counter: u64,
6569
) -> Result<PathBuf, ProfilerError> {
66-
let timestamp = SystemTime::now()
67-
.duration_since(SystemTime::UNIX_EPOCH)?
68-
.as_secs()
69-
.to_string();
70+
// Convert SystemTime to DateTime<Utc>
71+
let system_time = SystemTime::now();
72+
let datetime: DateTime<Utc> = system_time.into();
73+
74+
// Format the datetime (YYYY-MM-DD-HH_MM_SS)
75+
let formatted_time = datetime.format("%Y-%m-%d-%H_%M_%S").to_string();
7076

71-
let filename = format!("{}-{}-{}.{}", prefix, timestamp, counter, extension);
77+
let filename = format!("{}-{}-{}.{}", prefix, formatted_time, counter, extension);
7278
Ok(Path::new(base_path).join(filename))
7379
}
7480

@@ -118,7 +124,7 @@ fn setup(path: String, frequency: i32, interval: u64, name: String) -> Result<()
118124
let path_clone = path.clone();
119125
thread::spawn(move || {
120126
// Wait a bit for the application to start
121-
thread::sleep(Duration::from_secs(10));
127+
thread::sleep(Duration::from_secs(WAIT_TIME));
122128
tracing::info!("🔍 Starting continuous profiling...");
123129

124130
// Counter for tracking report generation

0 commit comments

Comments
 (0)