From 2aa94c643cb3f25a377a78f391c18bb291cca449 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 10 Feb 2021 13:07:26 +0800 Subject: [PATCH] Refine server stat, extract to hybrid server stat --- trunk/src/app/srs_app_hourglass.hpp | 5 ++- trunk/src/app/srs_app_hybrid.cpp | 53 ++++++++++++++++++++++++++++ trunk/src/app/srs_app_hybrid.hpp | 9 ++++- trunk/src/app/srs_app_rtc_server.cpp | 10 ++---- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/trunk/src/app/srs_app_hourglass.hpp b/trunk/src/app/srs_app_hourglass.hpp index e75e040a6..a9f781268 100644 --- a/trunk/src/app/srs_app_hourglass.hpp +++ b/trunk/src/app/srs_app_hourglass.hpp @@ -29,6 +29,7 @@ #include #include +#include class SrsCoroutine; @@ -70,6 +71,7 @@ public: class SrsHourGlass : virtual public ISrsCoroutineHandler { private: + std::string label_; SrsCoroutine* trd; ISrsHourGlass* handler; srs_utime_t _resolution; @@ -81,7 +83,8 @@ private: // for each cycle, we increase it with a resolution. srs_utime_t total_elapse; public: - SrsHourGlass(ISrsHourGlass* h, srs_utime_t resolution); + // TODO: FIMXE: Refine to SrsHourGlass(std::string label); + SrsHourGlass(std::string label, ISrsHourGlass* h, srs_utime_t resolution); virtual ~SrsHourGlass(); public: // Start or stop the hourglass. diff --git a/trunk/src/app/srs_app_hybrid.cpp b/trunk/src/app/srs_app_hybrid.cpp index 6a8d3100c..528a5184f 100644 --- a/trunk/src/app/srs_app_hybrid.cpp +++ b/trunk/src/app/srs_app_hybrid.cpp @@ -27,9 +27,18 @@ #include #include #include +#include using namespace std; +extern SrsPps* _srs_pps_cids_get; +extern SrsPps* _srs_pps_cids_set; + +extern SrsPps* _srs_pps_timer; +extern SrsPps* _srs_pps_pub; +extern SrsPps* _srs_pps_conn; +extern SrsPps* _srs_pps_dispose; + ISrsHybridServer::ISrsHybridServer() { } @@ -109,6 +118,7 @@ SrsServer* SrsServerAdapter::instance() SrsHybridServer::SrsHybridServer() { + timer_ = NULL; } SrsHybridServer::~SrsHybridServer() @@ -135,6 +145,10 @@ srs_error_t SrsHybridServer::initialize() return srs_error_wrap(err, "initialize st failed"); } + if ((err = setup_ticks()) != srs_success) { + return srs_error_wrap(err, "tick"); + } + vector::iterator it; for (it = servers.begin(); it != servers.end(); ++it) { ISrsHybridServer* server = *it; @@ -185,5 +199,44 @@ SrsServerAdapter* SrsHybridServer::srs() return NULL; } +srs_error_t SrsHybridServer::setup_ticks() +{ + srs_error_t err = srs_success; + + timer_ = new SrsHourGlass("hybrid", this, 1 * SRS_UTIME_SECONDS); + + if ((err = timer_->tick(1, 5 * SRS_UTIME_SECONDS)) != srs_success) { + return srs_error_wrap(err, "tick"); + } + + if ((err = timer_->start()) != srs_success) { + return srs_error_wrap(err, "start"); + } + + return err; +} + +srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t tick) +{ + srs_error_t err = srs_success; + + // Show statistics for RTC server. + SrsProcSelfStat* u = srs_get_self_proc_stat(); + // Resident Set Size: number of pages the process has in real memory. + int memory = (int)(u->rss * 4 / 1024); + + _srs_pps_cids_get->update(); _srs_pps_cids_set->update(); + _srs_pps_timer->update(); _srs_pps_pub->update(); _srs_pps_conn->update(); _srs_pps_dispose->update(); + + srs_trace("Hybrid cpu=%.2f%%,%dMB, cid=%d,%d, timer=%d,%d,%d, free=%d", + u->percent * 100, memory, + _srs_pps_cids_get->r10s(), _srs_pps_cids_set->r10s(), + _srs_pps_timer->r10s(), _srs_pps_pub->r10s(), _srs_pps_conn->r10s(), + _srs_pps_dispose->r10s() + ); + + return err; +} + SrsHybridServer* _srs_hybrid = new SrsHybridServer(); diff --git a/trunk/src/app/srs_app_hybrid.hpp b/trunk/src/app/srs_app_hybrid.hpp index 0f995afe4..7e988fe26 100644 --- a/trunk/src/app/srs_app_hybrid.hpp +++ b/trunk/src/app/srs_app_hybrid.hpp @@ -28,6 +28,8 @@ #include +#include + class SrsServer; // The hibrid server interfaces, we could register many servers. @@ -62,10 +64,11 @@ public: }; // The hybrid server manager. -class SrsHybridServer +class SrsHybridServer : public ISrsHourGlass { private: std::vector servers; + SrsHourGlass* timer_; public: SrsHybridServer(); virtual ~SrsHybridServer(); @@ -77,6 +80,10 @@ public: virtual void stop(); public: virtual SrsServerAdapter* srs(); +// interface ISrsHourGlass +private: + virtual srs_error_t setup_ticks(); + virtual srs_error_t notify(int event, srs_utime_t interval, srs_utime_t tick); }; extern SrsHybridServer* _srs_hybrid; diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index 6f5df2cd4..1573c73ff 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -662,11 +662,6 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic return err; } - // Show statistics for RTC server. - SrsProcSelfStat* u = srs_get_self_proc_stat(); - // Resident Set Size: number of pages the process has in real memory. - int memory = (int)(u->rss * 4 / 1024); - // Update the pps stat for UDP socket and adddresses. _srs_pps_pkts->update(); _srs_pps_addrs->update(); _srs_pps_fast_addrs->update(); _srs_pps_ids->update(); _srs_pps_fids->update(); _srs_pps_fids_level0->update(); @@ -676,12 +671,11 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic _srs_pps_rnack->update(); _srs_pps_rnack2->update(); // TODO: FIXME: Show more data for RTC server. - srs_trace("RTC: Server conns=%u, cpu=%.2f%%, rss=%dMB, pkts=%d, addrs=%d,%d, fid=%d,%d,%d, rtcp=%d,%d,%d, timer=%d,%d,%d, snk=%d,%d,%d,%d, rnk=%d,%d", - nn_rtc_conns, u->percent * 100, memory, + srs_trace("RTC: Server conns=%u, pkts=%d, addrs=%d,%d, fid=%d,%d,%d, rtcp=%d,%d,%d, snk=%d,%d,%d,%d, rnk=%d,%d", + nn_rtc_conns, _srs_pps_pkts->r10s(), _srs_pps_addrs->r10s(), _srs_pps_fast_addrs->r10s(), _srs_pps_ids->r10s(), _srs_pps_fids->r10s(), _srs_pps_fids_level0->r10s(), _srs_pps_pli->r10s(), _srs_pps_twcc->r10s(), _srs_pps_rr->r10s(), - _srs_pps_timer->r10s(), _srs_pps_pub->r10s(), _srs_pps_conn->r10s(), _srs_pps_snack->r10s(), _srs_pps_snack2->r10s(), _srs_pps_sanack->r10s(), _srs_pps_svnack->r10s(), _srs_pps_rnack->r10s(), _srs_pps_rnack2->r10s() );