1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

STAT: Extract an ephemeral delta object.

This commit is contained in:
winlin 2022-08-29 13:37:27 +08:00
parent 4fe90d4885
commit db91102e67
5 changed files with 70 additions and 19 deletions

View file

@ -68,6 +68,28 @@ ISrsKbpsDelta::~ISrsKbpsDelta()
{
}
SrsEphemeralDelta::SrsEphemeralDelta()
{
in_ = out_ = 0;
}
SrsEphemeralDelta::~SrsEphemeralDelta()
{
}
void SrsEphemeralDelta::add_delta(int64_t in, int64_t out)
{
in_ += in;
out_ += out;
}
void SrsEphemeralDelta::remark(int64_t* in, int64_t* out)
{
if (in) *in = in_;
if (out) *out = out_;
in_ = out_ = 0;
}
SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c)
{
clk = c;

View file

@ -84,6 +84,23 @@ public:
virtual void remark(int64_t* in, int64_t* out) = 0;
};
// A delta data source for SrsKbps, used in ephemeral case, for example, UDP server to increase stat when received or
// sent out each UDP packet.
class SrsEphemeralDelta : public ISrsKbpsDelta
{
private:
uint64_t in_;
uint64_t out_;
public:
SrsEphemeralDelta();
virtual ~SrsEphemeralDelta();
public:
virtual void add_delta(int64_t in, int64_t out);
// Interface ISrsKbpsDelta.
public:
virtual void remark(int64_t* in, int64_t* out);
};
/**
* to statistic the kbps of io.
* itself can be a statistic source, for example, used for SRS bytes stat.