Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -pf option with values json and default (#345) #356

Merged
merged 4 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ int main( int argc, char** argv )
cerr << "\t-b:<bandwidth> - set SRT bandwidth\n";
cerr << "\t-r:<report-frequency=0> - bandwidth report frequency\n";
cerr << "\t-s:<stats-report-freq=0> - frequency of status report\n";
cerr << "\t-pf:<format> - printformat (json or default)\n";
cerr << "\t-f - full counters in stats-report (prints total statistics)\n";
cerr << "\t-q - quiet mode (default no)\n";
cerr << "\t-v - verbose mode (default no)\n";
Expand All @@ -207,6 +208,18 @@ int main( int argc, char** argv )
bool internal_log = Option("no", "loginternal") != "no";
bool autoreconnect = Option("yes", "a", "auto") != "no";
transmit_total_stats = Option("no", "f", "fullstats") != "no";

// Print format
string pf = Option("default", "pf", "printformat");
if (pf == "json")
{
printformat_json = true;
}
else if (pf != "default")
{
cerr << "ERROR: Unsupported print format: " << pf << endl;
return 1;
}

try
{
Expand Down
2 changes: 1 addition & 1 deletion apps/transmitbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern volatile bool transmit_throw_on_interrupt;
extern unsigned long transmit_bw_report;
extern unsigned long transmit_stats_report;
extern unsigned long transmit_chunk_size;

extern bool printformat_json;

class Location
{
Expand Down
73 changes: 61 additions & 12 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool clear_stats = false;
unsigned long transmit_bw_report = 0;
unsigned long transmit_stats_report = 0;
unsigned long transmit_chunk_size = SRT_LIVE_DEF_PLSIZE;
bool printformat_json = false;

class FileSource: public Source
{
Expand Down Expand Up @@ -103,17 +104,61 @@ Iface* CreateFile(const string& name) { return new typename File<Iface>::type (n
template <class PerfMonType>
void PrintSrtStats(int sid, const PerfMonType& mon)
{
cerr << "======= SRT STATS: sid=" << sid << endl;
cerr << "PACKETS SENT: " << setw(11) << mon.pktSent << " RECEIVED: " << setw(11) << mon.pktRecv << endl;
cerr << "LOST PKT SENT: " << setw(11) << mon.pktSndLoss << " RECEIVED: " << setw(11) << mon.pktRcvLoss << endl;
cerr << "REXMIT SENT: " << setw(11) << mon.pktRetrans << " RECEIVED: " << setw(11) << mon.pktRcvRetrans << endl;
cerr << "DROP PKT SENT: " << setw(11) << mon.pktSndDrop << " RECEIVED: " << setw(11) << mon.pktRcvDrop << endl;
cerr << "RATE SENDING: " << setw(11) << mon.mbpsSendRate << " RECEIVING: " << setw(11) << mon.mbpsRecvRate << endl;
cerr << "BELATED RECEIVED: " << setw(11) << mon.pktRcvBelated << " AVG TIME: " << setw(11) << mon.pktRcvAvgBelatedTime << endl;
cerr << "REORDER DISTANCE: " << setw(11) << mon.pktReorderDistance << endl;
cerr << "WINDOW FLOW: " << setw(11) << mon.pktFlowWindow << " CONGESTION: " << setw(11) << mon.pktCongestionWindow << " FLIGHT: " << setw(11) << mon.pktFlightSize << endl;
cerr << "LINK RTT: " << setw(9) << mon.msRTT << "ms BANDWIDTH: " << setw(7) << mon.mbpsBandwidth << "Mb/s " << endl;
cerr << "BUFFERLEFT: SND: " << setw(11) << mon.byteAvailSndBuf << " RCV: " << setw(11) << mon.byteAvailRcvBuf << endl;
std::ostringstream output;

if (printformat_json)
{
output << "{";
output << "\"sid\":" << sid << ",";
output << "\"time\":" << mon.msTimeStamp << ",";
output << "\"window\":{";
output << "\"flow\":" << mon.pktFlowWindow << ",";
output << "\"congestion\":" << mon.pktCongestionWindow << ",";
output << "\"flight\":" << mon.pktFlightSize;
output << "},";
output << "\"link\":{";
output << "\"rtt\":" << mon.msRTT << ",";
output << "\"bandwidth\":" << mon.mbpsBandwidth << ",";
output << "\"maxBandwidth\":" << mon.mbpsMaxBW;
output << "},";
output << "\"send\":{";
output << "\"packets\":" << mon.pktSent << ",";
output << "\"packetsLost\":" << mon.pktSndLoss << ",";
output << "\"packetsDropped\":" << mon.pktSndDrop << ",";
output << "\"packetsRetransmitted\":" << mon.pktRetrans << ",";
output << "\"bytes\":" << mon.byteSent << ",";
output << "\"bytesDropped\":" << mon.byteSndDrop << ",";
output << "\"mbitRate\":" << mon.mbpsSendRate;
output << "},";
output << "\"recv\": {";
output << "\"packets\":" << mon.pktRecv << ",";
output << "\"packetsLost\":" << mon.pktRcvLoss << ",";
output << "\"packetsDropped\":" << mon.pktRcvDrop << ",";
output << "\"packetsRetransmitted\":" << mon.pktRcvRetrans << ",";
output << "\"packetsBelated\":" << mon.pktRcvBelated << ",";
output << "\"bytes\":" << mon.byteRecv << ",";
output << "\"bytesLost\":" << mon.byteRcvLoss << ",";
output << "\"bytesDropped\":" << mon.byteRcvDrop << ",";
output << "\"mbitRate\":" << mon.mbpsRecvRate;
output << "}";
output << "}" << endl;
}
else
{
output << "======= SRT STATS: sid=" << sid << endl;
output << "PACKETS SENT: " << setw(11) << mon.pktSent << " RECEIVED: " << setw(11) << mon.pktRecv << endl;
output << "LOST PKT SENT: " << setw(11) << mon.pktSndLoss << " RECEIVED: " << setw(11) << mon.pktRcvLoss << endl;
output << "REXMIT SENT: " << setw(11) << mon.pktRetrans << " RECEIVED: " << setw(11) << mon.pktRcvRetrans << endl;
output << "DROP PKT SENT: " << setw(11) << mon.pktSndDrop << " RECEIVED: " << setw(11) << mon.pktRcvDrop << endl;
output << "RATE SENDING: " << setw(11) << mon.mbpsSendRate << " RECEIVING: " << setw(11) << mon.mbpsRecvRate << endl;
output << "BELATED RECEIVED: " << setw(11) << mon.pktRcvBelated << " AVG TIME: " << setw(11) << mon.pktRcvAvgBelatedTime << endl;
output << "REORDER DISTANCE: " << setw(11) << mon.pktReorderDistance << endl;
output << "WINDOW FLOW: " << setw(11) << mon.pktFlowWindow << " CONGESTION: " << setw(11) << mon.pktCongestionWindow << " FLIGHT: " << setw(11) << mon.pktFlightSize << endl;
output << "LINK RTT: " << setw(9) << mon.msRTT << "ms BANDWIDTH: " << setw(7) << mon.mbpsBandwidth << "Mb/s " << endl;
output << "BUFFERLEFT: SND: " << setw(11) << mon.byteAvailSndBuf << " RCV: " << setw(11) << mon.byteAvailRcvBuf << endl;
}

cerr << output.str() << std::flush;
}


Expand Down Expand Up @@ -602,7 +647,11 @@ bool SrtTarget::Write(const bytevector& data)
clear_stats = false;
if ( transmit_bw_report && (counter % transmit_bw_report) == transmit_bw_report - 1 )
{
cerr << "+++/+++SRT BANDWIDTH: " << perf.mbpsBandwidth << endl;
if (printformat_json) {
cerr << "{\"bandwidth\":" << perf.mbpsBandwidth << '}' << endl;
} else {
cerr << "+++/+++SRT BANDWIDTH: " << perf.mbpsBandwidth << endl;
}
}
if ( transmit_stats_report && (counter % transmit_stats_report) == transmit_stats_report - 1)
{
Expand Down