Skip to content

Commit

Permalink
*: fix a build issue on mac os (tikv#11036)
Browse files Browse the repository at this point in the history
* *: fix a build issue on mac os

Signed-off-by: qupeng <[email protected]>

* trigger dco

Signed-off-by: qupeng <[email protected]>
  • Loading branch information
hicqu authored Oct 13, 2021
1 parent 6d0edd7 commit 8e8d91e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/server/status_server/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#[cfg(test)]
pub use self::test_utils::TEST_PROFILE_MUTEX;

use std::fs::File;
use std::fs::{File, Metadata};
use std::io::Read;
use std::os::linux::fs::MetadataExt;
use std::pin::Pin;
use std::process::Command;
use std::sync::Mutex as StdMutex;
Expand Down Expand Up @@ -242,7 +241,7 @@ pub fn list_heap_profiles() -> Result<Vec<(String, String)>, String> {
if !f.ends_with(HEAP_PROFILE_SUFFIX) {
continue;
}
let ct = item.metadata().map(|x| x.st_ctime() as u64).unwrap();
let ct = item.metadata().map(|x| last_change_epoch(&x)).unwrap();
let dt = DateTime::<Local>::from(UNIX_EPOCH + Duration::from_secs(ct));
profiles.push((f, dt.format("%Y-%m-%d %H:%M:%S").to_string()));
}
Expand Down Expand Up @@ -302,6 +301,17 @@ mod test_utils {
}
}

#[cfg(unix)]
fn last_change_epoch(metadata: &Metadata) -> u64 {
use std::os::unix::fs::MetadataExt;
metadata.ctime() as u64
}

#[cfg(not(unix))]
fn last_change_epoch(metadata: &Metadata) -> u64 {
0
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -313,6 +323,12 @@ mod tests {
use std::time::Duration;
use tokio::runtime;

#[test]
fn test_last_change_epoch() {
let f = tempfile::tempfile().unwrap();
assert!(last_change_epoch(&f.metadata().unwrap()) > 0);
}

#[test]
fn test_extract_thread_name() {
assert_eq!(&extract_thread_name("test-name-1"), "test-name");
Expand Down

0 comments on commit 8e8d91e

Please sign in to comment.