build: Add optional dhat heap profiling

Add new "dhat-heap" build feature which enables dhat heap profiling.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2023-01-17 12:53:55 +00:00
parent e2886a4b1f
commit 3a81f9328f
3 changed files with 204 additions and 60 deletions

View File

@@ -23,6 +23,10 @@ use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::signal::block_signal;
use vmm_sys_util::terminal::Terminal;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[derive(Error, Debug)]
enum Error {
#[error("Failed to create API EventFd: {0}")]
@@ -557,6 +561,9 @@ fn start_vmm(toplevel: TopLevel) -> Result<Option<String>, Error> {
}
fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
// Ensure all created files (.e.g sockets) are only accessible by this user
// SAFETY: trivially safe
let _ = unsafe { libc::umask(0o077) };
@@ -587,6 +594,9 @@ fn main() {
std::io::stdin().lock().set_canon_mode().unwrap();
}
#[cfg(feature = "dhat-heap")]
drop(_profiler);
std::process::exit(exit_code);
}