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

RTC: Refine error pithy print log

This commit is contained in:
winlin 2020-08-12 17:07:37 +08:00
parent ea10d7907f
commit 9d08318581
4 changed files with 28 additions and 14 deletions

View file

@ -542,10 +542,11 @@ srs_error_t SrsUdpMuxListener::cycle()
} }
// Use pithy print to show more smart information. // Use pithy print to show more smart information.
if (err != srs_success) { if (err != srs_success) {
if (pp_pkt_handler_err->can_print(err)) { uint32_t nn = 0;
if (pp_pkt_handler_err->can_print(err, &nn)) {
// Append more information. // Append more information.
err = srs_error_wrap(err, "size=%u, data=[%s]", skt.size(), srs_string_dumps_hex(skt.data(), skt.size(), 8).c_str()); err = srs_error_wrap(err, "size=%u, data=[%s]", skt.size(), srs_string_dumps_hex(skt.data(), skt.size(), 8).c_str());
srs_warn("handle udp pkt, count=%u, err: %s", pp_pkt_handler_err->nn_count, srs_error_desc(err).c_str()); srs_warn("handle udp pkt, count=%u/%u, err: %s", pp_pkt_handler_err->nn_count, nn, srs_error_desc(err).c_str());
} }
srs_freep(err); srs_freep(err);
} }

View file

@ -36,6 +36,7 @@ SrsStageInfo::SrsStageInfo(int _stage_id)
stage_id = _stage_id; stage_id = _stage_id;
nb_clients = 0; nb_clients = 0;
age = 0; age = 0;
nn_count = 0;
update_print_time(); update_print_time();
@ -123,19 +124,25 @@ SrsErrorPithyPrint::~SrsErrorPithyPrint()
{ {
} }
bool SrsErrorPithyPrint::can_print(srs_error_t err) bool SrsErrorPithyPrint::can_print(srs_error_t err, uint32_t* pnn)
{ {
int error_code = srs_error_code(err); int error_code = srs_error_code(err);
return can_print(error_code); return can_print(error_code, pnn);
} }
bool SrsErrorPithyPrint::can_print(int error_code) bool SrsErrorPithyPrint::can_print(int error_code, uint32_t* pnn)
{ {
nn_count++;
bool new_stage = false; bool new_stage = false;
SrsStageInfo* stage = stages.fetch_or_create(error_code, &new_stage); SrsStageInfo* stage = stages.fetch_or_create(error_code, &new_stage);
// Increase the count.
stage->nn_count++;
nn_count++;
if (pnn) {
*pnn = stage->nn_count;
}
// Always and only one client. // Always and only one client.
if (new_stage) { if (new_stage) {
stage->nb_clients = 1; stage->nb_clients = 1;

View file

@ -37,6 +37,8 @@ public:
int stage_id; int stage_id;
srs_utime_t interval; srs_utime_t interval;
int nb_clients; int nb_clients;
// The number of call of can_print().
uint32_t nn_count;
public: public:
srs_utime_t age; srs_utime_t age;
public: public:
@ -79,9 +81,9 @@ public:
virtual ~SrsErrorPithyPrint(); virtual ~SrsErrorPithyPrint();
public: public:
// Whether specified stage is ready for print. // Whether specified stage is ready for print.
bool can_print(srs_error_t err); bool can_print(srs_error_t err, uint32_t* pnn = NULL);
// We also support int error code. // We also support int error code.
bool can_print(int err); bool can_print(int err, uint32_t* pnn = NULL);
}; };
// The stage is used for a collection of object to do print, // The stage is used for a collection of object to do print,

View file

@ -501,8 +501,9 @@ srs_error_t SrsRtcPlayStream::cycle()
// Send-out all RTP packets and do cleanup // Send-out all RTP packets and do cleanup
if (true) { if (true) {
if ((err = send_packets(source, pkts, info)) != srs_success) { if ((err = send_packets(source, pkts, info)) != srs_success) {
if (epp->can_print(err)) { uint32_t nn = 0;
srs_warn("play send packets=%u, nn=%u, err: %s", pkts.size(), epp->nn_count, srs_error_desc(err).c_str()); if (epp->can_print(err, &nn)) {
srs_warn("play send packets=%u, nn=%u/%u, err: %s", pkts.size(), epp->nn_count, nn, srs_error_desc(err).c_str());
} }
srs_freep(err); srs_freep(err);
} }
@ -1986,9 +1987,12 @@ void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
// Show address change log. // Show address change log.
if (prev_peer_id.empty()) { if (prev_peer_id.empty()) {
srs_trace("RTC: session address init %s", peer_id.c_str()); srs_trace("RTC: session address init %s", peer_id.c_str());
} else if (pp_address_change->can_print(skt->get_peer_port())) { } else {
srs_trace("RTC: session address change %s -> %s, cached=%d, nn_change=%u, nn_address=%u", prev_peer_id.c_str(), uint32_t nn = 0;
peer_id.c_str(), (addr_cache? 1:0), pp_address_change->nn_count, peer_addresses_.size()); if (pp_address_change->can_print(skt->get_peer_port(), &nn)) {
srs_trace("RTC: session address change %s -> %s, cached=%d, nn_change=%u/%u, nn_address=%u", prev_peer_id.c_str(),
peer_id.c_str(), (addr_cache? 1:0), pp_address_change->nn_count, nn, peer_addresses_.size());
}
} }
// If no cache, build cache and setup the relations in connection. // If no cache, build cache and setup the relations in connection.