Perf: Improve fast find for pithy print

pull/2213/head
winlin 4 years ago
parent 3a7c742f07
commit adfca6069c

@ -171,6 +171,7 @@ static SrsStageManager* _srs_stages = new SrsStageManager();
SrsPithyPrint::SrsPithyPrint(int _stage_id)
{
stage_id = _stage_id;
cache_ = NULL;
client_id = enter_stage();
previous_tick = srs_get_system_time();
_age = 0;
@ -308,7 +309,10 @@ void SrsPithyPrint::leave_stage()
void SrsPithyPrint::elapse()
{
SrsStageInfo* stage = _srs_stages->fetch_or_create(stage_id);
SrsStageInfo* stage = cache_;
if (!stage) {
stage = cache_ = _srs_stages->fetch_or_create(stage_id);
}
srs_assert(stage != NULL);
srs_utime_t diff = srs_get_system_time() - previous_tick;
@ -321,7 +325,10 @@ void SrsPithyPrint::elapse()
bool SrsPithyPrint::can_print()
{
SrsStageInfo* stage = _srs_stages->fetch_or_create(stage_id);
SrsStageInfo* stage = cache_;
if (!stage) {
stage = cache_ = _srs_stages->fetch_or_create(stage_id);
}
srs_assert(stage != NULL);
return stage->can_print();

@ -111,6 +111,7 @@ class SrsPithyPrint
{
private:
int client_id;
SrsStageInfo* cache_;
int stage_id;
srs_utime_t _age;
srs_utime_t previous_tick;

Loading…
Cancel
Save