Skip to content

Commit

Permalink
Fix stats bugs (#1664)
Browse files Browse the repository at this point in the history
* Fix stats

* Fix stats
  • Loading branch information
OlivierHecart authored Dec 12, 2024
1 parent 8716c87 commit 77923a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 24 additions & 3 deletions io/zenoh-transport/src/common/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
8 changes: 4 additions & 4 deletions zenoh/src/net/routing/dispatcher/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 77923a2

Please sign in to comment.