Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Calculate statistics on a (wrapped) stream #24

Open
vshymanskyy opened this issue Jun 22, 2022 · 6 comments
Open

Feature request: Calculate statistics on a (wrapped) stream #24

vshymanskyy opened this issue Jun 22, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@vshymanskyy
Copy link

Could be interesting to be able to grab some stats of the stream usage:

  • Total TX/RX bytes count
  • Total TX/RX packets count (writes)
  • Min/Max/Average read/write size

The only difficulty I see here: Some functions (i.e. readBytes) could be implemented via read() on some streams, but it can also be implemented directly by other implementations. Not sure if there's a clean way to handle it.

@bblanchon
Copy link
Owner

Hi @vshymanskyy,

Thank you for this suggestion; I think this is a good idea.

We could name the new classes:

  • CountingPrint
  • CountingStream
  • WriteCountingStream
  • ReadCountingStream
  • etc.

The members could be:

  • readBytes()
  • readCount()
  • minReadSize()
  • maxReadSize()
  • avgReadSize()
  • writtenBytes()
  • writeCount()
  • minWriteSize()
  • maxWriteSize()
  • avgWriteSize()

How does that sound?

Best regards,
Benoit

@bblanchon bblanchon added the enhancement New feature or request label Jun 23, 2022
@vshymanskyy
Copy link
Author

Sounds cool. But some names may be ambiguous esp. readBytes(). Maybe prefix all of them with total, min, max, avg ?

@bblanchon
Copy link
Owner

You're right!
Maybe something like this, then:

read write
readCount() writeCount()
avgReadSize() avgWriteSize()
maxReadSize() maxWriteSize()
minReadSize() minWriteSize()
totalReadSize() totalWriteSize()

@bblanchon
Copy link
Owner

I'm not sure how to handle error cases: should we count them, or ignore them?

For example, if upstream's write() function returns 0, should I increment writeCount? should I set minWriteSize to 0?

@dpharris
Copy link

Maybe readErrors() and writeErrors()?

@mhaberler
Copy link

for such jobs I like the header-only stats classes by https://www.johndcook.com/blog/skewness_kurtosis/

he has several such classes on his website, real collectors items - I collect them here plus my adaptations: https://github.com/mhaberler/Stats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants