Perf: Refine the stat

pull/2204/head
winlin 4 years ago
parent 919107c674
commit c00d286344

@ -122,6 +122,13 @@ SrsPps* _srs_pps_thread_yield = new SrsPps();
SrsPps* _srs_pps_thread_yield2 = new SrsPps();
#endif
extern SrsPps* _srs_pps_objs_rtps;
extern SrsPps* _srs_pps_objs_rraw;
extern SrsPps* _srs_pps_objs_rfua;
extern SrsPps* _srs_pps_objs_rbuf;
extern SrsPps* _srs_pps_objs_msgs;
extern SrsPps* _srs_pps_objs_rothers;
ISrsHybridServer::ISrsHybridServer()
{
}
@ -446,13 +453,25 @@ srs_error_t SrsHybridServer::notify(int event, srs_utime_t interval, srs_utime_t
}
#endif
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s%s",
string objs_desc;
_srs_pps_objs_rtps->update(); _srs_pps_objs_rraw->update(); _srs_pps_objs_rfua->update(); _srs_pps_objs_rbuf->update(); _srs_pps_objs_msgs->update(); _srs_pps_objs_rothers->update();
if (_srs_pps_objs_rtps->r10s() || _srs_pps_objs_rraw->r10s() || _srs_pps_objs_rfua->r10s() || _srs_pps_objs_rbuf->r10s() || _srs_pps_objs_msgs->r10s() || _srs_pps_objs_rothers->r10s()) {
snprintf(buf, sizeof(buf), ", objs=%d,%d,%d,%d,%d,%d", _srs_pps_objs_rtps->r10s(), _srs_pps_objs_rraw->r10s(), _srs_pps_objs_rfua->r10s(), _srs_pps_objs_msgs->r10s(), _srs_pps_objs_rothers->r10s(), _srs_pps_objs_rbuf->r10s());
objs_desc = buf;
}
string cache_desc;
if (true) {
snprintf(buf, sizeof(buf), ", cache=%d,%d,%d,%d", _srs_rtp_cache->size(), _srs_rtp_raw_cache->size(), _srs_rtp_fua_cache->size(), _srs_rtp_msg_cache->size());
cache_desc = buf;
}
srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s%s%s%s",
u->percent * 100, memory,
cid_desc.c_str(), timer_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(),
thread_desc.c_str(),
free_desc.c_str()
thread_desc.c_str(), free_desc.c_str(), objs_desc.c_str(), cache_desc.c_str()
);
return err;

@ -75,12 +75,6 @@ extern SrsPps* _srs_pps_rnack2;
extern SrsPps* _srs_pps_rhnack;
extern SrsPps* _srs_pps_rmnack;
extern SrsPps* _srs_pps_objs_rtps;
extern SrsPps* _srs_pps_objs_rraw;
extern SrsPps* _srs_pps_objs_rfua;
extern SrsPps* _srs_pps_objs_rbuf;
extern SrsPps* _srs_pps_objs_msgs;
SrsRtcBlackhole::SrsRtcBlackhole()
{
blackhole = false;
@ -690,13 +684,6 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
}
static char buf[128];
string objs_desc;
_srs_pps_objs_rtps->update(); _srs_pps_objs_rraw->update(); _srs_pps_objs_rfua->update(); _srs_pps_objs_rbuf->update(); _srs_pps_objs_msgs->update();
if (_srs_pps_objs_rtps->r10s() || _srs_pps_objs_rraw->r10s() || _srs_pps_objs_rfua->r10s() || _srs_pps_objs_rbuf->r10s() || _srs_pps_objs_msgs->r10s()) {
snprintf(buf, sizeof(buf), ", objs=%d,%d,%d,%d,%d", _srs_pps_objs_rtps->r10s(), _srs_pps_objs_rraw->r10s(), _srs_pps_objs_rfua->r10s(), _srs_pps_objs_rbuf->r10s(), _srs_pps_objs_msgs->r10s());
objs_desc = buf;
}
string rpkts_desc;
_srs_pps_rpkts->update(); _srs_pps_rrtps->update(); _srs_pps_rstuns->update(); _srs_pps_rrtcps->update();
if (_srs_pps_rpkts->r10s() || _srs_pps_rrtps->r10s() || _srs_pps_rstuns->r10s() || _srs_pps_rrtcps->r10s()) {
@ -746,9 +733,9 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
fid_desc = buf;
}
srs_trace("RTC: Server conns=%u%s%s%s%s%s%s%s%s",
srs_trace("RTC: Server conns=%u%s%s%s%s%s%s%s",
nn_rtc_conns,
rpkts_desc.c_str(), spkts_desc.c_str(), rtcp_desc.c_str(), snk_desc.c_str(), rnk_desc.c_str(), drop_desc.c_str(), fid_desc.c_str(), objs_desc.c_str()
rpkts_desc.c_str(), spkts_desc.c_str(), rtcp_desc.c_str(), snk_desc.c_str(), rnk_desc.c_str(), drop_desc.c_str(), fid_desc.c_str()
);
return err;

@ -39,6 +39,7 @@ using namespace std;
#include <srs_kernel_codec.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_kbps.hpp>
@ -286,10 +287,24 @@ void SrsSharedPtrMessage::wrap(char* payload, int size)
this->size = ptr->size;
}
void SrsSharedPtrMessage::unwrap()
{
if (ptr) {
if (ptr->shared_count == 0) {
srs_freep(ptr);
} else {
ptr->shared_count--;
ptr = NULL;
}
}
payload = NULL;
size = 0;
}
int SrsSharedPtrMessage::count()
{
srs_assert(ptr);
return ptr->shared_count;
return ptr? ptr->shared_count : 0;
}
bool SrsSharedPtrMessage::check(int stream_id)
@ -346,7 +361,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
{
srs_assert(ptr);
SrsSharedPtrMessage* copy = new SrsSharedPtrMessage();
SrsSharedPtrMessage* copy = _srs_rtp_msg_cache->allocate();
copy->ptr = ptr;
ptr->shared_count++;

@ -328,6 +328,8 @@ public:
// Create shared ptr message from RAW payload.
// @remark Note that the header is set to zero.
virtual void wrap(char* payload, int size);
// Decrease the reference, if the last one, free it.
void unwrap();
// Get current reference count.
// when this object created, count set to 0.
// if copy() this object, count increase 1.

@ -40,6 +40,7 @@ SrsPps* _srs_pps_objs_rtps = new SrsPps();
SrsPps* _srs_pps_objs_rraw = new SrsPps();
SrsPps* _srs_pps_objs_rfua = new SrsPps();
SrsPps* _srs_pps_objs_rbuf = new SrsPps();
SrsPps* _srs_pps_objs_rothers = new SrsPps();
/* @see https://tools.ietf.org/html/rfc1889#section-5.1
0 1 2 3
@ -819,26 +820,11 @@ SrsRtpPacket2::SrsRtpPacket2()
SrsRtpPacket2::~SrsRtpPacket2()
{
srs_freep(payload);
// Recyle the real owner of message, no other reference object.
if (shared_msg && shared_msg->count() == 0) {
_srs_rtp_msg_cache->recycle(shared_msg);
shared_msg = NULL;
} else {
srs_freep(shared_msg);
}
reuse();
}
bool SrsRtpPacket2::reset()
void SrsRtpPacket2::reuse()
{
nalu_type = SrsAvcNaluTypeReserved;
frame_type = SrsFrameTypeReserved;
cached_payload_size = 0;
decode_handler = NULL;
header.reset();
// Only recycle some common payloads.
SrsRtpRawPayload* raw_payload;
SrsRtpFUAPayload2* fua_payload;
@ -853,13 +839,27 @@ bool SrsRtpPacket2::reset()
srs_freep(payload);
}
// Recyle the real owner of message, no other reference object.
if (shared_msg && shared_msg->count() == 0) {
// Recycle the real owner of message, clear the reference.
if (shared_msg) {
if (shared_msg->count() > 0) {
shared_msg->unwrap();
}
_srs_rtp_msg_cache->recycle(shared_msg);
shared_msg = NULL;
} else {
srs_freep(shared_msg);
}
}
bool SrsRtpPacket2::reset()
{
nalu_type = SrsAvcNaluTypeReserved;
frame_type = SrsFrameTypeReserved;
cached_payload_size = 0;
decode_handler = NULL;
header.reset();
// Reset and reuse the payload and shared message.
reuse();
return true;
}
@ -1095,6 +1095,8 @@ SrsRtpRawNALUs::SrsRtpRawNALUs()
{
cursor = 0;
nn_bytes = 0;
++_srs_pps_objs_rothers->sugar;
}
SrsRtpRawNALUs::~SrsRtpRawNALUs()
@ -1232,6 +1234,8 @@ ISrsRtpPayloader* SrsRtpRawNALUs::copy()
SrsRtpSTAPPayload::SrsRtpSTAPPayload()
{
nri = (SrsAvcNaluType)0;
++_srs_pps_objs_rothers->sugar;
}
SrsRtpSTAPPayload::~SrsRtpSTAPPayload()
@ -1381,7 +1385,7 @@ SrsRtpFUAPayload::SrsRtpFUAPayload()
start = end = false;
nri = nalu_type = (SrsAvcNaluType)0;
++_srs_pps_objs_rfua->sugar;
++_srs_pps_objs_rothers->sugar;
}
SrsRtpFUAPayload::~SrsRtpFUAPayload()

@ -302,6 +302,8 @@ private:
public:
SrsRtpPacket2();
virtual ~SrsRtpPacket2();
private:
void reuse();
public:
// Reset the object to reuse it.
virtual bool reset();
@ -356,6 +358,9 @@ public:
bool enabled() {
return enabled_;
}
int size() {
return (int)cache_objs_.size();
}
// Try to allocate from cache, create new object if no cache.
T* allocate() {
while (true) {

Loading…
Cancel
Save