Skip to content

Commit 6ad21dc

Browse files
committed
Add --flush option to flush all output
1 parent 5a637bf commit 6ad21dc

10 files changed

+37
-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-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

+12-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

@@ -274,6 +280,8 @@ void ui_message_handlert::xml_ui_msg(
274280

275281
out << result;
276282
out << '\n';
283+
if(always_flush)
284+
flush(1);
277285
}
278286

279287
void ui_message_handlert::json_ui_msg(
@@ -299,6 +307,8 @@ void ui_message_handlert::json_ui_msg(
299307
// The first entry is generated in the constructor and does not have
300308
// a trailing comma.
301309
std::cout << ",\n" << result;
310+
if(always_flush)
311+
flush(1);
302312
}
303313

304314
void ui_message_handlert::flush(unsigned level)
@@ -307,7 +317,7 @@ void ui_message_handlert::flush(unsigned level)
307317
{
308318
case uit::PLAIN:
309319
{
310-
console_message_handlert console_message_handler;
320+
console_message_handlert console_message_handler(always_flush);
311321
console_message_handler.flush(level);
312322
}
313323
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+
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)