perf_event_data/records/
cgroup.rs1use std::borrow::Cow;
2use std::fmt;
3
4use crate::prelude::*;
5
6#[derive(Clone)]
13pub struct CGroup<'a> {
14 pub id: u64,
16
17 pub path: Cow<'a, [u8]>,
19}
20
21impl<'a> CGroup<'a> {
22 #[cfg(unix)]
24 pub fn path_os(&self) -> &std::path::Path {
25 use std::ffi::OsStr;
26 use std::os::unix::ffi::OsStrExt;
27 use std::path::Path;
28
29 Path::new(OsStr::from_bytes(&self.path))
30 }
31
32 pub fn into_owned(self) -> CGroup<'static> {
34 CGroup {
35 path: self.path.into_owned().into(),
36 ..self
37 }
38 }
39}
40
41impl<'p> Parse<'p> for CGroup<'p> {
42 fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
43 where
44 E: Endian,
45 B: ParseBuf<'p>,
46 {
47 Ok(Self {
48 id: p.parse()?,
49 path: p.parse_rest_trim_nul()?,
50 })
51 }
52}
53
54impl fmt::Debug for CGroup<'_> {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.debug_struct("CGroup")
57 .field("id", &self.id)
58 .field("path", &crate::util::fmt::ByteStr(&self.path))
59 .finish()
60 }
61}