Skip to content

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

Open

Description

@vshymanskyy

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.

Activity

  1. bblanchon commented on Jun 23, 2022

    @bblanchon
    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

  2. vshymanskyy commented on Jun 24, 2022

    @vshymanskyy
    Author

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

  3. bblanchon commented on Jun 26, 2022

    @bblanchon
    Owner

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

    read write
    readCount() writeCount()
    avgReadSize() avgWriteSize()
    maxReadSize() maxWriteSize()
    minReadSize() minWriteSize()
    totalReadSize() totalWriteSize()
  4. bblanchon commented on Jun 27, 2022

    @bblanchon
    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?

  5. dpharris commented on Oct 23, 2022

    @dpharris

    Maybe readErrors() and writeErrors()?

  6. mhaberler commented on May 14, 2023

    @mhaberler

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions