Skip to content

Add --flush option to flush all output #1712

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

Merged
merged 1 commit into from
May 2, 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
1 change: 1 addition & 0 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ void cbmc_parse_optionst::help()
" --xml-interface bi-directional XML interface\n"
" --json-ui use JSON-formatted output\n"
HELP_GOTO_TRACE
HELP_FLUSH
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please also add this to goto-analyzer (and possibly goto-diff)?

" --verbosity # verbosity level\n"
HELP_TIMESTAMP
"\n";
Expand Down
1 change: 1 addition & 0 deletions src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class optionst;
"(arrays-uf-always)(arrays-uf-never)" \
"(string-abstraction)(no-arch)(arch):" \
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
OPT_FLUSH \
"(localize-faults)(localize-faults-method):" \
OPT_GOTO_TRACE \
"(claim):(show-claims)(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
Expand Down
1 change: 1 addition & 0 deletions src/goto-analyzer/goto_analyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ void goto_analyzer_parse_optionst::help()
"\n"
"Other options:\n"
" --version show version and exit\n"
HELP_FLUSH
HELP_TIMESTAMP
"\n";
// clang-format on
Expand Down
1 change: 1 addition & 0 deletions src/goto-analyzer/goto_analyzer_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class optionst;
"(show-local-may-alias)" \
"(json):(xml):" \
"(text):(dot):" \
OPT_FLUSH \
OPT_TIMESTAMP \
"(unreachable-instructions)(unreachable-functions)" \
"(reachable-functions)" \
Expand Down
1 change: 1 addition & 0 deletions src/goto-diff/goto_diff_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ void goto_diff_parse_optionst::help()
"Other options:\n"
" --version show version and exit\n"
" --json-ui use JSON-formatted output\n"
HELP_FLUSH
HELP_TIMESTAMP
"\n";
// clang-format on
Expand Down
1 change: 1 addition & 0 deletions src/goto-diff/goto_diff_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class optionst;
OPT_GOTO_CHECK \
"(cover):" \
"(verbosity):(version)" \
OPT_FLUSH \
OPT_TIMESTAMP \
"u(unified)(change-impact)(forward-impact)(backward-impact)" \
"(compact-output)"
Expand Down
1 change: 1 addition & 0 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ void goto_instrument_parse_optionst::help()
" --use-all-headers with --dump-c/--dump-cpp: generate C source with all includes\n" // NOLINT(*)
" --harness with --dump-c/--dump-cpp: include input generator in output\n" // NOLINT(*)
" --version show version and exit\n"
HELP_FLUSH
" --xml-ui use XML-formatted output\n"
" --json-ui use JSON-formatted output\n"
HELP_TIMESTAMP
Expand Down
1 change: 1 addition & 0 deletions src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Author: Daniel Kroening, [email protected]
"(show-threaded)(list-calls-args)(print-path-lengths)" \
"(undefined-function-is-assume-false)" \
"(remove-function-body):"\
OPT_FLUSH \
"(splice-call):" \
OPT_REMOVE_CALLS_NO_BODY
// clang-format on
Expand Down
1 change: 1 addition & 0 deletions src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ void jbmc_parse_optionst::help()
" --xml-ui use XML-formatted output\n"
" --json-ui use JSON-formatted output\n"
HELP_GOTO_TRACE
HELP_FLUSH
" --verbosity # verbosity level\n"
HELP_TIMESTAMP
"\n";
Expand Down
1 change: 1 addition & 0 deletions src/jbmc/jbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class optionst;
"(ppc-macos)" \
"(arrays-uf-always)(arrays-uf-never)" \
"(no-arch)(arch):" \
OPT_FLUSH \
JAVA_BYTECODE_LANGUAGE_OPTIONS \
"(java-unwind-enum-static)" \
"(localize-faults)(localize-faults-method):" \
Expand Down
2 changes: 1 addition & 1 deletion src/util/cout_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void console_message_handlert::flush(unsigned level)
// in particular when writing to NFS.
if(level>=4)
{
if(level<=6)
if(level <= 6 || always_flush)
std::cout << std::flush;
}
else
Expand Down
12 changes: 12 additions & 0 deletions src/util/cout_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class console_message_handlert:public ui_message_handlert
const std::string &message) override;

virtual void flush(unsigned level) override;

console_message_handlert() : always_flush(false)
{
}

explicit console_message_handlert(bool always_flush)
: always_flush(always_flush)
{
}

protected:
const bool always_flush;
};

class gcc_message_handlert:public ui_message_handlert
Expand Down
12 changes: 10 additions & 2 deletions src/util/ui_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]

ui_message_handlert::ui_message_handlert()
: _ui(uit::PLAIN),
always_flush(false),
time(timestampert::make(timestampert::clockt::NONE)),
out(std::cout),
json_stream(nullptr)
Expand All @@ -30,8 +31,10 @@ ui_message_handlert::ui_message_handlert()
ui_message_handlert::ui_message_handlert(
uit __ui,
const std::string &program,
bool always_flush,
timestampert::clockt clock_type)
: _ui(__ui),
always_flush(always_flush),
time(timestampert::make(clock_type)),
out(std::cout),
json_stream(nullptr)
Expand Down Expand Up @@ -79,6 +82,7 @@ ui_message_handlert::ui_message_handlert(
? uit::JSON_UI
: uit::PLAIN,
program,
cmdline.isset("flush"),
cmdline.isset("timestamp")
? cmdline.get_value("timestamp") == "monotonic"
? timestampert::clockt::MONOTONIC
Expand Down Expand Up @@ -130,11 +134,13 @@ void ui_message_handlert::print(
{
case uit::PLAIN:
{
console_message_handlert console_message_handler;
console_message_handlert console_message_handler(always_flush);
Copy link
Collaborator

Choose a reason for hiding this comment

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

JSON and XML streams should also be flushed.

std::stringstream ss;
const std::string timestamp = time->stamp();
ss << timestamp << (timestamp.empty() ? "" : " ") << message;
console_message_handler.print(level, ss.str());
if(always_flush)
console_message_handler.flush(level);
}
break;

Expand All @@ -144,6 +150,8 @@ void ui_message_handlert::print(
source_locationt location;
location.make_nil();
print(level, message, -1, location);
if(always_flush)
flush(level);
}
break;
}
Expand Down Expand Up @@ -302,7 +310,7 @@ void ui_message_handlert::flush(unsigned level)
{
case uit::PLAIN:
{
console_message_handlert console_message_handler;
console_message_handlert console_message_handler(always_flush);
console_message_handler.flush(level);
}
break;
Expand Down
6 changes: 6 additions & 0 deletions src/util/ui_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ui_message_handlert : public message_handlert
ui_message_handlert(
uit,
const std::string &program,
const bool always_flush,
timestampert::clockt clock_type);

ui_message_handlert(const class cmdlinet &, const std::string &program);
Expand Down Expand Up @@ -57,6 +58,7 @@ class ui_message_handlert : public message_handlert

protected:
uit _ui;
const bool always_flush;
std::unique_ptr<const timestampert> time;
std::ostream &out;
std::unique_ptr<json_stream_arrayt> json_stream;
Expand Down Expand Up @@ -100,4 +102,8 @@ class ui_message_handlert : public message_handlert
const char *level_string(unsigned level);
};

#define OPT_FLUSH "(flush)"

#define HELP_FLUSH " --flush flush every line of output\n"

#endif // CPROVER_UTIL_UI_MESSAGE_H