Skip to content

Commit ae1247e

Browse files
committed
Add tracing instrumentation to Parse methods.
Without these, the flamegraphs produced with tracing-flamegraph look rather sparse for `Command::from_frame`.
1 parent 930449f commit ae1247e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/parse.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::Frame;
22

33
use bytes::Bytes;
44
use std::{fmt, str, vec};
5+
use tracing::instrument;
56

67
/// Utility for parsing a command
78
///
@@ -33,6 +34,7 @@ impl Parse {
3334
/// Create a new `Parse` to parse the contents of `frame`.
3435
///
3536
/// Returns `Err` if `frame` is not an array frame.
37+
#[instrument(level = "trace", name = "Parse::new")]
3638
pub(crate) fn new(frame: Frame) -> Result<Parse, ParseError> {
3739
let array = match frame {
3840
Frame::Array(array) => array,
@@ -46,13 +48,15 @@ impl Parse {
4648

4749
/// Return the next entry. Array frames are arrays of frames, so the next
4850
/// entry is a frame.
51+
#[instrument(level = "trace", name = "Parse::next", skip(self))]
4952
fn next(&mut self) -> Result<Frame, ParseError> {
5053
self.parts.next().ok_or(ParseError::EndOfStream)
5154
}
5255

5356
/// Return the next entry as a string.
5457
///
5558
/// If the next entry cannot be represented as a String, then an error is returned.
59+
#[instrument(level = "trace", name = "Parse::next_string", skip(self))]
5660
pub(crate) fn next_string(&mut self) -> Result<String, ParseError> {
5761
match self.next()? {
5862
// Both `Simple` and `Bulk` representation may be strings. Strings
@@ -76,6 +80,7 @@ impl Parse {
7680
///
7781
/// If the next entry cannot be represented as raw bytes, an error is
7882
/// returned.
83+
#[instrument(level = "trace", name = "Parse::next_bytes", skip(self))]
7984
pub(crate) fn next_bytes(&mut self) -> Result<Bytes, ParseError> {
8085
match self.next()? {
8186
// Both `Simple` and `Bulk` representation may be raw bytes.
@@ -99,6 +104,7 @@ impl Parse {
99104
///
100105
/// If the next entry cannot be represented as an integer, then an error is
101106
/// returned.
107+
#[instrument(level = "trace", name = "Parse::next_int", skip(self))]
102108
pub(crate) fn next_int(&mut self) -> Result<u64, ParseError> {
103109
use atoi::atoi;
104110

@@ -116,6 +122,7 @@ impl Parse {
116122
}
117123

118124
/// Ensure there are no more entries in the array
125+
#[instrument(level = "trace", name = "Parse::finish", skip(self))]
119126
pub(crate) fn finish(&mut self) -> Result<(), ParseError> {
120127
if self.parts.next().is_none() {
121128
Ok(())

0 commit comments

Comments
 (0)