1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_memory_sampler_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct SamplerMarker;
16
17impl fidl::endpoints::ProtocolMarker for SamplerMarker {
18 type Proxy = SamplerProxy;
19 type RequestStream = SamplerRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = SamplerSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.memory.sampler.Sampler";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for SamplerMarker {}
26
27pub trait SamplerProxyInterface: Send + Sync {
28 fn r#record_allocation(
29 &self,
30 address: u64,
31 stack_trace: &StackTrace,
32 size: u64,
33 ) -> Result<(), fidl::Error>;
34 fn r#record_deallocation(
35 &self,
36 address: u64,
37 stack_trace: &StackTrace,
38 ) -> Result<(), fidl::Error>;
39 fn r#set_process_info(&self, payload: &SamplerSetProcessInfoRequest)
40 -> Result<(), fidl::Error>;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct SamplerSynchronousProxy {
45 client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for SamplerSynchronousProxy {
50 type Proxy = SamplerProxy;
51 type Protocol = SamplerMarker;
52
53 fn from_channel(inner: fidl::Channel) -> Self {
54 Self::new(inner)
55 }
56
57 fn into_channel(self) -> fidl::Channel {
58 self.client.into_channel()
59 }
60
61 fn as_channel(&self) -> &fidl::Channel {
62 self.client.as_channel()
63 }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl SamplerSynchronousProxy {
68 pub fn new(channel: fidl::Channel) -> Self {
69 let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71 }
72
73 pub fn into_channel(self) -> fidl::Channel {
74 self.client.into_channel()
75 }
76
77 pub fn wait_for_event(
80 &self,
81 deadline: zx::MonotonicInstant,
82 ) -> Result<SamplerEvent, fidl::Error> {
83 SamplerEvent::decode(self.client.wait_for_event(deadline)?)
84 }
85
86 pub fn r#record_allocation(
88 &self,
89 mut address: u64,
90 mut stack_trace: &StackTrace,
91 mut size: u64,
92 ) -> Result<(), fidl::Error> {
93 self.client.send::<SamplerRecordAllocationRequest>(
94 (address, stack_trace, size),
95 0x6b0add9f7769824d,
96 fidl::encoding::DynamicFlags::empty(),
97 )
98 }
99
100 pub fn r#record_deallocation(
102 &self,
103 mut address: u64,
104 mut stack_trace: &StackTrace,
105 ) -> Result<(), fidl::Error> {
106 self.client.send::<SamplerRecordDeallocationRequest>(
107 (address, stack_trace),
108 0x503bff5ec34dbeeb,
109 fidl::encoding::DynamicFlags::empty(),
110 )
111 }
112
113 pub fn r#set_process_info(
120 &self,
121 mut payload: &SamplerSetProcessInfoRequest,
122 ) -> Result<(), fidl::Error> {
123 self.client.send::<SamplerSetProcessInfoRequest>(
124 payload,
125 0x68a0557106e51783,
126 fidl::encoding::DynamicFlags::empty(),
127 )
128 }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<SamplerSynchronousProxy> for zx::Handle {
133 fn from(value: SamplerSynchronousProxy) -> Self {
134 value.into_channel().into()
135 }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl From<fidl::Channel> for SamplerSynchronousProxy {
140 fn from(value: fidl::Channel) -> Self {
141 Self::new(value)
142 }
143}
144
145#[derive(Debug, Clone)]
146pub struct SamplerProxy {
147 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
148}
149
150impl fidl::endpoints::Proxy for SamplerProxy {
151 type Protocol = SamplerMarker;
152
153 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
154 Self::new(inner)
155 }
156
157 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
158 self.client.into_channel().map_err(|client| Self { client })
159 }
160
161 fn as_channel(&self) -> &::fidl::AsyncChannel {
162 self.client.as_channel()
163 }
164}
165
166impl SamplerProxy {
167 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
169 let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
170 Self { client: fidl::client::Client::new(channel, protocol_name) }
171 }
172
173 pub fn take_event_stream(&self) -> SamplerEventStream {
179 SamplerEventStream { event_receiver: self.client.take_event_receiver() }
180 }
181
182 pub fn r#record_allocation(
184 &self,
185 mut address: u64,
186 mut stack_trace: &StackTrace,
187 mut size: u64,
188 ) -> Result<(), fidl::Error> {
189 SamplerProxyInterface::r#record_allocation(self, address, stack_trace, size)
190 }
191
192 pub fn r#record_deallocation(
194 &self,
195 mut address: u64,
196 mut stack_trace: &StackTrace,
197 ) -> Result<(), fidl::Error> {
198 SamplerProxyInterface::r#record_deallocation(self, address, stack_trace)
199 }
200
201 pub fn r#set_process_info(
208 &self,
209 mut payload: &SamplerSetProcessInfoRequest,
210 ) -> Result<(), fidl::Error> {
211 SamplerProxyInterface::r#set_process_info(self, payload)
212 }
213}
214
215impl SamplerProxyInterface for SamplerProxy {
216 fn r#record_allocation(
217 &self,
218 mut address: u64,
219 mut stack_trace: &StackTrace,
220 mut size: u64,
221 ) -> Result<(), fidl::Error> {
222 self.client.send::<SamplerRecordAllocationRequest>(
223 (address, stack_trace, size),
224 0x6b0add9f7769824d,
225 fidl::encoding::DynamicFlags::empty(),
226 )
227 }
228
229 fn r#record_deallocation(
230 &self,
231 mut address: u64,
232 mut stack_trace: &StackTrace,
233 ) -> Result<(), fidl::Error> {
234 self.client.send::<SamplerRecordDeallocationRequest>(
235 (address, stack_trace),
236 0x503bff5ec34dbeeb,
237 fidl::encoding::DynamicFlags::empty(),
238 )
239 }
240
241 fn r#set_process_info(
242 &self,
243 mut payload: &SamplerSetProcessInfoRequest,
244 ) -> Result<(), fidl::Error> {
245 self.client.send::<SamplerSetProcessInfoRequest>(
246 payload,
247 0x68a0557106e51783,
248 fidl::encoding::DynamicFlags::empty(),
249 )
250 }
251}
252
253pub struct SamplerEventStream {
254 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
255}
256
257impl std::marker::Unpin for SamplerEventStream {}
258
259impl futures::stream::FusedStream for SamplerEventStream {
260 fn is_terminated(&self) -> bool {
261 self.event_receiver.is_terminated()
262 }
263}
264
265impl futures::Stream for SamplerEventStream {
266 type Item = Result<SamplerEvent, fidl::Error>;
267
268 fn poll_next(
269 mut self: std::pin::Pin<&mut Self>,
270 cx: &mut std::task::Context<'_>,
271 ) -> std::task::Poll<Option<Self::Item>> {
272 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
273 &mut self.event_receiver,
274 cx
275 )?) {
276 Some(buf) => std::task::Poll::Ready(Some(SamplerEvent::decode(buf))),
277 None => std::task::Poll::Ready(None),
278 }
279 }
280}
281
282#[derive(Debug)]
283pub enum SamplerEvent {}
284
285impl SamplerEvent {
286 fn decode(
288 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
289 ) -> Result<SamplerEvent, fidl::Error> {
290 let (bytes, _handles) = buf.split_mut();
291 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
292 debug_assert_eq!(tx_header.tx_id, 0);
293 match tx_header.ordinal {
294 _ => Err(fidl::Error::UnknownOrdinal {
295 ordinal: tx_header.ordinal,
296 protocol_name: <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
297 }),
298 }
299 }
300}
301
302pub struct SamplerRequestStream {
304 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
305 is_terminated: bool,
306}
307
308impl std::marker::Unpin for SamplerRequestStream {}
309
310impl futures::stream::FusedStream for SamplerRequestStream {
311 fn is_terminated(&self) -> bool {
312 self.is_terminated
313 }
314}
315
316impl fidl::endpoints::RequestStream for SamplerRequestStream {
317 type Protocol = SamplerMarker;
318 type ControlHandle = SamplerControlHandle;
319
320 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
321 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
322 }
323
324 fn control_handle(&self) -> Self::ControlHandle {
325 SamplerControlHandle { inner: self.inner.clone() }
326 }
327
328 fn into_inner(
329 self,
330 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
331 {
332 (self.inner, self.is_terminated)
333 }
334
335 fn from_inner(
336 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
337 is_terminated: bool,
338 ) -> Self {
339 Self { inner, is_terminated }
340 }
341}
342
343impl futures::Stream for SamplerRequestStream {
344 type Item = Result<SamplerRequest, fidl::Error>;
345
346 fn poll_next(
347 mut self: std::pin::Pin<&mut Self>,
348 cx: &mut std::task::Context<'_>,
349 ) -> std::task::Poll<Option<Self::Item>> {
350 let this = &mut *self;
351 if this.inner.check_shutdown(cx) {
352 this.is_terminated = true;
353 return std::task::Poll::Ready(None);
354 }
355 if this.is_terminated {
356 panic!("polled SamplerRequestStream after completion");
357 }
358 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
359 |bytes, handles| {
360 match this.inner.channel().read_etc(cx, bytes, handles) {
361 std::task::Poll::Ready(Ok(())) => {}
362 std::task::Poll::Pending => return std::task::Poll::Pending,
363 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
364 this.is_terminated = true;
365 return std::task::Poll::Ready(None);
366 }
367 std::task::Poll::Ready(Err(e)) => {
368 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
369 e.into(),
370 ))))
371 }
372 }
373
374 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
376
377 std::task::Poll::Ready(Some(match header.ordinal {
378 0x6b0add9f7769824d => {
379 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
380 let mut req = fidl::new_empty!(
381 SamplerRecordAllocationRequest,
382 fidl::encoding::DefaultFuchsiaResourceDialect
383 );
384 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordAllocationRequest>(&header, _body_bytes, handles, &mut req)?;
385 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
386 Ok(SamplerRequest::RecordAllocation {
387 address: req.address,
388 stack_trace: req.stack_trace,
389 size: req.size,
390
391 control_handle,
392 })
393 }
394 0x503bff5ec34dbeeb => {
395 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
396 let mut req = fidl::new_empty!(
397 SamplerRecordDeallocationRequest,
398 fidl::encoding::DefaultFuchsiaResourceDialect
399 );
400 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordDeallocationRequest>(&header, _body_bytes, handles, &mut req)?;
401 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
402 Ok(SamplerRequest::RecordDeallocation {
403 address: req.address,
404 stack_trace: req.stack_trace,
405
406 control_handle,
407 })
408 }
409 0x68a0557106e51783 => {
410 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
411 let mut req = fidl::new_empty!(
412 SamplerSetProcessInfoRequest,
413 fidl::encoding::DefaultFuchsiaResourceDialect
414 );
415 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerSetProcessInfoRequest>(&header, _body_bytes, handles, &mut req)?;
416 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
417 Ok(SamplerRequest::SetProcessInfo { payload: req, control_handle })
418 }
419 _ => Err(fidl::Error::UnknownOrdinal {
420 ordinal: header.ordinal,
421 protocol_name:
422 <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
423 }),
424 }))
425 },
426 )
427 }
428}
429
430#[derive(Debug)]
432pub enum SamplerRequest {
433 RecordAllocation {
435 address: u64,
436 stack_trace: StackTrace,
437 size: u64,
438 control_handle: SamplerControlHandle,
439 },
440 RecordDeallocation {
442 address: u64,
443 stack_trace: StackTrace,
444 control_handle: SamplerControlHandle,
445 },
446 SetProcessInfo { payload: SamplerSetProcessInfoRequest, control_handle: SamplerControlHandle },
453}
454
455impl SamplerRequest {
456 #[allow(irrefutable_let_patterns)]
457 pub fn into_record_allocation(self) -> Option<(u64, StackTrace, u64, SamplerControlHandle)> {
458 if let SamplerRequest::RecordAllocation { address, stack_trace, size, control_handle } =
459 self
460 {
461 Some((address, stack_trace, size, control_handle))
462 } else {
463 None
464 }
465 }
466
467 #[allow(irrefutable_let_patterns)]
468 pub fn into_record_deallocation(self) -> Option<(u64, StackTrace, SamplerControlHandle)> {
469 if let SamplerRequest::RecordDeallocation { address, stack_trace, control_handle } = self {
470 Some((address, stack_trace, control_handle))
471 } else {
472 None
473 }
474 }
475
476 #[allow(irrefutable_let_patterns)]
477 pub fn into_set_process_info(
478 self,
479 ) -> Option<(SamplerSetProcessInfoRequest, SamplerControlHandle)> {
480 if let SamplerRequest::SetProcessInfo { payload, control_handle } = self {
481 Some((payload, control_handle))
482 } else {
483 None
484 }
485 }
486
487 pub fn method_name(&self) -> &'static str {
489 match *self {
490 SamplerRequest::RecordAllocation { .. } => "record_allocation",
491 SamplerRequest::RecordDeallocation { .. } => "record_deallocation",
492 SamplerRequest::SetProcessInfo { .. } => "set_process_info",
493 }
494 }
495}
496
497#[derive(Debug, Clone)]
498pub struct SamplerControlHandle {
499 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
500}
501
502impl fidl::endpoints::ControlHandle for SamplerControlHandle {
503 fn shutdown(&self) {
504 self.inner.shutdown()
505 }
506 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
507 self.inner.shutdown_with_epitaph(status)
508 }
509
510 fn is_closed(&self) -> bool {
511 self.inner.channel().is_closed()
512 }
513 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
514 self.inner.channel().on_closed()
515 }
516
517 #[cfg(target_os = "fuchsia")]
518 fn signal_peer(
519 &self,
520 clear_mask: zx::Signals,
521 set_mask: zx::Signals,
522 ) -> Result<(), zx_status::Status> {
523 use fidl::Peered;
524 self.inner.channel().signal_peer(clear_mask, set_mask)
525 }
526}
527
528impl SamplerControlHandle {}
529
530mod internal {
531 use super::*;
532}