diskann_platform/linux/perf.rs
1/*
2 * Copyright (c) Microsoft Corporation.
3 * Licensed under the MIT license.
4 */
5
6use std::{
7 fs::File,
8 io::{self, BufRead},
9 path::Path,
10};
11
12pub fn get_process_cycle_time() -> Option<u64> {
13 Some(0)
14}
15
16// Gets the process time in kernel and user modes.
17pub fn get_process_time() -> Option<u64> {
18 None
19}
20
21// Gets the system time in kernel and user modes.
22pub fn get_system_time() -> Option<u64> {
23 None
24}
25
26// Gets the number of processors.
27pub fn get_number_of_processors() -> Option<u64> {
28 None
29}
30
31/// Retrieves the peak resident set size of the current process.
32///
33/// This function returns the VmHWM field from the /proc/self/status file, which represents the maximum amount of memory that the process has used at any point in time. The resident set size is the portion of a process's memory that is held in RAM.
34/// The VmHWM value might be inaccurate, according to https://manpages.ubuntu.com/manpages/jammy/man5/proc.5.html.
35/// If there are accuracy concerns, consider switching to /proc/[pid]/smaps or /proc/[pid]/smaps_rollup instead, which are much slower but provide accurate, detailed information.
36///
37/// # Arguments
38///
39/// * `process_handle` - An optional process handle. This argument is ignored on Linux.
40///
41/// # Returns
42///
43/// An `Option<u64>` representing the peak working set size in bytes, or `None` if the operation fails or is not supported on the current platform.
44pub fn get_peak_workingset_size() -> Option<u64> {
45 if cfg!(unix) {
46 // Open the file
47 let path = Path::new("/proc/self/status");
48 let file = File::open(path).ok()?;
49 let reader = io::BufReader::new(file);
50
51 // Read the file line by line
52 for line in reader.lines() {
53 let line = line.ok()?;
54 // Look for the VmHWM field
55 if line.starts_with("VmHWM:") {
56 // Split the line into parts
57 let parts: Vec<&str> = line.split_whitespace().collect();
58 if parts.len() >= 2 {
59 // Parse the value as u64
60 if let Ok(value) = parts[1].parse::<u64>() {
61 // Return the value in bytes
62 return Some(value * 1024);
63 }
64 }
65 }
66 }
67 }
68
69 None
70}