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

Perf: Add stat for sched of ST.

This commit is contained in:
winlin 2021-02-10 20:00:33 +08:00
parent 7b913b1115
commit a46debb4bb
3 changed files with 118 additions and 18 deletions

View file

@ -47,6 +47,14 @@
#include <sys/epoll.h>
#endif
// Global stat.
#ifdef DEBUG
unsigned long long _st_stat_epoll = 0;
unsigned long long _st_stat_epoll_zero = 0;
unsigned long long _st_stat_epoll_shake = 0;
unsigned long long _st_stat_epoll_spin = 0;
#endif
#if defined(USE_POLL) && !defined(MD_HAVE_POLL)
/* Force poll usage if explicitly asked for it */
#define MD_HAVE_POLL
@ -1205,6 +1213,10 @@ ST_HIDDEN void _st_epoll_dispatch(void)
int events, op;
short revents;
#ifdef DEBUG
++_st_stat_epoll;
#endif
if (_ST_SLEEPQ == NULL) {
timeout = -1;
} else {
@ -1212,8 +1224,18 @@ ST_HIDDEN void _st_epoll_dispatch(void)
timeout = (int) (min_timeout / 1000);
// At least wait 1ms when <1ms, to avoid epoll_wait spin loop.
if (min_timeout > 0 && timeout == 0) {
timeout = 1;
if (timeout == 0) {
#ifdef DEBUG
++_st_stat_epoll_zero;
#endif
if (min_timeout > 0) {
#ifdef DEBUG
++_st_stat_epoll_shake;
#endif
timeout = 1;
}
}
}
@ -1240,6 +1262,12 @@ ST_HIDDEN void _st_epoll_dispatch(void)
/* Check for I/O operations */
nfd = epoll_wait(_st_epoll_data->epfd, _st_epoll_data->evtlist, _st_epoll_data->evtlist_size, timeout);
#ifdef DEBUG
if (nfd <= 0) {
++_st_stat_epoll_spin;
}
#endif
if (nfd > 0) {
for (i = 0; i < nfd; i++) {
osfd = _st_epoll_data->evtlist[i].data.fd;

View file

@ -52,6 +52,19 @@
#include <valgrind/valgrind.h>
#endif
// Global stat.
#ifdef DEBUG
unsigned long long _st_stat_clock_us = 0;
unsigned long long _st_stat_clock_10ms = 0;
unsigned long long _st_stat_clock_20ms = 0;
unsigned long long _st_stat_clock_40ms = 0;
unsigned long long _st_stat_clock_80ms = 0;
unsigned long long _st_stat_clock_160ms = 0;
unsigned long long _st_stat_clock_320ms = 0;
unsigned long long _st_stat_clock_1000ms = 0;
unsigned long long _st_stat_clock_s = 0;
#endif
/* Global data */
_st_vp_t _st_this_vp; /* This VP */
@ -482,6 +495,28 @@ void _st_vp_check_clock(void)
now = st_utime();
elapsed = now - _ST_LAST_CLOCK;
_ST_LAST_CLOCK = now;
#ifdef DEBUG
if (elapsed < 1000) {
++_st_stat_clock_us;
} else if (elapsed < 10000) {
++_st_stat_clock_10ms;
} else if (elapsed < 20000) {
++_st_stat_clock_20ms;
} else if (elapsed < 40000) {
++_st_stat_clock_40ms;
} else if (elapsed < 80000) {
++_st_stat_clock_80ms;
} else if (elapsed < 160000) {
++_st_stat_clock_160ms;
} else if (elapsed < 320000) {
++_st_stat_clock_320ms;
} else if (elapsed < 1000000) {
++_st_stat_clock_1000ms;
} else {
++_st_stat_clock_s;
}
#endif
if (_st_curr_time && now - _st_last_tset > 999000) {
_st_curr_time = time(NULL);