From 77923a2e084b0e7f4fa316978a9a6226cc4d4031 Mon Sep 17 00:00:00 2001 From: OlivierHecart Date: Thu, 12 Dec 2024 16:27:54 +0100 Subject: [PATCH] Fix stats bugs (#1664) * Fix stats * Fix stats --- io/zenoh-transport/src/common/batch.rs | 27 +++++++++++++++++++--- zenoh/src/net/routing/dispatcher/pubsub.rs | 8 +++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/io/zenoh-transport/src/common/batch.rs b/io/zenoh-transport/src/common/batch.rs index 65150f728..0a0a41cf9 100644 --- a/io/zenoh-transport/src/common/batch.rs +++ b/io/zenoh-transport/src/common/batch.rs @@ -363,7 +363,14 @@ impl Encode<&TransportMessage> for &mut WBatch { fn encode(self, x: &TransportMessage) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } } @@ -381,7 +388,14 @@ impl Encode<(&NetworkMessage, &FrameHeader)> for &mut WBatch { fn encode(self, x: (&NetworkMessage, &FrameHeader)) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } } @@ -390,7 +404,14 @@ impl Encode<(&mut ZBufReader<'_>, &mut FragmentHeader)> for &mut WBatch { fn encode(self, x: (&mut ZBufReader<'_>, &mut FragmentHeader)) -> Self::Output { let mut writer = self.buffer.writer(); - self.codec.write(&mut writer, x) + let res = self.codec.write(&mut writer, x); + #[cfg(feature = "stats")] + { + if res.is_ok() { + self.stats.t_msgs += 1; + } + } + res } } diff --git a/zenoh/src/net/routing/dispatcher/pubsub.rs b/zenoh/src/net/routing/dispatcher/pubsub.rs index c755e26a4..4c5ff66c8 100644 --- a/zenoh/src/net/routing/dispatcher/pubsub.rs +++ b/zenoh/src/net/routing/dispatcher/pubsub.rs @@ -434,9 +434,9 @@ pub fn route_data( drop(tables); #[cfg(feature = "stats")] if !admin { - inc_stats!(face, tx, user, msg.payload) + inc_stats!(outface, tx, user, msg.payload) } else { - inc_stats!(face, tx, admin, msg.payload) + inc_stats!(outface, tx, admin, msg.payload) } outface.primitives.send_push( @@ -465,9 +465,9 @@ pub fn route_data( for (outface, key_expr, context) in route { #[cfg(feature = "stats")] if !admin { - inc_stats!(face, tx, user, msg.payload) + inc_stats!(outface, tx, user, msg.payload) } else { - inc_stats!(face, tx, admin, msg.payload) + inc_stats!(outface, tx, admin, msg.payload) } outface.primitives.send_push(