1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! An in-process stack sampler for Windows x64, a rolling stall recorder, processor placement
//! readings, and an MSVC `/MAP` symbolizer.
//!
//! [`Sampler`] runs one thread that pauses the matching threads of the calling process a
//! thousand times a second (by default), copies their stacks, resumes them, and unwinds the
//! copies with the x64 unwind data the images carry. It needs no administrator rights, no ETW
//! session, no PDB files and no debug help library. The result is a [`Profile`]: folded stacks
//! with module-relative addresses, which [`symbolize()`] (or the `mapsample` command) names
//! from the linker map of the same build, on any host.
//!
//! The last few seconds are always kept in a [`Ring`], so a stall can be written out after the
//! fact with [`Sampler::dump_recent`] or a [`DumpHandle`] from a watchdog thread. On Windows 11
//! the sampler can also record which logical processor each thread ran on
//! ([`PlacementMode`]), to see efficiency-core time, migrations and hyperthread sharing.
//!
//! ```no_run
//! use mapsample::{Config, Sampler};
//! use std::path::Path;
//!
//! let config = Config::parse("worker,render:1000")?;
//! let sampler = Sampler::start(config)?;
//! // ... run the workload ...
//! let profile = sampler.stop()?;
//! profile.write_to(Path::new("."))?; // samples.folded, samples.txt, samples.modules.txt
//! # Ok::<(), mapsample::Error>(())
//! ```
//!
//! Everything but [`Sampler::start`] works on every platform; there it returns
//! [`Error::UnsupportedPlatform`] unless the target is Windows on x86-64.
//!
//! # Safety model
//!
//! While a thread is paused the sampler allocates nothing, takes no lock and cannot panic: the
//! paused thread may hold the heap lock or any other. A guard resumes the thread on every
//! path. Unwinding happens after the thread runs again, in safe Rust over the copied stack
//! bytes, so a damaged frame stops the walk instead of reading past the copy. Each module the
//! walk enters is pinned for the rest of the walk and read only through fault-safe copies
//! inside the readable ranges of its own header. Placement APCs only touch a static table of
//! atomics in a module pinned for the life of the process, and a slot is never reused while an
//! APC aimed at it may still run.
pub use ;
pub use Error;
pub use ;
pub use ;
pub use Ring;
pub use ;
pub use ;