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 1 commit
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
16 changes: 16 additions & 0 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ 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")
{
printformat_default = true;
}
else
{
cerr << "ERROR: Unsupported print format: " << pf << endl;
return 1;
}

try
{
Expand Down
3 changes: 2 additions & 1 deletion apps/transmitbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ 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;
extern bool printformat_default;

class Location
{
Expand Down
70 changes: 58 additions & 12 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ 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;
bool printformat_default = false;

class FileSource: public Source
{
Expand Down Expand Up @@ -103,17 +105,57 @@ 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;
if (printformat_json)
{
cerr << "{";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be more efficient to write JSON into std::ostringstream and then send it to std::cerr in one go. Probably regular stats should do the same. If you rather not change this now I can do the change later together with other (overdue) clean up tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't cerr buffer all data up until the endl?

I'll fix the typo right away.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think std::cerr buffers data by default, at least not according to the following quote from 'http://en.cppreference.com/w/cpp/io/cerr':

Once initialized, (std::cerr.flags() & unitbuf) != 0 (same for wcerr) meaning that any output sent to these stream objects is immediately flushed to the OS

Maybe another way to improve the code is to do std::cerr << std::unitbuf << ... << std::nounitbuf << std::endl but I am not sure if this approach is much better since std::cerr is shared and if something somewhere else (another thread) does a flush on it there can still be a mess. std::ostringstream is probably still safer (and clearer) way to go.

cerr << "\"sid\":" << sid << ",";
cerr << "\"time\":" << mon.msTimeStamp << ",";
cerr << "\"window\":{";
cerr << "\"flow\":" << mon.pktFlowWindow << ",";
cerr << "\"congestion\":" << mon.pktCongestionWindow << ",";
cerr << "\"flight\":" << mon.pktFlightSize;
cerr << "},";
cerr << "\"link\":{";
cerr << "\"rtt\":" << mon.msRTT << ",";
cerr << "\"bandwidth\":" << mon.mbpsBandwidth << ",";
cerr << "\"maxBandwidth\":" << mon.mbpsMaxBW;
cerr << "},";
cerr << "\"send\":{";
cerr << "\"packets\":" << mon.pktSent << ",";
cerr << "\"packetsLost\":" << mon.pktSndLoss << ",";
cerr << "\"packetsDropped\":" << mon.pktSndDrop << ",";
cerr << "\"packetsRetransmitted\":" << mon.pktRetrans << ",";
cerr << "\"bytes\":" << mon.byteSent << ",";
cerr << "\"bytesDropped\":" << mon.byteSndDrop << ",";
cerr << "\"mbitRate\":" << mon.mbpsSendRate;
cerr << "},";
cerr << "\"recv\": {";
cerr << "\"packets\":" << mon.pktRecv << ",";
cerr << "\"packetsLost\":" << mon.pktRcvLoss << ",";
cerr << "\"packetsDopped\":" << mon.pktRcvDrop << ",";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/packetsDopped/packetsDropped/ ?

cerr << "\"packetsRetransmitted\":" << mon.pktRcvRetrans << ",";
cerr << "\"packetsBelated\":" << mon.pktRcvBelated << ",";
cerr << "\"bytes\":" << mon.byteRecv << ",";
cerr << "\"bytesLost\":" << mon.byteRcvLoss << ",";
cerr << "\"bytesDropped\":" << mon.byteRcvDrop << ",";
cerr << "\"mbitRate\":" << mon.mbpsRecvRate;
cerr << "}";
cerr << "}" << endl;
}
else
{
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;
}
}


Expand Down Expand Up @@ -602,7 +644,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