mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
Refine get_pithy_print in time unit
This commit is contained in:
parent
60f9561d2d
commit
5df8f2f6c1
6 changed files with 22 additions and 13 deletions
|
@ -49,7 +49,7 @@ daemon on;
|
||||||
# if on, use gmtime() instead, which use UTC time.
|
# if on, use gmtime() instead, which use UTC time.
|
||||||
# default: off
|
# default: off
|
||||||
utc_time off;
|
utc_time off;
|
||||||
# config for the pithy print,
|
# config for the pithy print in ms,
|
||||||
# which always print constant message specified by interval,
|
# which always print constant message specified by interval,
|
||||||
# whatever the clients in concurrency.
|
# whatever the clients in concurrency.
|
||||||
# default: 10000
|
# default: 10000
|
||||||
|
|
|
@ -4055,16 +4055,16 @@ string SrsConfig::get_pid_file()
|
||||||
return conf->arg0();
|
return conf->arg0();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfig::get_pithy_print_ms()
|
srs_utime_t SrsConfig::get_pithy_print()
|
||||||
{
|
{
|
||||||
static int DEFAULT = 10000;
|
static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS;
|
||||||
|
|
||||||
SrsConfDirective* conf = root->get("pithy_print_ms");
|
SrsConfDirective* conf = root->get("pithy_print_ms");
|
||||||
if (!conf || conf->arg0().empty()) {
|
if (!conf || conf->arg0().empty()) {
|
||||||
return DEFAULT;
|
return DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ::atoi(conf->arg0().c_str());
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsConfig::get_utc_time()
|
bool SrsConfig::get_utc_time()
|
||||||
|
|
|
@ -604,11 +604,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual std::string get_pid_file();
|
virtual std::string get_pid_file();
|
||||||
/**
|
/**
|
||||||
* get pithy print pulse ms,
|
* get pithy print pulse in srs_utime_t,
|
||||||
* for example, all rtmp connections only print one message
|
* for example, all rtmp connections only print one message
|
||||||
* every this interval in ms.
|
* every this interval in ms.
|
||||||
*/
|
*/
|
||||||
virtual int get_pithy_print_ms();
|
virtual srs_utime_t get_pithy_print();
|
||||||
/**
|
/**
|
||||||
* whether use utc-time to format the time.
|
* whether use utc-time to format the time.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -49,17 +49,17 @@ SrsStageInfo::~SrsStageInfo()
|
||||||
|
|
||||||
void SrsStageInfo::update_print_time()
|
void SrsStageInfo::update_print_time()
|
||||||
{
|
{
|
||||||
pithy_print_time_ms = _srs_config->get_pithy_print_ms();
|
interval = _srs_config->get_pithy_print();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsStageInfo::elapse(int64_t diff)
|
void SrsStageInfo::elapse(srs_utime_t diff)
|
||||||
{
|
{
|
||||||
age += diff;
|
age += diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsStageInfo::can_print()
|
bool SrsStageInfo::can_print()
|
||||||
{
|
{
|
||||||
int64_t can_print_age = nb_clients * pithy_print_time_ms;
|
srs_utime_t can_print_age = nb_clients * interval;
|
||||||
|
|
||||||
bool can_print = age >= can_print_age;
|
bool can_print = age >= can_print_age;
|
||||||
if (can_print) {
|
if (can_print) {
|
||||||
|
@ -211,7 +211,7 @@ void SrsPithyPrint::elapse()
|
||||||
int64_t diff = srs_get_system_time_ms() - previous_tick;
|
int64_t diff = srs_get_system_time_ms() - previous_tick;
|
||||||
diff = srs_max(0, diff);
|
diff = srs_max(0, diff);
|
||||||
|
|
||||||
stage->elapse(diff);
|
stage->elapse(diff * SRS_UTIME_MILLISECONDS);
|
||||||
_age += diff;
|
_age += diff;
|
||||||
previous_tick = srs_get_system_time_ms();
|
previous_tick = srs_get_system_time_ms();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
#include <srs_app_reload.hpp>
|
#include <srs_app_reload.hpp>
|
||||||
|
#include <srs_service_time.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the stage info to calc the age.
|
* the stage info to calc the age.
|
||||||
|
@ -35,16 +36,16 @@ class SrsStageInfo : public ISrsReloadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int stage_id;
|
int stage_id;
|
||||||
int pithy_print_time_ms;
|
srs_utime_t interval;
|
||||||
int nb_clients;
|
int nb_clients;
|
||||||
public:
|
public:
|
||||||
int64_t age;
|
srs_utime_t age;
|
||||||
public:
|
public:
|
||||||
SrsStageInfo(int _stage_id);
|
SrsStageInfo(int _stage_id);
|
||||||
virtual ~SrsStageInfo();
|
virtual ~SrsStageInfo();
|
||||||
virtual void update_print_time();
|
virtual void update_print_time();
|
||||||
public:
|
public:
|
||||||
virtual void elapse(int64_t diff);
|
virtual void elapse(srs_utime_t diff);
|
||||||
virtual bool can_print();
|
virtual bool can_print();
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t on_reload_pithy_print();
|
virtual srs_error_t on_reload_pithy_print();
|
||||||
|
|
|
@ -1835,5 +1835,13 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues)
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{interval 10;}"));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"heartbeat{interval 10;}"));
|
||||||
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_heartbeat_interval());
|
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_heartbeat_interval());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
||||||
|
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_pithy_print());
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pithy_print_ms 20000;"));
|
||||||
|
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_pithy_print());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue