mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine SrsWallClock and SrsKbps in time unit.
This commit is contained in:
parent
5560b529a7
commit
cfab73b552
5 changed files with 39 additions and 39 deletions
|
@ -35,7 +35,7 @@ SrsKbpsSample::~SrsKbpsSample()
|
|||
{
|
||||
}
|
||||
|
||||
SrsKbpsSample* SrsKbpsSample::update(int64_t b, int64_t t, int k)
|
||||
SrsKbpsSample* SrsKbpsSample::update(int64_t b, srs_utime_t t, int k)
|
||||
{
|
||||
bytes = b;
|
||||
time = t;
|
||||
|
@ -61,7 +61,7 @@ int64_t SrsKbpsSlice::get_total_bytes()
|
|||
|
||||
void SrsKbpsSlice::sample()
|
||||
{
|
||||
int64_t now = clk->time_ms();
|
||||
srs_utime_t now = clk->now();
|
||||
int64_t total_bytes = get_total_bytes();
|
||||
|
||||
if (sample_30s.time < 0) {
|
||||
|
@ -77,20 +77,20 @@ void SrsKbpsSlice::sample()
|
|||
sample_60m.update(total_bytes, now, 0);
|
||||
}
|
||||
|
||||
if (now - sample_30s.time >= 30 * 1000) {
|
||||
int kbps = (int)((total_bytes - sample_30s.bytes) * 8 / (now - sample_30s.time));
|
||||
if (now - sample_30s.time >= 30 * SRS_UTIME_SECONDS) {
|
||||
int kbps = (int)((total_bytes - sample_30s.bytes) * 8 / srsu2ms(now - sample_30s.time));
|
||||
sample_30s.update(total_bytes, now, kbps);
|
||||
}
|
||||
if (now - sample_1m.time >= 60 * 1000) {
|
||||
int kbps = (int)((total_bytes - sample_1m.bytes) * 8 / (now - sample_1m.time));
|
||||
if (now - sample_1m.time >= 60 * SRS_UTIME_SECONDS) {
|
||||
int kbps = (int)((total_bytes - sample_1m.bytes) * 8 / srsu2ms(now - sample_1m.time));
|
||||
sample_1m.update(total_bytes, now, kbps);
|
||||
}
|
||||
if (now - sample_5m.time >= 300 * 1000) {
|
||||
int kbps = (int)((total_bytes - sample_5m.bytes) * 8 / (now - sample_5m.time));
|
||||
if (now - sample_5m.time >= 300 * SRS_UTIME_SECONDS) {
|
||||
int kbps = (int)((total_bytes - sample_5m.bytes) * 8 / srsu2ms(now - sample_5m.time));
|
||||
sample_5m.update(total_bytes, now, kbps);
|
||||
}
|
||||
if (now - sample_60m.time >= 3600 * 1000) {
|
||||
int kbps = (int)((total_bytes - sample_60m.bytes) * 8 / (now - sample_60m.time));
|
||||
if (now - sample_60m.time >= 3600 * SRS_UTIME_SECONDS) {
|
||||
int kbps = (int)((total_bytes - sample_60m.bytes) * 8 / srsu2ms(now - sample_60m.time));
|
||||
sample_60m.update(total_bytes, now, kbps);
|
||||
}
|
||||
}
|
||||
|
@ -111,9 +111,9 @@ SrsWallClock::~SrsWallClock()
|
|||
{
|
||||
}
|
||||
|
||||
int64_t SrsWallClock::time_ms()
|
||||
srs_utime_t SrsWallClock::now()
|
||||
{
|
||||
return srsu2ms(srs_get_system_time());
|
||||
return srs_get_system_time();
|
||||
}
|
||||
|
||||
SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c)
|
||||
|
@ -130,7 +130,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
// set input stream
|
||||
// now, set start time.
|
||||
if (is.starttime == 0) {
|
||||
is.starttime = clk->time_ms();
|
||||
is.starttime = clk->now();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (is.io) {
|
||||
|
@ -148,7 +148,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
// set output stream
|
||||
// now, set start time.
|
||||
if (os.starttime == 0) {
|
||||
os.starttime = clk->time_ms();
|
||||
os.starttime = clk->now();
|
||||
}
|
||||
// save the old in bytes.
|
||||
if (os.io) {
|
||||
|
@ -166,22 +166,22 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
|||
|
||||
int SrsKbps::get_send_kbps()
|
||||
{
|
||||
int64_t duration = clk->time_ms() - is.starttime;
|
||||
srs_utime_t duration = clk->now() - is.starttime;
|
||||
if (duration <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int64_t bytes = get_send_bytes();
|
||||
return (int)(bytes * 8 / duration);
|
||||
return (int)(bytes * 8 / srsu2ms(duration));
|
||||
}
|
||||
|
||||
int SrsKbps::get_recv_kbps()
|
||||
{
|
||||
int64_t duration = clk->time_ms() - os.starttime;
|
||||
srs_utime_t duration = clk->now() - os.starttime;
|
||||
if (duration <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int64_t bytes = get_recv_bytes();
|
||||
return (int)(bytes * 8 / duration);
|
||||
return (int)(bytes * 8 / srsu2ms(duration));
|
||||
}
|
||||
|
||||
int SrsKbps::get_send_kbps_30s()
|
||||
|
|
|
@ -38,13 +38,13 @@ class SrsKbpsSample
|
|||
{
|
||||
public:
|
||||
int64_t bytes;
|
||||
int64_t time;
|
||||
srs_utime_t time;
|
||||
int kbps;
|
||||
public:
|
||||
SrsKbpsSample();
|
||||
virtual ~SrsKbpsSample();
|
||||
public:
|
||||
virtual SrsKbpsSample* update(int64_t b, int64_t t, int k);
|
||||
virtual SrsKbpsSample* update(int64_t b, srs_utime_t t, int k);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
// @remark, use total_bytes() to get the total bytes of slice.
|
||||
int64_t bytes;
|
||||
// slice starttime, the first time to record bytes.
|
||||
int64_t starttime;
|
||||
srs_utime_t starttime;
|
||||
// session startup bytes number for io when set it,
|
||||
// the base offset of bytes for io.
|
||||
int64_t io_bytes_base;
|
||||
|
@ -129,9 +129,9 @@ public:
|
|||
virtual ~SrsWallClock();
|
||||
public:
|
||||
/**
|
||||
* Current time in ms.
|
||||
* Current time in srs_utime_t.
|
||||
*/
|
||||
virtual int64_t time_ms();
|
||||
virtual srs_utime_t now();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue