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

Core: Refine ST stat for thread switch

This commit is contained in:
winlin 2021-02-11 13:26:20 +08:00
parent e726aba8f9
commit 71cc8e35d9
2 changed files with 26 additions and 2 deletions

View file

@ -63,6 +63,9 @@ unsigned long long _st_stat_sched_160ms = 0;
unsigned long long _st_stat_sched_320ms = 0; unsigned long long _st_stat_sched_320ms = 0;
unsigned long long _st_stat_sched_1000ms = 0; unsigned long long _st_stat_sched_1000ms = 0;
unsigned long long _st_stat_sched_s = 0; unsigned long long _st_stat_sched_s = 0;
unsigned long long _st_stat_thread_run = 0;
unsigned long long _st_stat_thread_idle = 0;
#endif #endif
@ -131,10 +134,18 @@ void _st_vp_schedule(void)
_st_thread_t *thread; _st_thread_t *thread;
if (_ST_RUNQ.next != &_ST_RUNQ) { if (_ST_RUNQ.next != &_ST_RUNQ) {
#ifdef DEBUG
++_st_stat_thread_run;
#endif
/* Pull thread off of the run queue */ /* Pull thread off of the run queue */
thread = _ST_THREAD_PTR(_ST_RUNQ.next); thread = _ST_THREAD_PTR(_ST_RUNQ.next);
_ST_DEL_RUNQ(thread); _ST_DEL_RUNQ(thread);
} else { } else {
#ifdef DEBUG
++_st_stat_thread_idle;
#endif
/* If there are no threads to run, switch to the idle thread */ /* If there are no threads to run, switch to the idle thread */
thread = _st_this_vp.idle_thread; thread = _st_this_vp.idle_thread;
} }

View file

@ -112,6 +112,11 @@ SrsPps* _srs_pps_clock_80ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_160ms = new SrsPps(_srs_clock); SrsPps* _srs_pps_clock_160ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_timer_s = new SrsPps(_srs_clock); SrsPps* _srs_pps_timer_s = new SrsPps(_srs_clock);
extern unsigned long long _st_stat_thread_run;
extern unsigned long long _st_stat_thread_idle;
SrsPps* _srs_pps_thread_run = new SrsPps(_srs_clock);
SrsPps* _srs_pps_thread_idle = new SrsPps(_srs_clock);
ISrsHybridServer::ISrsHybridServer() ISrsHybridServer::ISrsHybridServer()
{ {
} }
@ -248,7 +253,7 @@ srs_error_t SrsHybridServer::run()
} }
// Wait for all server to quit. // Wait for all server to quit.
srs_thread_exit(NULL); srs_usleep(SRS_UTIME_NO_TIMEOUT);
return err; return err;
} }
@ -417,11 +422,19 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
clock_desc = buf; clock_desc = buf;
} }
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s", string thread_desc;
_srs_pps_thread_run->update(_st_stat_thread_run); _srs_pps_thread_idle->update(_st_stat_thread_idle);
if (_srs_pps_thread_run->r10s() || _srs_pps_thread_idle->r10s()) {
snprintf(buf, sizeof(buf), ", co=%d,%d", _srs_pps_thread_run->r10s(), _srs_pps_thread_idle->r10s());
thread_desc = buf;
}
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s%s",
u->percent * 100, memory, u->percent * 100, memory,
cid_desc.c_str(), timer_desc.c_str(), cid_desc.c_str(), timer_desc.c_str(),
recvfrom_desc.c_str(), io_desc.c_str(), msg_desc.c_str(), recvfrom_desc.c_str(), io_desc.c_str(), msg_desc.c_str(),
epoll_desc.c_str(), sched_desc.c_str(), clock_desc.c_str(), epoll_desc.c_str(), sched_desc.c_str(), clock_desc.c_str(),
thread_desc.c_str(),
free_desc.c_str() free_desc.c_str()
); );