Skip to content

Commit

Permalink
Fix stats feature (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets authored Dec 6, 2023
1 parent f84138c commit 9f7a37e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ jobs:
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

- name: Clippy unstable
- name: Clippy unstable and stats
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --features unstable -- -D warnings
args: --all-targets --features unstable --features stats -- -D warnings
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

Expand Down
8 changes: 8 additions & 0 deletions io/zenoh-transport/src/common/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ impl WBatch {
pub fn clear(&mut self) {
self.buffer.clear();
self.codec.clear();
#[cfg(feature = "stats")]
{
self.stats.clear();
}
if let Some(h) = self.header.get() {
let mut writer = self.buffer.writer();
let _ = writer.write_u8(h.get());
Expand Down Expand Up @@ -314,6 +318,10 @@ impl RBatch {
}
}

pub fn len(&self) -> usize {
self.buffer.len()
}

#[inline(always)]
pub const fn is_empty(&self) -> bool {
self.buffer.is_empty()
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-transport/src/multicast/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ async fn tx_task(
#[cfg(feature = "stats")]
{
stats.inc_tx_t_msgs(batch.stats.t_msgs);
stats.inc_tx_bytes(bytes.len());
stats.inc_tx_bytes(batch.len() as usize);
}
// Reinsert the batch into the queue
pipeline.refill(batch, priority);
Expand Down Expand Up @@ -595,7 +595,7 @@ async fn rx_task(
match action {
Action::Read((batch, locator)) => {
#[cfg(feature = "stats")]
transport.stats.inc_rx_bytes(zslice.len());
transport.stats.inc_rx_bytes(batch.len());

// Deserialize all the messages from the current ZBuf
transport.read_messages(
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/src/unicast/universal/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async fn tx_task(
#[cfg(feature = "stats")]
{
stats.inc_tx_t_msgs(batch.stats.t_msgs);
stats.inc_tx_bytes(bytes.len());
stats.inc_tx_bytes(batch.len() as usize);
}

// Reinsert the batch into the queue
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ macro_rules! inc_stats {
) => {
paste::paste! {
if let Some(stats) = $face.stats.as_ref() {
use zenoh_buffers::SplitBuffer;
use zenoh_buffers::buffer::Buffer;
match &$body {
PushBody::Put(p) => {
stats.[<$txrx _z_put_msgs>].[<inc_ $space>](1);
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/net/routing/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ macro_rules! inc_req_stats {
) => {
paste::paste! {
if let Some(stats) = $face.stats.as_ref() {
use zenoh_buffers::SplitBuffer;
use zenoh_buffers::buffer::Buffer;
match &$body {
RequestBody::Put(p) => {
stats.[<$txrx _z_put_msgs>].[<inc_ $space>](1);
Expand Down Expand Up @@ -2036,7 +2036,7 @@ macro_rules! inc_res_stats {
) => {
paste::paste! {
if let Some(stats) = $face.stats.as_ref() {
use zenoh_buffers::SplitBuffer;
use zenoh_buffers::buffer::Buffer;
match &$body {
ResponseBody::Put(p) => {
stats.[<$txrx _z_put_msgs>].[<inc_ $space>](1);
Expand Down

0 comments on commit 9f7a37e

Please sign in to comment.