Skip to content

Commit 1ef0f41

Browse files
committed
Add --flush option to flush all output
1 parent 0764f77 commit 1ef0f41

14 files changed

+39
-3
lines changed

src/cbmc/cbmc_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ void cbmc_parse_optionst::help()
990990
" --xml-interface bi-directional XML interface\n"
991991
" --json-ui use JSON-formatted output\n"
992992
HELP_GOTO_TRACE
993+
HELP_FLUSH
993994
" --verbosity # verbosity level\n"
994995
HELP_TIMESTAMP
995996
"\n";

src/cbmc/cbmc_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class optionst;
7171
"(arrays-uf-always)(arrays-uf-never)" \
7272
"(string-abstraction)(no-arch)(arch):" \
7373
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
74+
OPT_FLUSH \
7475
"(localize-faults)(localize-faults-method):" \
7576
OPT_GOTO_TRACE \
7677
"(claim):(show-claims)(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)

src/goto-analyzer/goto_analyzer_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ void goto_analyzer_parse_optionst::help()
905905
"\n"
906906
"Other options:\n"
907907
" --version show version and exit\n"
908+
HELP_FLUSH
908909
HELP_TIMESTAMP
909910
"\n";
910911
// clang-format on

src/goto-analyzer/goto_analyzer_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class optionst;
139139
"(show-local-may-alias)" \
140140
"(json):(xml):" \
141141
"(text):(dot):" \
142+
OPT_FLUSH \
142143
OPT_TIMESTAMP \
143144
"(unreachable-instructions)(unreachable-functions)" \
144145
"(reachable-functions)" \

src/goto-diff/goto_diff_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ void goto_diff_parse_optionst::help()
537537
"Other options:\n"
538538
" --version show version and exit\n"
539539
" --json-ui use JSON-formatted output\n"
540+
HELP_FLUSH
540541
HELP_TIMESTAMP
541542
"\n";
542543
// clang-format on

src/goto-diff/goto_diff_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class optionst;
3535
OPT_GOTO_CHECK \
3636
"(cover):" \
3737
"(verbosity):(version)" \
38+
OPT_FLUSH \
3839
OPT_TIMESTAMP \
3940
"u(unified)(change-impact)(forward-impact)(backward-impact)" \
4041
"(compact-output)"

src/goto-instrument/goto_instrument_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ void goto_instrument_parse_optionst::help()
15731573
" --use-all-headers with --dump-c/--dump-cpp: generate C source with all includes\n" // NOLINT(*)
15741574
" --harness with --dump-c/--dump-cpp: include input generator in output\n" // NOLINT(*)
15751575
" --version show version and exit\n"
1576+
HELP_FLUSH
15761577
" --xml-ui use XML-formatted output\n"
15771578
" --json-ui use JSON-formatted output\n"
15781579
HELP_TIMESTAMP

src/goto-instrument/goto_instrument_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Author: Daniel Kroening, [email protected]
8585
"(show-threaded)(list-calls-args)(print-path-lengths)" \
8686
"(undefined-function-is-assume-false)" \
8787
"(remove-function-body):"\
88+
OPT_FLUSH \
8889
"(splice-call):" \
8990
OPT_REMOVE_CALLS_NO_BODY
9091
// clang-format on

src/jbmc/jbmc_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ void jbmc_parse_optionst::help()
10831083
" --xml-ui use XML-formatted output\n"
10841084
" --json-ui use JSON-formatted output\n"
10851085
HELP_GOTO_TRACE
1086+
HELP_FLUSH
10861087
" --verbosity # verbosity level\n"
10871088
HELP_TIMESTAMP
10881089
"\n";

src/jbmc/jbmc_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class optionst;
7171
"(ppc-macos)" \
7272
"(arrays-uf-always)(arrays-uf-never)" \
7373
"(no-arch)(arch):" \
74+
OPT_FLUSH \
7475
JAVA_BYTECODE_LANGUAGE_OPTIONS \
7576
"(java-unwind-enum-static)" \
7677
"(localize-faults)(localize-faults-method):" \

src/util/cout_message.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void console_message_handlert::flush(unsigned level)
9090
// in particular when writing to NFS.
9191
if(level>=4)
9292
{
93-
if(level<=6)
93+
if(level <= 6 || always_flush)
9494
std::cout << std::flush;
9595
}
9696
else

src/util/cout_message.h

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class console_message_handlert:public ui_message_handlert
3535
const std::string &message) override;
3636

3737
virtual void flush(unsigned level) override;
38+
39+
console_message_handlert() : always_flush(false)
40+
{
41+
}
42+
43+
explicit console_message_handlert(bool always_flush)
44+
: always_flush(always_flush)
45+
{
46+
}
47+
48+
protected:
49+
const bool always_flush;
3850
};
3951

4052
class gcc_message_handlert:public ui_message_handlert

src/util/ui_message.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121

2222
ui_message_handlert::ui_message_handlert()
2323
: _ui(uit::PLAIN),
24+
always_flush(false),
2425
time(timestampert::make(timestampert::clockt::NONE)),
2526
out(std::cout),
2627
json_stream(nullptr)
@@ -30,8 +31,10 @@ ui_message_handlert::ui_message_handlert()
3031
ui_message_handlert::ui_message_handlert(
3132
uit __ui,
3233
const std::string &program,
34+
bool always_flush,
3335
timestampert::clockt clock_type)
3436
: _ui(__ui),
37+
always_flush(always_flush),
3538
time(timestampert::make(clock_type)),
3639
out(std::cout),
3740
json_stream(nullptr)
@@ -79,6 +82,7 @@ ui_message_handlert::ui_message_handlert(
7982
? uit::JSON_UI
8083
: uit::PLAIN,
8184
program,
85+
cmdline.isset("flush"),
8286
cmdline.isset("timestamp")
8387
? cmdline.get_value("timestamp") == "monotonic"
8488
? timestampert::clockt::MONOTONIC
@@ -130,11 +134,13 @@ void ui_message_handlert::print(
130134
{
131135
case uit::PLAIN:
132136
{
133-
console_message_handlert console_message_handler;
137+
console_message_handlert console_message_handler(always_flush);
134138
std::stringstream ss;
135139
const std::string timestamp = time->stamp();
136140
ss << timestamp << (timestamp.empty() ? "" : " ") << message;
137141
console_message_handler.print(level, ss.str());
142+
if(always_flush)
143+
console_message_handler.flush(level);
138144
}
139145
break;
140146

@@ -144,6 +150,8 @@ void ui_message_handlert::print(
144150
source_locationt location;
145151
location.make_nil();
146152
print(level, message, -1, location);
153+
if(always_flush)
154+
flush(level);
147155
}
148156
break;
149157
}
@@ -302,7 +310,7 @@ void ui_message_handlert::flush(unsigned level)
302310
{
303311
case uit::PLAIN:
304312
{
305-
console_message_handlert console_message_handler;
313+
console_message_handlert console_message_handler(always_flush);
306314
console_message_handler.flush(level);
307315
}
308316
break;

src/util/ui_message.h

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ui_message_handlert : public message_handlert
2424
ui_message_handlert(
2525
uit,
2626
const std::string &program,
27+
const bool always_flush,
2728
timestampert::clockt clock_type);
2829

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

5859
protected:
5960
uit _ui;
61+
const bool always_flush;
6062
std::unique_ptr<const timestampert> time;
6163
std::ostream &out;
6264
std::unique_ptr<json_stream_arrayt> json_stream;
@@ -100,4 +102,8 @@ class ui_message_handlert : public message_handlert
100102
const char *level_string(unsigned level);
101103
};
102104

105+
#define OPT_FLUSH "(flush)"
106+
107+
#define HELP_FLUSH " --flush flush every line of output\n"
108+
103109
#endif // CPROVER_UTIL_UI_MESSAGE_H

0 commit comments

Comments
 (0)