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

RTC: Eliminate unused stat API

This commit is contained in:
winlin 2021-05-14 08:56:41 +08:00
parent 06f7d7d11b
commit cd45750c9d
8 changed files with 1 additions and 406 deletions

View file

@ -1303,95 +1303,6 @@ srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
return srs_api_response(w, r, obj->dumps());
}
SrsGoApiPerf::SrsGoApiPerf()
{
}
SrsGoApiPerf::~SrsGoApiPerf()
{
}
srs_error_t SrsGoApiPerf::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
srs_error_t err = srs_success;
SrsJsonObject* obj = SrsJsonAny::object();
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
SrsStatistic* stat = SrsStatistic::instance();
string target = r->query_get("target");
string reset = r->query_get("reset");
srs_trace("query target=%s, reset=%s, rtc_stat_enabled=%d", target.c_str(), reset.c_str(),
_srs_config->get_rtc_server_perf_stat());
if (true) {
SrsJsonObject* p = SrsJsonAny::object();
data->set("query", p);
p->set("target", SrsJsonAny::str(target.c_str()));
p->set("reset", SrsJsonAny::str(reset.c_str()));
p->set("help", SrsJsonAny::str("?target=avframes|rtc|rtp|writev_iovs|bytes"));
p->set("help2", SrsJsonAny::str("?reset=all"));
}
if (!reset.empty()) {
stat->reset_perf();
return srs_api_response(w, r, obj->dumps());
}
if (target.empty() || target == "avframes") {
SrsJsonObject* p = SrsJsonAny::object();
data->set("avframes", p);
if ((err = stat->dumps_perf_msgs(p)) != srs_success) {
int code = srs_error_code(err); srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
}
if (target.empty() || target == "rtc") {
SrsJsonObject* p = SrsJsonAny::object();
data->set("rtc", p);
if ((err = stat->dumps_perf_rtc_packets(p)) != srs_success) {
int code = srs_error_code(err); srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
}
if (target.empty() || target == "rtp") {
SrsJsonObject* p = SrsJsonAny::object();
data->set("rtp", p);
if ((err = stat->dumps_perf_rtp_packets(p)) != srs_success) {
int code = srs_error_code(err); srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
}
if (target.empty() || target == "writev_iovs") {
SrsJsonObject* p = SrsJsonAny::object();
data->set("writev_iovs", p);
if ((err = stat->dumps_perf_writev_iovs(p)) != srs_success) {
int code = srs_error_code(err); srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
}
if (target.empty() || target == "bytes") {
SrsJsonObject* p = SrsJsonAny::object();
data->set("bytes", p);
if ((err = stat->dumps_perf_bytes(p)) != srs_success) {
int code = srs_error_code(err); srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
}
return srs_api_response(w, r, obj->dumps());
}
SrsGoApiError::SrsGoApiError()
{
}

View file

@ -213,15 +213,6 @@ public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiPerf : public ISrsHttpHandler
{
public:
SrsGoApiPerf();
virtual ~SrsGoApiPerf();
public:
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
class SrsGoApiError : public ISrsHttpHandler
{
public:

View file

@ -190,9 +190,6 @@ SrsQueueRecvThread::~SrsQueueRecvThread()
srs_error_t SrsQueueRecvThread::start()
{
srs_error_t err = srs_success;
SrsStatistic* stat = SrsStatistic::instance();
rtmp->set_perf(stat);
if ((err = trd.start()) != srs_success) {
return srs_error_wrap(err, "queue recv thread");

View file

@ -997,9 +997,6 @@ srs_error_t SrsServer::http_handle()
if ((err = http_api_mux->handle("/api/v1/clusters", new SrsGoApiClusters())) != srs_success) {
return srs_error_wrap(err, "handle clusters");
}
if ((err = http_api_mux->handle("/api/v1/perf", new SrsGoApiPerf())) != srs_success) {
return srs_error_wrap(err, "handle perf");
}
#ifdef SRS_GB28181
if ((err = http_api_mux->handle("/api/v1/gb28181", new SrsGoApiGb28181())) != srs_success) {
return srs_error_wrap(err, "handle raw");

View file

@ -229,27 +229,6 @@ srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj)
return err;
}
SrsStatisticCategory::SrsStatisticCategory()
{
nn = 0;
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
g = 0;
h = 0;
i = 0;
j = 0;
}
SrsStatisticCategory::~SrsStatisticCategory()
{
}
SrsStatistic* SrsStatistic::_instance = NULL;
SrsStatistic::SrsStatistic()
@ -259,12 +238,6 @@ SrsStatistic::SrsStatistic()
clk = new SrsWallClock();
kbps = new SrsKbps(clk);
kbps->set_io(NULL, NULL);
perf_iovs = new SrsStatisticCategory();
perf_msgs = new SrsStatisticCategory();
perf_rtp = new SrsStatisticCategory();
perf_rtc = new SrsStatisticCategory();
perf_bytes = new SrsStatisticCategory();
}
SrsStatistic::~SrsStatistic()
@ -298,12 +271,6 @@ SrsStatistic::~SrsStatistic()
rvhosts.clear();
streams.clear();
rstreams.clear();
srs_freep(perf_iovs);
srs_freep(perf_msgs);
srs_freep(perf_rtp);
srs_freep(perf_rtc);
srs_freep(perf_bytes);
}
SrsStatistic* SrsStatistic::instance()
@ -587,157 +554,6 @@ srs_error_t SrsStatistic::dumps_clients(SrsJsonArray* arr, int start, int count)
return err;
}
void SrsStatistic::perf_on_msgs(int nb_msgs)
{
perf_on_packets(perf_msgs, nb_msgs);
}
srs_error_t SrsStatistic::dumps_perf_msgs(SrsJsonObject* obj)
{
return dumps_perf(perf_msgs, obj);
}
void SrsStatistic::perf_on_rtc_packets(int nb_packets)
{
perf_on_packets(perf_rtc, nb_packets);
}
srs_error_t SrsStatistic::dumps_perf_rtc_packets(SrsJsonObject* obj)
{
return dumps_perf(perf_rtc, obj);
}
void SrsStatistic::perf_on_rtp_packets(int nb_packets)
{
perf_on_packets(perf_rtp, nb_packets);
}
srs_error_t SrsStatistic::dumps_perf_rtp_packets(SrsJsonObject* obj)
{
return dumps_perf(perf_rtp, obj);
}
void SrsStatistic::perf_on_writev_iovs(int nb_iovs)
{
perf_on_packets(perf_iovs, nb_iovs);
}
srs_error_t SrsStatistic::dumps_perf_writev_iovs(SrsJsonObject* obj)
{
return dumps_perf(perf_iovs, obj);
}
void SrsStatistic::perf_on_rtc_bytes(int nn_bytes, int nn_rtp_bytes, int nn_padding)
{
// a: AVFrame bytes.
// b: RTC bytes.
// c: RTC paddings.
perf_bytes->a += nn_bytes;
perf_bytes->b += nn_rtp_bytes;
perf_bytes->c += nn_padding;
perf_bytes->nn += nn_rtp_bytes;
}
srs_error_t SrsStatistic::dumps_perf_bytes(SrsJsonObject* obj)
{
obj->set("avframe_bytes", SrsJsonAny::integer(perf_bytes->a));
obj->set("rtc_bytes", SrsJsonAny::integer(perf_bytes->b));
obj->set("rtc_padding", SrsJsonAny::integer(perf_bytes->c));
obj->set("nn", SrsJsonAny::integer(perf_bytes->nn));
return srs_success;
}
void SrsStatistic::reset_perf()
{
srs_freep(perf_iovs);
srs_freep(perf_msgs);
srs_freep(perf_rtp);
srs_freep(perf_rtc);
srs_freep(perf_bytes);
perf_iovs = new SrsStatisticCategory();
perf_msgs = new SrsStatisticCategory();
perf_rtp = new SrsStatisticCategory();
perf_rtc = new SrsStatisticCategory();
perf_bytes = new SrsStatisticCategory();
}
void SrsStatistic::perf_on_packets(SrsStatisticCategory* p, int nb_msgs)
{
// The range for stat:
// 2, 3, 5, 9, 16, 32, 64, 128, 256
// that is:
// a: <2
// b: <3
// c: <5
// d: <9
// e: <16
// f: <32
// g: <64
// h: <128
// i: <256
// j: >=256
if (nb_msgs < 2) {
p->a++;
} else if (nb_msgs < 3) {
p->b++;
} else if (nb_msgs < 5) {
p->c++;
} else if (nb_msgs < 9) {
p->d++;
} else if (nb_msgs < 16) {
p->e++;
} else if (nb_msgs < 32) {
p->f++;
} else if (nb_msgs < 64) {
p->g++;
} else if (nb_msgs < 128) {
p->h++;
} else if (nb_msgs < 256) {
p->i++;
} else {
p->j++;
}
p->nn += nb_msgs;
}
srs_error_t SrsStatistic::dumps_perf(SrsStatisticCategory* p, SrsJsonObject* obj)
{
srs_error_t err = srs_success;
// The range for stat:
// 2, 3, 5, 9, 16, 32, 64, 128, 256
// that is:
// a: <2
// b: <3
// c: <5
// d: <9
// e: <16
// f: <32
// g: <64
// h: <128
// i: <256
// j: >=256
if (p->a) obj->set("lt_2", SrsJsonAny::integer(p->a));
if (p->b) obj->set("lt_3", SrsJsonAny::integer(p->b));
if (p->c) obj->set("lt_5", SrsJsonAny::integer(p->c));
if (p->d) obj->set("lt_9", SrsJsonAny::integer(p->d));
if (p->e) obj->set("lt_16", SrsJsonAny::integer(p->e));
if (p->f) obj->set("lt_32", SrsJsonAny::integer(p->f));
if (p->g) obj->set("lt_64", SrsJsonAny::integer(p->g));
if (p->h) obj->set("lt_128", SrsJsonAny::integer(p->h));
if (p->i) obj->set("lt_256", SrsJsonAny::integer(p->i));
if (p->j) obj->set("gt_256", SrsJsonAny::integer(p->j));
obj->set("nn", SrsJsonAny::integer(p->nn));
return err;
}
SrsStatisticVhost* SrsStatistic::create_vhost(SrsRequest* req)
{
SrsStatisticVhost* vhost = NULL;

View file

@ -124,28 +124,7 @@ public:
virtual srs_error_t dumps(SrsJsonObject* obj);
};
class SrsStatisticCategory
{
public:
uint64_t nn;
public:
uint64_t a;
uint64_t b;
uint64_t c;
uint64_t d;
uint64_t e;
public:
uint64_t f;
uint64_t g;
uint64_t h;
uint64_t i;
uint64_t j;
public:
SrsStatisticCategory();
virtual ~SrsStatisticCategory();
};
class SrsStatistic : public ISrsProtocolPerf
class SrsStatistic
{
private:
static SrsStatistic *_instance;
@ -169,12 +148,6 @@ private:
// The server total kbps.
SrsKbps* kbps;
SrsWallClock* clk;
// The perf stat for mw(merged write).
SrsStatisticCategory* perf_iovs;
SrsStatisticCategory* perf_msgs;
SrsStatisticCategory* perf_rtp;
SrsStatisticCategory* perf_rtc;
SrsStatisticCategory* perf_bytes;
private:
SrsStatistic();
virtual ~SrsStatistic();
@ -231,35 +204,6 @@ public:
// @param start the start index, from 0.
// @param count the max count of clients to dump.
virtual srs_error_t dumps_clients(SrsJsonArray* arr, int start, int count);
public:
// Stat for packets merged written, nb_msgs is the number of RTMP messages.
// For example, publish by FFMPEG, Audio and Video frames.
virtual void perf_on_msgs(int nb_msgs);
virtual srs_error_t dumps_perf_msgs(SrsJsonObject* obj);
public:
// Stat for packets merged written, nb_packets is the number of RTC packets.
// For example, a RTMP/AAC audio packet maybe transcoded to two RTC/opus packets.
virtual void perf_on_rtc_packets(int nb_packets);
virtual srs_error_t dumps_perf_rtc_packets(SrsJsonObject* obj);
public:
// Stat for packets merged written, nb_packets is the number of RTP packets.
// For example, a RTC/opus packet maybe package to three RTP packets.
virtual void perf_on_rtp_packets(int nb_packets);
virtual srs_error_t dumps_perf_rtp_packets(SrsJsonObject* obj);
public:
// Stat for TCP writev, nb_iovs is the total number of iovec.
virtual void perf_on_writev_iovs(int nb_iovs);
virtual srs_error_t dumps_perf_writev_iovs(SrsJsonObject* obj);
public:
// Stat for bytes, nn_bytes is the size of bytes, nb_padding is padding bytes.
virtual void perf_on_rtc_bytes(int nn_bytes, int nn_rtp_bytes, int nn_padding);
virtual srs_error_t dumps_perf_bytes(SrsJsonObject* obj);
public:
// Reset all perf stat data.
virtual void reset_perf();
private:
virtual void perf_on_packets(SrsStatisticCategory* p, int nb_msgs);
virtual srs_error_t dumps_perf(SrsStatisticCategory* p, SrsJsonObject* obj);
private:
virtual SrsStatisticVhost* create_vhost(SrsRequest* req);
virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req);

View file

@ -217,14 +217,6 @@ srs_error_t SrsPacket::encode_packet(SrsBuffer* stream)
return srs_error_new(ERROR_SYSTEM_PACKET_INVALID, "encode");
}
ISrsProtocolPerf::ISrsProtocolPerf()
{
}
ISrsProtocolPerf::~ISrsProtocolPerf()
{
}
SrsProtocol::AckWindowSize::AckWindowSize()
{
window = 0;
@ -264,7 +256,6 @@ SrsProtocol::SrsProtocol(ISrsProtocolReadWriter* io)
}
out_c0c3_caches = new char[SRS_CONSTS_C0C3_HEADERS_MAX];
perf = NULL;
}
SrsProtocol::~SrsProtocol()
@ -312,11 +303,6 @@ void SrsProtocol::set_auto_response(bool v)
auto_response_when_recv = v;
}
void SrsProtocol::set_perf(ISrsProtocolPerf* v)
{
perf = v;
}
srs_error_t SrsProtocol::manual_response_flush()
{
srs_error_t err = srs_success;
@ -463,11 +449,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg
int c0c3_cache_index = 0;
char* c0c3_cache = out_c0c3_caches + c0c3_cache_index;
// How many messages are merged in written.
int nb_msgs_merged_written = 0;
// How many bytes of messages are merged in written.
int bytes_msgs_merged_written = 0;
// try to send use the c0c3 header cache,
// if cache is consumed, try another loop.
for (int i = 0; i < nb_msgs; i++) {
@ -481,10 +462,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg
if (!msg->payload || msg->size <= 0) {
continue;
}
// Increase the perf stat data.
nb_msgs_merged_written++;
bytes_msgs_merged_written += msg->size;
// p set to current write position,
// it's ok when payload is NULL and size is 0.
@ -545,13 +522,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg
if ((err = do_iovs_send(out_iovs, iov_index)) != srs_success) {
return srs_error_wrap(err, "send iovs");
}
// Notify about perf stat.
if (perf) {
perf->perf_on_msgs(nb_msgs_merged_written);
perf->perf_on_writev_iovs(iov_index);
nb_msgs_merged_written = 0; bytes_msgs_merged_written = 0;
}
// reset caches, while these cache ensure
// atleast we can sendout a chunk.
@ -575,13 +545,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg
return srs_error_wrap(err, "send iovs");
}
// Notify about perf stat.
if (perf) {
perf->perf_on_msgs(nb_msgs_merged_written);
perf->perf_on_writev_iovs(iov_index);
nb_msgs_merged_written = 0; bytes_msgs_merged_written = 0;
}
return err;
#else
// try to send use the c0c3 header cache,
@ -2251,11 +2214,6 @@ void SrsRtmpServer::set_auto_response(bool v)
protocol->set_auto_response(v);
}
void SrsRtmpServer::set_perf(ISrsProtocolPerf* v)
{
protocol->set_perf(v);
}
#ifdef SRS_PERF_MERGED_READ
void SrsRtmpServer::set_merge_read(bool v, IMergeReadHandler* handler)
{

View file

@ -147,19 +147,6 @@ protected:
virtual srs_error_t encode_packet(SrsBuffer* stream);
};
// The performance statistic data collect.
class ISrsProtocolPerf
{
public:
ISrsProtocolPerf();
virtual ~ISrsProtocolPerf();
public:
// Stat for packets merged written, nb_msgs is the number of RTMP messages,
virtual void perf_on_msgs(int nb_msgs) = 0;
// Stat for TCP writev, nb_iovs is the total number of iovec.
virtual void perf_on_writev_iovs(int nb_iovs) = 0;
};
// The protocol provides the rtmp-message-protocol services,
// To recv RTMP message from RTMP chunk stream,
// and to send out RTMP message over RTMP chunk stream.
@ -181,8 +168,6 @@ private:
private:
// The underlayer socket object, send/recv bytes.
ISrsProtocolReadWriter* skt;
// The performance stat handler.
ISrsProtocolPerf* perf;
// The requests sent out, used to build the response.
// key: transactionId
// value: the request command name
@ -242,8 +227,6 @@ public:
// @param v, whether auto response message when recv message.
// @see: https://github.com/ossrs/srs/issues/217
virtual void set_auto_response(bool v);
// Set the performance stat handler.
virtual void set_perf(ISrsProtocolPerf* v);
// Flush for manual response when the auto response is disabled
// by set_auto_response(false), we default use auto response, so donot
// need to call this api(the protocol sdk will auto send message).
@ -648,8 +631,6 @@ public:
// @param v, whether auto response message when recv message.
// @see: https://github.com/ossrs/srs/issues/217
virtual void set_auto_response(bool v);
// Set the performance stat handler.
virtual void set_perf(ISrsProtocolPerf* v);
#ifdef SRS_PERF_MERGED_READ
// To improve read performance, merge some packets then read,
// When it on and read small bytes, we sleep to wait more data.,