Merge night/cpu: a sampling profiler

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 03:23:59 -06:00
commit f76060a65d
7 files changed
+241 -8

No files matched your search

+18
View File
@@ -1009,6 +1009,7 @@ pub(crate) fn recorded(started: std::time::Instant) {
/// submission lock).
pub(crate) fn submission_begins() {
let now = now_us();
INSIDE.fetch_add(1, Relaxed);
if !SUBMITTED_SINCE.load(Relaxed) && !SUBMITTED_SINCE.swap(true, Relaxed) {
add(C::UntilSubmitUs, now.saturating_sub(PRESENTED_AT.load(Relaxed)));
}
@@ -1029,6 +1030,7 @@ pub(crate) fn submission_begins() {
/// submission lock.
pub(crate) fn submission_ends(lock: u64) {
let now = now_us();
INSIDE.fetch_sub(1, Relaxed);
SUBMITTED_AT.store(now, Relaxed);
let (user, kernel) = thread_times();
let (u, k) = ENTERED.with(|e| e.get());
@@ -1042,6 +1044,22 @@ pub(crate) fn submission_ends(lock: u64) {
s.inside_kernel += kernel.saturating_sub(k);
}
/// The submissions being prepared now.
static INSIDE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
/// What the frame is at, for the sampling profiler (`VICTORY_PROFILE`): 3
/// in a submission, else 0 after a present until the first list call, 1 until
/// the first submission, 2 behind it.
pub(crate) fn phase() -> u32 {
if INSIDE.load(Relaxed) > 0 {
3
} else if SUBMITTED_SINCE.load(Relaxed) {
2
} else {
u32::from(RECORDED_SINCE.load(Relaxed))
}
}
/// The title calls its present (before our own copy to the window runs).
pub(crate) fn present_begins() {
add(C::TailUs, now_us().saturating_sub(SUBMITTED_AT.load(Relaxed)));
+6
View File
@@ -73,6 +73,12 @@ mod watch;
#[cfg(windows)]
pub use host::on_failure;
/// What the frame is at (`copystat::phase`), for the sampling profiler.
#[cfg(all(windows, feature = "diagnostics"))]
pub fn frame_phase() -> u32 {
copystat::phase()
}
#[cfg(windows)]
pub use inplace::{title_memory_freeing, title_memory_section, title_memory_section_gone, title_memory_view};
#[cfg(windows)]