Perf: Add stat for sched of ST.

pull/2213/head
winlin 4 years ago
parent e91e0eaf46
commit 70fb647ac9

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

@ -52,6 +52,19 @@
#include <valgrind/valgrind.h> #include <valgrind/valgrind.h>
#endif #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 */ /* Global data */
_st_vp_t _st_this_vp; /* This VP */ _st_vp_t _st_this_vp; /* This VP */
@ -482,6 +495,28 @@ void _st_vp_check_clock(void)
now = st_utime(); now = st_utime();
elapsed = now - _ST_LAST_CLOCK; elapsed = now - _ST_LAST_CLOCK;
_ST_LAST_CLOCK = now; _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) { if (_st_curr_time && now - _st_last_tset > 999000) {
_st_curr_time = time(NULL); _st_curr_time = time(NULL);

@ -74,6 +74,34 @@ SrsPps* _srs_pps_sendmsg_eagain = new SrsPps(_srs_clock);
SrsPps* _srs_pps_sendmmsg = new SrsPps(_srs_clock); SrsPps* _srs_pps_sendmmsg = new SrsPps(_srs_clock);
SrsPps* _srs_pps_sendmmsg_eagain = new SrsPps(_srs_clock); SrsPps* _srs_pps_sendmmsg_eagain = new SrsPps(_srs_clock);
extern unsigned long long _st_stat_epoll;
extern unsigned long long _st_stat_epoll_zero;
extern unsigned long long _st_stat_epoll_shake;
extern unsigned long long _st_stat_epoll_spin;
SrsPps* _srs_pps_epoll = new SrsPps(_srs_clock);
SrsPps* _srs_pps_epoll_zero = new SrsPps(_srs_clock);
SrsPps* _srs_pps_epoll_shake = new SrsPps(_srs_clock);
SrsPps* _srs_pps_epoll_spin = new SrsPps(_srs_clock);
extern unsigned long long _st_stat_clock_us;
extern unsigned long long _st_stat_clock_10ms;
extern unsigned long long _st_stat_clock_20ms;
extern unsigned long long _st_stat_clock_40ms;
extern unsigned long long _st_stat_clock_80ms;
extern unsigned long long _st_stat_clock_160ms;
extern unsigned long long _st_stat_clock_320ms;
extern unsigned long long _st_stat_clock_1000ms;
extern unsigned long long _st_stat_clock_s;
SrsPps* _srs_pps_clock_us = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_10ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_20ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_40ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_80ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_160ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_320ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_1000ms = new SrsPps(_srs_clock);
SrsPps* _srs_pps_clock_s = new SrsPps(_srs_clock);
ISrsHybridServer::ISrsHybridServer() ISrsHybridServer::ISrsHybridServer()
{ {
} }
@ -287,10 +315,7 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
_srs_pps_recvfrom->update(_st_stat_recvfrom); _srs_pps_recvfrom_eagain->update(_st_stat_recvfrom_eagain); _srs_pps_recvfrom->update(_st_stat_recvfrom); _srs_pps_recvfrom_eagain->update(_st_stat_recvfrom_eagain);
_srs_pps_sendto->update(_st_stat_sendto); _srs_pps_sendto_eagain->update(_st_stat_sendto_eagain); _srs_pps_sendto->update(_st_stat_sendto); _srs_pps_sendto_eagain->update(_st_stat_sendto_eagain);
if (_srs_pps_recvfrom->r10s() || _srs_pps_recvfrom_eagain->r10s() || _srs_pps_sendto->r10s() || _srs_pps_sendto_eagain->r10s()) { if (_srs_pps_recvfrom->r10s() || _srs_pps_recvfrom_eagain->r10s() || _srs_pps_sendto->r10s() || _srs_pps_sendto_eagain->r10s()) {
snprintf(buf, sizeof(buf), ", udp=%d,%d,%d,%d", snprintf(buf, sizeof(buf), ", udp=%d,%d,%d,%d", _srs_pps_recvfrom->r10s(), _srs_pps_recvfrom_eagain->r10s(), _srs_pps_sendto->r10s(), _srs_pps_sendto_eagain->r10s());
_srs_pps_recvfrom->r10s(), _srs_pps_recvfrom_eagain->r10s(),
_srs_pps_sendto->r10s(), _srs_pps_sendto_eagain->r10s()
);
recvfrom_desc = buf; recvfrom_desc = buf;
} }
@ -299,11 +324,7 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
_srs_pps_readv->update(_st_stat_readv); _srs_pps_readv_eagain->update(_st_stat_readv_eagain); _srs_pps_readv->update(_st_stat_readv); _srs_pps_readv_eagain->update(_st_stat_readv_eagain);
_srs_pps_writev->update(_st_stat_writev); _srs_pps_writev_eagain->update(_st_stat_writev_eagain); _srs_pps_writev->update(_st_stat_writev); _srs_pps_writev_eagain->update(_st_stat_writev_eagain);
if (_srs_pps_read->r10s() || _srs_pps_read_eagain->r10s() || _srs_pps_readv->r10s() || _srs_pps_readv_eagain->r10s() || _srs_pps_writev->r10s() || _srs_pps_writev_eagain->r10s()) { if (_srs_pps_read->r10s() || _srs_pps_read_eagain->r10s() || _srs_pps_readv->r10s() || _srs_pps_readv_eagain->r10s() || _srs_pps_writev->r10s() || _srs_pps_writev_eagain->r10s()) {
snprintf(buf, sizeof(buf), ", io=%d,%d,%d,%d,%d,%d", snprintf(buf, sizeof(buf), ", io=%d,%d,%d,%d,%d,%d", _srs_pps_read->r10s(), _srs_pps_read_eagain->r10s(), _srs_pps_readv->r10s(), _srs_pps_readv_eagain->r10s(), _srs_pps_writev->r10s(), _srs_pps_writev_eagain->r10s());
_srs_pps_read->r10s(), _srs_pps_read_eagain->r10s(),
_srs_pps_readv->r10s(), _srs_pps_readv_eagain->r10s(),
_srs_pps_writev->r10s(), _srs_pps_writev_eagain->r10s()
);
io_desc = buf; io_desc = buf;
} }
@ -312,18 +333,34 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
_srs_pps_sendmsg->update(_st_stat_sendmsg); _srs_pps_sendmsg_eagain->update(_st_stat_sendmsg_eagain); _srs_pps_sendmsg->update(_st_stat_sendmsg); _srs_pps_sendmsg_eagain->update(_st_stat_sendmsg_eagain);
_srs_pps_sendmmsg->update(_st_stat_sendmmsg); _srs_pps_sendmmsg_eagain->update(_st_stat_sendmmsg_eagain); _srs_pps_sendmmsg->update(_st_stat_sendmmsg); _srs_pps_sendmmsg_eagain->update(_st_stat_sendmmsg_eagain);
if (_srs_pps_recvmsg->r10s() || _srs_pps_recvmsg_eagain->r10s() || _srs_pps_sendmsg->r10s() || _srs_pps_sendmsg_eagain->r10s() || _srs_pps_sendmmsg->r10s() || _srs_pps_sendmmsg_eagain->r10s()) { if (_srs_pps_recvmsg->r10s() || _srs_pps_recvmsg_eagain->r10s() || _srs_pps_sendmsg->r10s() || _srs_pps_sendmsg_eagain->r10s() || _srs_pps_sendmmsg->r10s() || _srs_pps_sendmmsg_eagain->r10s()) {
snprintf(buf, sizeof(buf), ", msg=%d,%d,%d,%d,%d,%d", snprintf(buf, sizeof(buf), ", msg=%d,%d,%d,%d,%d,%d", _srs_pps_recvmsg->r10s(), _srs_pps_recvmsg_eagain->r10s(), _srs_pps_sendmsg->r10s(), _srs_pps_sendmsg_eagain->r10s(), _srs_pps_sendmmsg->r10s(), _srs_pps_sendmmsg_eagain->r10s());
_srs_pps_recvmsg->r10s(), _srs_pps_recvmsg_eagain->r10s(),
_srs_pps_sendmsg->r10s(), _srs_pps_sendmsg_eagain->r10s(),
_srs_pps_sendmmsg->r10s(), _srs_pps_sendmmsg_eagain->r10s()
);
msg_desc = buf; msg_desc = buf;
} }
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s", string epoll_desc;
_srs_pps_epoll->update(_st_stat_epoll); _srs_pps_epoll_zero->update(_st_stat_epoll_zero);
_srs_pps_epoll_shake->update(_st_stat_epoll_shake); _srs_pps_epoll_spin->update(_st_stat_epoll_spin);
if (_srs_pps_epoll->r10s() || _srs_pps_epoll_zero->r10s() || _srs_pps_epoll_shake->r10s() || _srs_pps_epoll_spin->r10s()) {
snprintf(buf, sizeof(buf), ", epoll=%d,%d,%d,%d", _srs_pps_epoll->r10s(), _srs_pps_epoll_zero->r10s(), _srs_pps_epoll_shake->r10s(), _srs_pps_epoll_spin->r10s());
epoll_desc = buf;
}
string clock_desc;
_srs_pps_clock_us->update(_st_stat_clock_us); _srs_pps_clock_s->update(_st_stat_clock_s);
_srs_pps_clock_10ms->update(_st_stat_clock_10ms); _srs_pps_clock_20ms->update(_st_stat_clock_20ms);
_srs_pps_clock_40ms->update(_st_stat_clock_40ms); _srs_pps_clock_80ms->update(_st_stat_clock_80ms);
_srs_pps_clock_160ms->update(_st_stat_clock_160ms); _srs_pps_clock_320ms->update(_st_stat_clock_320ms);
_srs_pps_clock_1000ms->update(_st_stat_clock_1000ms);
if (_srs_pps_clock_us->r10s() || _srs_pps_clock_s->r10s() || _srs_pps_clock_10ms->r10s() || _srs_pps_clock_20ms->r10s() || _srs_pps_clock_40ms->r10s() || _srs_pps_clock_80ms->r10s() || _srs_pps_clock_160ms->r10s() || _srs_pps_clock_320ms->r10s() || _srs_pps_clock_1000ms->r10s()) {
snprintf(buf, sizeof(buf), ", clock=%d,%d,%d,%d,%d,%d,%d,%d,%d", _srs_pps_clock_us->r10s(), _srs_pps_clock_10ms->r10s(), _srs_pps_clock_20ms->r10s(), _srs_pps_clock_40ms->r10s(), _srs_pps_clock_80ms->r10s(), _srs_pps_clock_160ms->r10s(), _srs_pps_clock_320ms->r10s(), _srs_pps_clock_1000ms->r10s(), _srs_pps_clock_s->r10s());
clock_desc = buf;
}
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s",
u->percent * 100, memory, u->percent * 100, memory,
cid_desc.c_str(), timer_desc.c_str(), free_desc.c_str(), cid_desc.c_str(), timer_desc.c_str(), free_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(), clock_desc.c_str()
); );
return err; return err;

Loading…
Cancel
Save