aboutsummaryrefslogtreecommitdiff
path: root/crates/profile
diff options
context:
space:
mode:
Diffstat (limited to 'crates/profile')
-rw-r--r--crates/profile/Cargo.toml3
-rw-r--r--crates/profile/src/memory_usage.rs16
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml
index 1a8c8f862..653d3d983 100644
--- a/crates/profile/Cargo.toml
+++ b/crates/profile/Cargo.toml
@@ -20,6 +20,9 @@ jemalloc-ctl = { version = "0.4.1", package = "tikv-jemalloc-ctl", optional = tr
20[target.'cfg(target_os = "linux")'.dependencies] 20[target.'cfg(target_os = "linux")'.dependencies]
21perf-event = "0.4" 21perf-event = "0.4"
22 22
23[target.'cfg(windows)'.dependencies]
24winapi = { version = "0.3.8", features = ["psapi"] }
25
23[features] 26[features]
24cpu_profiler = [] 27cpu_profiler = []
25jemalloc = ["jemalloc-ctl"] 28jemalloc = ["jemalloc-ctl"]
diff --git a/crates/profile/src/memory_usage.rs b/crates/profile/src/memory_usage.rs
index 2917ded60..6ef58c9c1 100644
--- a/crates/profile/src/memory_usage.rs
+++ b/crates/profile/src/memory_usage.rs
@@ -35,6 +35,22 @@ impl MemoryUsage {
35 // Note: This is incredibly slow. 35 // Note: This is incredibly slow.
36 let alloc = unsafe { libc::mallinfo() }.uordblks as isize; 36 let alloc = unsafe { libc::mallinfo() }.uordblks as isize;
37 MemoryUsage { allocated: Bytes(alloc) } 37 MemoryUsage { allocated: Bytes(alloc) }
38 } else if #[cfg(windows)] {
39 // There doesn't seem to be an API for determining heap usage, so we try to
40 // approximate that by using the Commit Charge value.
41
42 use winapi::um::processthreadsapi::*;
43 use winapi::um::psapi::*;
44 use std::mem::{MaybeUninit, size_of};
45
46 let proc = unsafe { GetCurrentProcess() };
47 let mut mem_counters = MaybeUninit::uninit();
48 let cb = size_of::<PROCESS_MEMORY_COUNTERS>();
49 let ret = unsafe { GetProcessMemoryInfo(proc, mem_counters.as_mut_ptr(), cb as u32) };
50 assert!(ret != 0);
51
52 let usage = unsafe { mem_counters.assume_init().PagefileUsage };
53 MemoryUsage { allocated: Bytes(usage as isize) }
38 } else { 54 } else {
39 MemoryUsage { allocated: Bytes(0) } 55 MemoryUsage { allocated: Bytes(0) }
40 } 56 }