relay_event_schema/protocol/contexts/
chromium_stability_report.rs1use relay_protocol::{Annotated, Array, Empty, FromValue, IntoValue};
2
3use crate::processor::ProcessValue;
4
5fn bytes_from_4k_pages(value: u32) -> u64 {
7 (value as u64) * 4096
8}
9
10#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
12pub struct ProcessStateContext {
13 pub process_id: Annotated<u64>,
15 pub memory_state: Annotated<process_state::MemoryStateContext>,
17 pub file_system_state: Annotated<process_state::FileSystemStateContext>,
19}
20
21pub mod process_state {
23 use super::*;
24
25 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
28 pub struct MemoryStateContext {
29 pub windows_memory: Annotated<memory_state::WindowsMemoryContext>,
30 }
31 pub mod memory_state {
33 use super::*;
34
35 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
36 pub struct WindowsMemoryContext {
37 pub process_private_usage: Annotated<u64>,
39 pub process_peak_workingset_size: Annotated<u64>,
41 pub process_peak_pagefile_usage: Annotated<u64>,
43 pub process_allocation_attempt: Annotated<u64>,
45 }
46 }
47 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
49 pub struct FileSystemStateContext {
50 pub posix_file_system_state: Annotated<file_system_state::PosixFileSystemStateContext>,
52 pub windows_file_system_state: Annotated<file_system_state::WindowsFileSystemStateContext>,
54 }
55 pub mod file_system_state {
57 use super::*;
58
59 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
60 pub struct PosixFileSystemStateContext {
61 pub open_file_descriptors: Annotated<u64>,
63 }
64 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
65 pub struct WindowsFileSystemStateContext {
66 pub process_handle_count: Annotated<u64>,
68 }
69 }
70}
71#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
73pub struct SystemMemoryStateContext {
74 pub windows_memory: Annotated<system_memory_state::WindowsMemoryContext>,
75}
76pub mod system_memory_state {
78 use super::*;
79
80 #[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
81
82 pub struct WindowsMemoryContext {
83 pub system_commit_limit: Annotated<u64>,
85 pub system_commit_remaining: Annotated<u64>,
87 pub system_handle_count: Annotated<u64>,
89 }
90}
91
92#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
97pub struct StabilityReportContext {
98 pub process_states: Annotated<Array<ProcessStateContext>>,
100 pub system_memory_state: Annotated<SystemMemoryStateContext>,
102}
103
104impl super::DefaultContext for StabilityReportContext {
105 fn default_key() -> &'static str {
106 "chromium_stability_report"
107 }
108
109 fn from_context(context: super::Context) -> Option<Self> {
110 match context {
111 super::Context::ChromiumStabilityReport(c) => Some(*c),
112 _ => None,
113 }
114 }
115
116 fn cast(context: &super::Context) -> Option<&Self> {
117 match context {
118 super::Context::ChromiumStabilityReport(c) => Some(c),
119 _ => None,
120 }
121 }
122
123 fn cast_mut(context: &mut super::Context) -> Option<&mut Self> {
124 match context {
125 super::Context::ChromiumStabilityReport(c) => Some(c),
126 _ => None,
127 }
128 }
129
130 fn into_context(self) -> super::Context {
131 super::Context::ChromiumStabilityReport(Box::new(self))
132 }
133}
134
135impl From<minidump::StabilityReport> for StabilityReportContext {
137 fn from(report: minidump::StabilityReport) -> Self {
138 Self {
139 process_states: Annotated::from(
140 report
141 .process_states
142 .into_iter()
143 .map(|ps| Annotated::from(ProcessStateContext::from(ps)))
144 .collect::<Vec<_>>(),
145 ),
146 system_memory_state: report.system_memory_state.map(Into::into).into(),
147 }
148 }
149}
150
151impl From<minidump::ProcessState> for ProcessStateContext {
152 fn from(state: minidump::ProcessState) -> Self {
153 Self {
154 process_id: state.process_id.map(|id| id as u64).into(),
155 memory_state: state.memory_state.map(Into::into).into(),
156 file_system_state: state.file_system_state.map(Into::into).into(),
157 }
158 }
159}
160
161impl From<minidump::SystemMemoryState> for SystemMemoryStateContext {
162 fn from(state: minidump::SystemMemoryState) -> Self {
163 Self {
164 windows_memory: state.windows_memory.map(Into::into).into(),
165 }
166 }
167}
168
169impl From<minidump::system_memory_state::WindowsMemory>
170 for system_memory_state::WindowsMemoryContext
171{
172 fn from(memory: minidump::system_memory_state::WindowsMemory) -> Self {
173 Self {
174 system_commit_limit: memory.system_commit_limit.map(bytes_from_4k_pages).into(),
175 system_commit_remaining: memory
176 .system_commit_remaining
177 .map(bytes_from_4k_pages)
178 .into(),
179 system_handle_count: memory.system_handle_count.map(|v| v as u64).into(),
180 }
181 }
182}
183
184impl From<minidump::process_state::MemoryState> for process_state::MemoryStateContext {
185 fn from(state: minidump::process_state::MemoryState) -> Self {
186 Self {
187 windows_memory: state.windows_memory.map(Into::into).into(),
188 }
189 }
190}
191
192impl From<minidump::process_state::memory_state::WindowsMemory>
193 for process_state::memory_state::WindowsMemoryContext
194{
195 fn from(memory: minidump::process_state::memory_state::WindowsMemory) -> Self {
196 Self {
197 process_private_usage: memory.process_private_usage.map(bytes_from_4k_pages).into(),
198 process_peak_workingset_size: memory
199 .process_peak_workingset_size
200 .map(bytes_from_4k_pages)
201 .into(),
202 process_peak_pagefile_usage: memory
203 .process_peak_pagefile_usage
204 .map(bytes_from_4k_pages)
205 .into(),
206 process_allocation_attempt: memory.process_allocation_attempt.map(|v| v as u64).into(),
207 }
208 }
209}
210
211impl From<minidump::process_state::FileSystemState> for process_state::FileSystemStateContext {
212 fn from(state: minidump::process_state::FileSystemState) -> Self {
213 Self {
214 posix_file_system_state: state.posix_file_system_state.map(Into::into).into(),
215 windows_file_system_state: state.windows_file_system_state.map(Into::into).into(),
216 }
217 }
218}
219
220impl From<minidump::process_state::file_system_state::PosixFileSystemState>
221 for process_state::file_system_state::PosixFileSystemStateContext
222{
223 fn from(state: minidump::process_state::file_system_state::PosixFileSystemState) -> Self {
224 Self {
225 open_file_descriptors: state.open_file_descriptors.map(|v| v as u64).into(),
226 }
227 }
228}
229
230impl From<minidump::process_state::file_system_state::WindowsFileSystemState>
231 for process_state::file_system_state::WindowsFileSystemStateContext
232{
233 fn from(state: minidump::process_state::file_system_state::WindowsFileSystemState) -> Self {
234 Self {
235 process_handle_count: state.process_handle_count.map(|v| v as u64).into(),
236 }
237 }
238}