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

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

merged 4 commits into from
May 23, 2018

Conversation

gissleh
Copy link
Contributor

@gissleh gissleh commented Apr 23, 2018

This PR adds a json print format for the statistical (-s) output, activated by a -pf:json option. I've left the code fairly general to allow for other print formats to be added in the future. As I said in the issue, the existing format is not very parser-friendly. I have not touched the default print format, so there is a disparity between them regarding the amount of monitoring data from they convey.

The change is only for the srt-live-transmit/stransmit app because I do not use and thus cannot properly test the file transfer option.

Copy link
Collaborator

@ethouris ethouris left a comment

Choose a reason for hiding this comment

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

I think this printformat_default variable is superfluous. You simply use json format if printformat_json is true and the "old way" otherwise.

@gissleh
Copy link
Contributor Author

gissleh commented May 4, 2018

I've made the change you requested. You're right, it's superfluous even in the future scenario I thought of when adding it, which was leaving room for different print formats.

@ethouris
Copy link
Collaborator

ethouris commented May 4, 2018

Don't worry, if any more formats are going to be supported in future, we'd make some enum and possibly some format table. This is ok as it is now.

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 << "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.

@gissleh
Copy link
Contributor Author

gissleh commented May 22, 2018

I've changed the statistics printer to use an intermediary std::ostringstream.

@rndi rndi merged commit d3f0ae7 into Haivision:master May 23, 2018
@gissleh gissleh deleted the dev-345-printformat-json branch June 11, 2018 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants