use cfg_if! and use FileSerializationSink for wasi
This commit is contained in:
parent
6fb524a455
commit
f72de476b7
1 changed files with 55 additions and 37 deletions
|
@ -97,14 +97,27 @@ use std::time::{Duration, Instant};
|
||||||
use measureme::{EventId, EventIdBuilder, SerializableString, StringId};
|
use measureme::{EventId, EventIdBuilder, SerializableString, StringId};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
/// MmapSerializatioSink is faster on macOS and Linux
|
cfg_if! {
|
||||||
/// but FileSerializationSink is faster on Windows
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
#[cfg(all(not(windows), not(target_arch = "wasm32")))]
|
cfg_if! {
|
||||||
type SerializationSink = measureme::MmapSerializationSink;
|
if #[cfg(target_os = "wasi")] {
|
||||||
#[cfg(all(windows, not(target_arch = "wasm32")))]
|
type SerializationSink = measureme::FileSerializationSink;
|
||||||
type SerializationSink = measureme::FileSerializationSink;
|
} else {
|
||||||
#[cfg(target_arch = "wasm32")]
|
type SerializationSink = measureme::ByteVecSink;
|
||||||
type SerializationSink = measureme::ByteVecSink;
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(windows)] {
|
||||||
|
/// FileSerializationSink is faster on Windows
|
||||||
|
type SerializationSink = measureme::FileSerializationSink;
|
||||||
|
} else {
|
||||||
|
/// MmapSerializatioSink is faster on macOS and Linux
|
||||||
|
type SerializationSink = measureme::MmapSerializationSink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Profiler = measureme::Profiler<SerializationSink>;
|
type Profiler = measureme::Profiler<SerializationSink>;
|
||||||
|
|
||||||
|
@ -604,36 +617,41 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Memory reporting
|
// Memory reporting
|
||||||
#[cfg(all(unix, not(target_arch = "wasm32")))]
|
cfg_if! {
|
||||||
fn get_resident() -> Option<usize> {
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
let field = 1;
|
fn get_resident() -> Option<usize> {
|
||||||
let contents = fs::read("/proc/self/statm").ok()?;
|
None
|
||||||
let contents = String::from_utf8(contents).ok()?;
|
}
|
||||||
let s = contents.split_whitespace().nth(field)?;
|
} else {
|
||||||
let npages = s.parse::<usize>().ok()?;
|
cfg_if! {
|
||||||
Some(npages * 4096)
|
if #[cfg(windows)] {
|
||||||
}
|
fn get_resident() -> Option<usize> {
|
||||||
|
use std::mem::{self, MaybeUninit};
|
||||||
|
use winapi::shared::minwindef::DWORD;
|
||||||
|
use winapi::um::processthreadsapi::GetCurrentProcess;
|
||||||
|
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
|
||||||
|
|
||||||
#[cfg(all(windows, not(target_arch = "wasm32")))]
|
let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
|
||||||
fn get_resident() -> Option<usize> {
|
match unsafe {
|
||||||
use std::mem::{self, MaybeUninit};
|
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
|
||||||
use winapi::shared::minwindef::DWORD;
|
} {
|
||||||
use winapi::um::processthreadsapi::GetCurrentProcess;
|
0 => None,
|
||||||
use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
|
_ => {
|
||||||
|
let pmc = unsafe { pmc.assume_init() };
|
||||||
let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
|
Some(pmc.WorkingSetSize as usize)
|
||||||
match unsafe {
|
}
|
||||||
GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
|
}
|
||||||
} {
|
}
|
||||||
0 => None,
|
} else {
|
||||||
_ => {
|
fn get_resident() -> Option<usize> {
|
||||||
let pmc = unsafe { pmc.assume_init() };
|
let field = 1;
|
||||||
Some(pmc.WorkingSetSize as usize)
|
let contents = fs::read("/proc/self/statm").ok()?;
|
||||||
|
let contents = String::from_utf8(contents).ok()?;
|
||||||
|
let s = contents.split_whitespace().nth(field)?;
|
||||||
|
let npages = s.parse::<usize>().ok()?;
|
||||||
|
Some(npages * 4096)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn get_resident() -> Option<usize> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue