Skip to main content

katra_core/
scope.rs

1//! Event scope — which layer of the compatibility stack an event belongs to
2//! (KatraProfiler §5).
3
4use serde::{Deserialize, Serialize};
5
6/// The layer of the stack that produced an event.
7#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum Scope {
10    /// Windows-facing activity (NtReadFile, ReadFile, mappings, waits, ...).
11    WindowsFacing,
12    /// Wine/Proton activity (Windows→Unix transitions, server calls, ...).
13    WineProton,
14    /// Linux activity (syscalls, io_uring, page faults, scheduler, ...).
15    Linux,
16    /// D3D12/vkd3d activity (command lists, barriers, descriptors, PSOs, ...).
17    D3d12Vkd3d,
18    /// Vulkan activity (queue submissions, command buffers, ...).
19    Vulkan,
20    /// GPU activity (timestamps, idle bubbles, utilization).
21    Gpu,
22    /// Katra3D-native activity (graph ops, prefetch, staging, ...).
23    Katra,
24}
25
26impl Scope {
27    /// All scopes, in a stable order (append-only).
28    pub const ALL: [Scope; 7] = [
29        Scope::WindowsFacing,
30        Scope::WineProton,
31        Scope::Linux,
32        Scope::D3d12Vkd3d,
33        Scope::Vulkan,
34        Scope::Gpu,
35        Scope::Katra,
36    ];
37
38    /// Stable string name.
39    pub const fn as_str(self) -> &'static str {
40        match self {
41            Scope::WindowsFacing => "windows_facing",
42            Scope::WineProton => "wine_proton",
43            Scope::Linux => "linux",
44            Scope::D3d12Vkd3d => "d3d12_vkd3d",
45            Scope::Vulkan => "vulkan",
46            Scope::Gpu => "gpu",
47            Scope::Katra => "katra",
48        }
49    }
50}
51
52impl std::fmt::Display for Scope {
53    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54        f.write_str(self.as_str())
55    }
56}