Skip to content

Commit

Permalink
Stat bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 16, 2020
1 parent b7dab00 commit 5ad99b1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
11 changes: 10 additions & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ srs_error_t SrsGoApiPerf::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*

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|gso|writev_iovs|sendmmsg"));
p->set("help", SrsJsonAny::str("?target=avframes|rtc|rtp|gso|writev_iovs|sendmmsg|bytes"));
p->set("help2", SrsJsonAny::str("?reset=all"));
}

Expand Down Expand Up @@ -1687,6 +1687,15 @@ srs_error_t SrsGoApiPerf::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
}
}

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());
}

Expand Down
22 changes: 13 additions & 9 deletions trunk/src/app/srs_app_rtc_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ SrsRtcPackets::SrsRtcPackets()
nn_rtp_pkts = 0;
nn_audios = nn_extras = 0;
nn_videos = nn_samples = 0;
nn_paddings = 0;
nn_padding_bytes = nn_paddings = 0;

cursor = 0;
}
Expand Down Expand Up @@ -504,7 +504,7 @@ void SrsRtcPackets::reset(bool gso, bool merge_nalus)
nn_rtp_pkts = 0;
nn_audios = nn_extras = 0;
nn_videos = nn_samples = 0;
nn_paddings = 0;
nn_padding_bytes = nn_paddings = 0;

cursor = 0;
}
Expand Down Expand Up @@ -733,18 +733,20 @@ srs_error_t SrsRtcSenderThread::cycle()
stat->perf_on_rtp_packets(pkts.size());
// Stat the RTP packets going into kernel.
stat->perf_on_gso_packets(pkts.nn_rtp_pkts);
// Stat the bytes and paddings.
stat->perf_on_rtc_bytes(pkts.nn_bytes, pkts.nn_padding_bytes);
#if defined(SRS_DEBUG)
srs_trace("RTC PLAY done, msgs %d/%d, rtp %d, gso %d, %d audios, %d extras, %d videos, %d samples, %d bytes",
srs_trace("RTC PLAY done, msgs %d/%d, rtp %d, gso %d, %d audios, %d extras, %d videos, %d samples, %d/%d bytes",
msg_count, nn_rtc_packets, pkts.size(), pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos,
pkts.nn_samples, pkts.nn_bytes);
pkts.nn_samples, pkts.nn_bytes, pkts.nn_padding_bytes);
#endif

pprint->elapse();
if (pprint->can_print()) {
// TODO: FIXME: Print stat like frame/s, packet/s, loss_packets.
srs_trace("-> RTC PLAY %d msgs, %d/%d packets, %d audios, %d extras, %d videos, %d samples, %d bytes, %d pad",
srs_trace("-> RTC PLAY %d msgs, %d/%d packets, %d audios, %d extras, %d videos, %d samples, %d/%d bytes, %d pad",
msg_count, pkts.size(), pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos,
pkts.nn_samples, pkts.nn_bytes, pkts.nn_paddings);
pkts.nn_samples, pkts.nn_bytes, pkts.nn_padding_bytes, pkts.nn_paddings);
}
}
}
Expand Down Expand Up @@ -965,6 +967,7 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
packet->set_padding(padding);
nn_packet += padding;
packets.nn_paddings++;
packets.nn_padding_bytes += padding;
}
}

Expand Down Expand Up @@ -1128,8 +1131,9 @@ srs_error_t SrsRtcSenderThread::send_packets_gso(SrsUdpMuxSocket* skt, SrsRtcPac
}

#if defined(SRS_DEBUG)
srs_trace("#%d, RTC PLAY summary, rtp %d/%d, videos %d/%d, audios %d/%d, pad %d", packets.debug_id, packets.size(),
packets.nn_rtp_pkts, packets.nn_videos, packets.nn_samples, packets.nn_audios, packets.nn_extras, packets.nn_paddings);
srs_trace("#%d, RTC PLAY summary, rtp %d/%d, videos %d/%d, audios %d/%d, pad %d/%d", packets.debug_id, packets.size(),
packets.nn_rtp_pkts, packets.nn_videos, packets.nn_samples, packets.nn_audios, packets.nn_extras, packets.nn_paddings,
packets.nn_padding_bytes);
#endif

return err;
Expand Down Expand Up @@ -1971,7 +1975,7 @@ srs_error_t SrsUdpMuxSender::cycle()
srs_warn("sendmmsg %d msgs, %d done", vlen, r0);
}

stat->perf_sendmmsg_on_packets(vlen);
stat->perf_on_sendmmsg_packets(vlen);
}
}

Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ class SrsRtcPackets
// Debug id.
uint32_t debug_id;
#endif
public:
// The total bytes of RTP packets.
int nn_bytes;
// The total padded bytes.
int nn_padding_bytes;
public:
// The RTP packets send out by sendmmsg or sendmsg. Note that if many packets group to
// one msghdr by GSO, it's only one RTP packet, because we only send once.
int nn_rtp_pkts;
Expand Down
26 changes: 25 additions & 1 deletion trunk/src/app/srs_app_statistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ SrsStatistic::SrsStatistic()
perf_gso = new SrsStatisticCategory();
perf_rtp = new SrsStatisticCategory();
perf_rtc = new SrsStatisticCategory();
perf_bytes = new SrsStatisticCategory();
}

SrsStatistic::~SrsStatistic()
Expand Down Expand Up @@ -311,6 +312,7 @@ SrsStatistic::~SrsStatistic()
srs_freep(perf_gso);
srs_freep(perf_rtp);
srs_freep(perf_rtc);
srs_freep(perf_bytes);
}

SrsStatistic* SrsStatistic::instance()
Expand Down Expand Up @@ -641,7 +643,7 @@ srs_error_t SrsStatistic::dumps_perf_writev_iovs(SrsJsonObject* obj)
return dumps_perf(perf_iovs, obj);
}

void SrsStatistic::perf_sendmmsg_on_packets(int nb_packets)
void SrsStatistic::perf_on_sendmmsg_packets(int nb_packets)
{
perf_on_packets(perf_sendmmsg, nb_packets);
}
Expand All @@ -651,6 +653,26 @@ srs_error_t SrsStatistic::dumps_perf_sendmmsg(SrsJsonObject* obj)
return dumps_perf(perf_sendmmsg, obj);
}

void SrsStatistic::perf_on_rtc_bytes(int nn_bytes, int nn_padding)
{
// a: RTC bytes.
// b: RTC paddings.
perf_bytes->a += nn_bytes;
perf_bytes->b += nn_padding;

perf_bytes->nn += nn_bytes + nn_padding;
}

srs_error_t SrsStatistic::dumps_perf_bytes(SrsJsonObject* obj)
{
obj->set("rtc_bytes", SrsJsonAny::integer(perf_bytes->a));
obj->set("rtc_padding", SrsJsonAny::integer(perf_bytes->b));

obj->set("nn", SrsJsonAny::integer(perf_bytes->nn));

return srs_success;
}

void SrsStatistic::reset_perf()
{
srs_freep(perf_iovs);
Expand All @@ -659,13 +681,15 @@ void SrsStatistic::reset_perf()
srs_freep(perf_gso);
srs_freep(perf_rtp);
srs_freep(perf_rtc);
srs_freep(perf_bytes);

perf_iovs = new SrsStatisticCategory();
perf_msgs = new SrsStatisticCategory();
perf_sendmmsg = new SrsStatisticCategory();
perf_gso = new SrsStatisticCategory();
perf_rtp = new SrsStatisticCategory();
perf_rtc = new SrsStatisticCategory();
perf_bytes = new SrsStatisticCategory();
}

void SrsStatistic::perf_on_packets(SrsStatisticCategory* p, int nb_msgs)
Expand Down
10 changes: 6 additions & 4 deletions trunk/src/app/srs_app_statistic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class SrsStatistic : public ISrsProtocolPerf
SrsStatisticCategory* perf_gso;
SrsStatisticCategory* perf_rtp;
SrsStatisticCategory* perf_rtc;
SrsStatisticCategory* perf_bytes;
private:
SrsStatistic();
virtual ~SrsStatistic();
Expand Down Expand Up @@ -245,23 +246,24 @@ class SrsStatistic : public ISrsProtocolPerf
// 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);
// Dumps the perf statistic data for RTP packets, for performance analysis.
virtual srs_error_t dumps_perf_rtp_packets(SrsJsonObject* obj);
public:
// Stat for packets UDP GSO, nb_packets is the merged RTP packets.
// For example, three RTP/audio packets maybe GSO to one msghdr.
virtual void perf_on_gso_packets(int nb_packets);
// Dumps the perf statistic data for UDP GSO, for performance analysis.
virtual srs_error_t dumps_perf_gso(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 packets UDP sendmmsg, nb_packets is the vlen for sendmmsg.
virtual void perf_sendmmsg_on_packets(int nb_packets);
// Dumps the perf statistic data for UDP sendmmsg, for performance analysis.
virtual void perf_on_sendmmsg_packets(int nb_packets);
virtual srs_error_t dumps_perf_sendmmsg(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_padding);
virtual srs_error_t dumps_perf_bytes(SrsJsonObject* obj);
public:
// Reset all perf stat data.
virtual void reset_perf();
Expand Down

0 comments on commit 5ad99b1

Please sign in to comment.