Skip to content

Commit

Permalink
tree: make DisplayFormat a ref in event_fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Tenart <[email protected]>
  • Loading branch information
atenart committed Jun 26, 2024
1 parent 98d0154 commit e1fed23
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions retis-events/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct CommonEventMd {
}

impl EventFmt for CommonEventMd {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(f, "Retis version {}", self.retis_version)
}
}
Expand All @@ -39,7 +39,7 @@ pub struct CommonEvent {
}

impl EventFmt for CommonEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result {
match format.time_format {
TimeFormat::MonotonicTimestamp => write!(f, "{}", self.timestamp)?,
TimeFormat::UtcDate => match format.monotonic_offset {
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/ct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct CtEvent {
}

impl EventFmt for CtEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
use CtState::*;
match self.state {
Established => write!(f, "ct_state ESTABLISHED ")?,
Expand Down
10 changes: 5 additions & 5 deletions retis-events/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl DisplayFormat {
/// arguments, unlike a plain std::fmt::Display implementation.
pub trait EventDisplay<'a>: EventFmt {
/// Display the event using the default event format.
fn display(&'a self, format: DisplayFormat) -> Box<dyn fmt::Display + 'a>;
fn display(&'a self, format: &'a DisplayFormat) -> Box<dyn fmt::Display + 'a>;
}

/// Trait controlling how an event or an event section (or any custom type
Expand All @@ -64,17 +64,17 @@ pub trait EventDisplay<'a>: EventFmt {
/// members if any.
pub trait EventFmt {
/// Default formatting of an event.
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result;
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result;
}

impl<'a, T> EventDisplay<'a> for T
where
T: EventFmt,
{
fn display(&'a self, format: DisplayFormat) -> Box<dyn fmt::Display + 'a> {
fn display(&'a self, format: &'a DisplayFormat) -> Box<dyn fmt::Display + 'a> {
struct DefaultDisplay<'a, U> {
myself: &'a U,
format: DisplayFormat,
format: &'a DisplayFormat,
}
impl<U: EventFmt> fmt::Display for DefaultDisplay<'_, U> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -83,7 +83,7 @@ where
}
Box::new(DefaultDisplay {
myself: self,
format,
format: format,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Event {
}

impl EventFmt for Event {
fn event_fmt(&self, f: &mut std::fmt::Formatter, format: DisplayFormat) -> std::fmt::Result {
fn event_fmt(&self, f: &mut std::fmt::Formatter, format: &DisplayFormat) -> std::fmt::Result {
// First format the first event line starting with the {common} section,
// followed by the {kernel} or {user} one.
if let Some(common) = self.0.get(&SectionId::Common) {
Expand Down
4 changes: 2 additions & 2 deletions retis-events/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct KernelEvent {
}

impl EventFmt for KernelEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"[{}] {}",
Expand Down Expand Up @@ -42,7 +42,7 @@ impl StackTrace {
}

impl EventFmt for StackTrace {
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result {
let last = self.0.len() - 1;
match format.flavor {
DisplayFormatFlavor::SingleLine => {
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct NftEvent {
}

impl EventFmt for NftEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"table {} ({}) chain {} ({})",
Expand Down
16 changes: 8 additions & 8 deletions retis-events/src/ovs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct OvsEvent {
}

impl EventFmt for OvsEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result {
self.event.event_fmt(f, format)
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ pub enum OvsEventType {
}

impl EventFmt for OvsEventType {
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result {
use OvsEventType::*;
let disp: &dyn EventFmt = match self {
Upcall(e) => e,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct UpcallEvent {
}

impl EventFmt for UpcallEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"upcall{} port {} cpu {}",
Expand Down Expand Up @@ -134,7 +134,7 @@ pub struct UpcallEnqueueEvent {
}

impl EventFmt for UpcallEnqueueEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"upcall_enqueue{} ({}/{}) q {} ret {}",
Expand All @@ -158,7 +158,7 @@ pub struct UpcallReturnEvent {
}

impl EventFmt for UpcallReturnEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"upcall_ret ({}/{}) ret {}",
Expand Down Expand Up @@ -218,7 +218,7 @@ impl OperationEvent {
}

impl EventFmt for OperationEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(
f,
"flow_{} q {} ts {} ({})",
Expand Down Expand Up @@ -250,7 +250,7 @@ pub struct RecvUpcallEvent {
}

impl EventFmt for RecvUpcallEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
// FIXME: there are more fields.
write!(
f,
Expand All @@ -276,7 +276,7 @@ pub struct ActionEvent {
}

impl EventFmt for ActionEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
if self.recirc_id != 0 {
write!(f, "[recirc_id {:#x}] ", self.recirc_id)?;
}
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/skb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct SkbEvent {
}

impl EventFmt for SkbEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
let mut len = 0;

let mut space = DelimWriter::new(' ');
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/skb_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SkbDropEvent {
}

impl EventFmt for SkbDropEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
match &self.subsys {
None => write!(f, "drop (reason {})", self.drop_reason),
Some(name) => write!(f, "drop (reason {name}/{})", self.drop_reason),
Expand Down
4 changes: 2 additions & 2 deletions retis-events/src/skb_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl SkbTrackingEvent {
}

impl EventFmt for SkbTrackingEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(f, "#{:x} (skb {:x})", self.tracking_id(), self.skb)
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ impl Ord for TrackingInfo {
}

impl EventFmt for TrackingInfo {
fn event_fmt(&self, f: &mut fmt::Formatter, format: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, format: &DisplayFormat) -> fmt::Result {
write!(f, "{} n {}", self.skb.display(format), self.idx)
}
}
Expand Down
2 changes: 1 addition & 1 deletion retis-events/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct UserEvent {
}

impl EventFmt for UserEvent {
fn event_fmt(&self, f: &mut fmt::Formatter, _: DisplayFormat) -> fmt::Result {
fn event_fmt(&self, f: &mut fmt::Formatter, _: &DisplayFormat) -> fmt::Result {
write!(f, "[u] {}", self.symbol)?;
if let Some((_, bin)) = self.path.rsplit_once('/') {
write!(f, " ({})", bin)?;
Expand Down
2 changes: 1 addition & 1 deletion retis/src/collect/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ mod tests {
struct TestEvent {}

impl EventFmt for TestEvent {
fn event_fmt(&self, f: &mut std::fmt::Formatter, _: DisplayFormat) -> std::fmt::Result {
fn event_fmt(&self, f: &mut std::fmt::Formatter, _: &DisplayFormat) -> std::fmt::Result {
write!(f, "test event section")
}
}
Expand Down
2 changes: 1 addition & 1 deletion retis/src/core/events/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ mod tests {
}

impl EventFmt for TestEvent {
fn event_fmt(&self, f: &mut std::fmt::Formatter, _: DisplayFormat) -> std::fmt::Result {
fn event_fmt(&self, f: &mut std::fmt::Formatter, _: &DisplayFormat) -> std::fmt::Result {
write!(
f,
"field0: {:?} field1: {:?} field2: {:?}",
Expand Down
4 changes: 2 additions & 2 deletions retis/src/process/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl PrintSingle {
format.set_monotonic_offset(common.clock_monotonic_offset);
}

let event = format!("{}", e.display(*format));
let event = format!("{}", e.display(format));
if !event.is_empty() {
self.writer.write_all(event.as_bytes())?;
match format.flavor {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl PrintSeries {
format.set_monotonic_offset(common.clock_monotonic_offset);
}

content.push_str(&Self::indent(indent, format!("{}", event.display(*format))));
content.push_str(&Self::indent(indent, format!("{}", event.display(format))));
if !content.is_empty() {
content.push('\n');
indent = 2;
Expand Down

0 comments on commit e1fed23

Please sign in to comment.