Skip to content

Commit

Permalink
tree: add common md event
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Tenart <[email protected]>
  • Loading branch information
atenart committed Jun 4, 2024
1 parent ef03350 commit 159077a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
11 changes: 11 additions & 0 deletions retis-events/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ use std::fmt;

use crate::{event_section, event_type, *};

#[event_section("md_common")]
pub struct CommonEventMd {
pub retis_version: String,
}

impl EventFmt for CommonEventMd {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
write!(f, "Retis version {}", self.retis_version)
}
}

#[event_type]
#[derive(Default)]
pub struct TaskEvent {
Expand Down
14 changes: 11 additions & 3 deletions retis-events/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ pub enum SectionId {
Ovs = 8,
Nft = 9,
Ct = 10,
MdCommon = 11,
// TODO: use std::mem::variant_count once in stable.
_MAX = 11,
_MAX = 12,
}

impl FromStr for SectionId {
Expand All @@ -210,6 +211,7 @@ impl FromStr for SectionId {
OvsEvent::SECTION_NAME => Ovs,
NftEvent::SECTION_NAME => Nft,
CtEvent::SECTION_NAME => Ct,
CommonEventMd::SECTION_NAME => MdCommon,
x => bail!("Can't construct a SectionId from {}", x),
})
}
Expand All @@ -230,6 +232,7 @@ impl SectionId {
8 => Ovs,
9 => Nft,
10 => Ct,
11 => MdCommon,
x => bail!("Can't construct a SectionId from {}", x),
})
}
Expand All @@ -249,7 +252,8 @@ impl SectionId {
Ovs => 8,
Nft => 9,
Ct => 10,
_MAX => 11,
MdCommon => 11,
_MAX => 12,
}
}

Expand All @@ -267,13 +271,14 @@ impl SectionId {
Ovs => OvsEvent::SECTION_NAME,
Nft => NftEvent::SECTION_NAME,
Ct => CtEvent::SECTION_NAME,
MdCommon => CommonEventMd::SECTION_NAME,
_MAX => "_max",
}
}

/// Is the section a metadata one?
pub fn is_metadata(&self) -> bool {
false
matches!(self, SectionId::MdCommon)
}
}

Expand Down Expand Up @@ -317,6 +322,9 @@ fn event_sections() -> Result<&'static EventSectionMap> {
events.insert(CtEvent::SECTION_NAME.to_string(), |v| {
Ok(Box::new(serde_json::from_value::<CtEvent>(v)?))
});
events.insert(CommonEventMd::SECTION_NAME.to_string(), |v| {
Ok(Box::new(serde_json::from_value::<CommonEventMd>(v)?))
});
Ok(events)
})
}
Expand Down
12 changes: 11 additions & 1 deletion retis/src/collect/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
kernel::Symbol,
probe::kernel::utils::parse_probe,
},
events::Event,
events::*,
process::display::*,
};

Expand Down Expand Up @@ -202,6 +202,16 @@ impl Collectors {
bail!("Retis needs to be run as root when --allow-system-changes is used");
}

// Set common md event.
self.md_event.insert_section(
SectionId::MdCommon,
Box::new(CommonEventMd {
retis_version: option_env!("RELEASE_VERSION")
.unwrap_or("unspec")
.to_string(),
}),
)?;

// Try initializing all collectors.
for name in &collect.args()?.collectors {
let id = SectionId::from_str(name)?;
Expand Down

0 comments on commit 159077a

Please sign in to comment.