Refactor pithy print logs

pull/1753/head
winlin 5 years ago
parent 2b132d6d64
commit d5b3cf9af7

@ -431,11 +431,18 @@ void SrsUdpMuxListener::set_socket_buffer()
srs_error_t SrsUdpMuxListener::cycle() srs_error_t SrsUdpMuxListener::cycle()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_recv();
SrsAutoFree(SrsPithyPrint, pprint);
uint64_t nn_loop = 0;
while (true) { while (true) {
if ((err = trd->pull()) != srs_success) { if ((err = trd->pull()) != srs_success) {
return srs_error_wrap(err, "udp listener"); return srs_error_wrap(err, "udp listener");
} }
nn_loop++;
SrsUdpMuxSocket skt(lfd); SrsUdpMuxSocket skt(lfd);
@ -452,8 +459,13 @@ srs_error_t SrsUdpMuxListener::cycle()
// remux udp never return // remux udp never return
srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str()); srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str());
srs_error_reset(err); srs_error_reset(err);
continue; }
}
pprint->elapse();
if (pprint->can_print()) {
srs_trace("-> RTC #%d RECV schedule %" PRId64, srs_netfd_fileno(lfd), nn_loop);
nn_loop = 0;
}
if (SrsUdpPacketRecvCycleInterval > 0) { if (SrsUdpPacketRecvCycleInterval > 0) {
srs_usleep(SrsUdpPacketRecvCycleInterval); srs_usleep(SrsUdpPacketRecvCycleInterval);

@ -114,6 +114,8 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id)
#define SRS_CONSTS_STAGE_RTC_PLAY 12 #define SRS_CONSTS_STAGE_RTC_PLAY 12
// for the rtc send // for the rtc send
#define SRS_CONSTS_STAGE_RTC_SEND 13 #define SRS_CONSTS_STAGE_RTC_SEND 13
// for the rtc recv
#define SRS_CONSTS_STAGE_RTC_RECV 14
SrsPithyPrint* SrsPithyPrint::create_rtmp_play() SrsPithyPrint* SrsPithyPrint::create_rtmp_play()
{ {
@ -180,6 +182,11 @@ SrsPithyPrint* SrsPithyPrint::create_rtc_send()
return new SrsPithyPrint(SRS_CONSTS_STAGE_RTC_SEND); return new SrsPithyPrint(SRS_CONSTS_STAGE_RTC_SEND);
} }
SrsPithyPrint* SrsPithyPrint::create_rtc_recv()
{
return new SrsPithyPrint(SRS_CONSTS_STAGE_RTC_RECV);
}
SrsPithyPrint::~SrsPithyPrint() SrsPithyPrint::~SrsPithyPrint()
{ {
leave_stage(); leave_stage();

@ -89,6 +89,7 @@ public:
static SrsPithyPrint* create_http_stream_cache(); static SrsPithyPrint* create_http_stream_cache();
static SrsPithyPrint* create_rtc_play(); static SrsPithyPrint* create_rtc_play();
static SrsPithyPrint* create_rtc_send(); static SrsPithyPrint* create_rtc_send();
static SrsPithyPrint* create_rtc_recv();
virtual ~SrsPithyPrint(); virtual ~SrsPithyPrint();
private: private:
// Enter the specified stage, return the client id. // Enter the specified stage, return the client id.

@ -1670,6 +1670,9 @@ srs_error_t SrsRtcServer::cycle()
uint64_t nn_msgs = 0; uint64_t nn_msgs = 0;
uint64_t nn_msgs_last = 0; uint64_t nn_msgs_last = 0;
uint64_t nn_msgs_max = 0;
uint64_t nn_loop = 0;
uint64_t nn_wait = 0;
srs_utime_t time_last = srs_get_system_time(); srs_utime_t time_last = srs_get_system_time();
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
@ -1681,9 +1684,12 @@ srs_error_t SrsRtcServer::cycle()
return err; return err;
} }
nn_loop++;
int pos = cache_pos; int pos = cache_pos;
if (pos <= 0) { if (pos <= 0) {
waiting_msgs = true; waiting_msgs = true;
nn_wait++;
srs_cond_wait(cond); srs_cond_wait(cond);
continue; continue;
} }
@ -1693,11 +1699,13 @@ srs_error_t SrsRtcServer::cycle()
cache_pos = 0; cache_pos = 0;
mmsghdr* p = &hotspot[0]; mmsghdr* p = &hotspot[0];
for (mmsghdr* end = p + pos; p < end; p += max_sendmmsg) { mmsghdr* end = p + pos;
srs_netfd_t stfd = mmstfd;
for (; p < end; p += max_sendmmsg) {
int vlen = (int)(end - p); int vlen = (int)(end - p);
vlen = srs_min(max_sendmmsg, vlen); vlen = srs_min(max_sendmmsg, vlen);
int r0 = srs_sendmmsg(mmstfd, p, (unsigned int)vlen, 0, SRS_UTIME_NO_TIMEOUT); int r0 = srs_sendmmsg(stfd, p, (unsigned int)vlen, 0, SRS_UTIME_NO_TIMEOUT);
if (r0 != vlen) { if (r0 != vlen) {
srs_warn("sendmsg %d msgs, %d done", vlen, r0); srs_warn("sendmsg %d msgs, %d done", vlen, r0);
} }
@ -1707,6 +1715,7 @@ srs_error_t SrsRtcServer::cycle()
// Increase total messages. // Increase total messages.
nn_msgs += pos; nn_msgs += pos;
nn_msgs_max = srs_max(pos, nn_msgs_max);
pprint->elapse(); pprint->elapse();
if (pprint->can_print()) { if (pprint->can_print()) {
@ -1719,9 +1728,11 @@ srs_error_t SrsRtcServer::cycle()
pps_last = (int)((nn_msgs - nn_msgs_last) * SRS_UTIME_SECONDS / (srs_get_system_time() - time_last)); pps_last = (int)((nn_msgs - nn_msgs_last) * SRS_UTIME_SECONDS / (srs_get_system_time() - time_last));
} }
} }
srs_trace("-> RTC SEND %d by sendmmsg %d, total %" PRId64 ", pps %d/%d, sessions %d/%d",
pos, max_sendmmsg, nn_msgs, pps_average, pps_last, (int)map_username_session.size(), (int)map_id_session.size()); srs_trace("-> RTC #%d SEND %d by sendmmsg %d, pps %d/%d, sessions %d, schedule %" PRId64 "/%" PRId64 "/%"PRId64,
srs_netfd_fileno(stfd), pos, max_sendmmsg, pps_average, pps_last, (int)map_username_session.size(), nn_loop, nn_wait, nn_msgs_max);
nn_msgs_last = nn_msgs; time_last = srs_get_system_time(); nn_msgs_last = nn_msgs; time_last = srs_get_system_time();
nn_loop = nn_wait = nn_msgs_max = 0;
} }
} }

Loading…
Cancel
Save