Skip to content

Commit 4c4a267

Browse files
committed
Adding computation and save of goto program statistics.
1 parent 6bc86e1 commit 4c4a267

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/goto-instrument/goto_instrument_parse_options.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Author: Daniel Kroening, [email protected]
4242
#include <goto-programs/parameter_assignments.h>
4343
#include <goto-programs/slice_global_inits.h>
4444
#include <goto-programs/show_symbol_table.h>
45+
#include <goto-programs/goto_statistics.h>
4546

4647
#include <pointer-analysis/value_set_analysis.h>
4748
#include <pointer-analysis/goto_program_dereference.h>
@@ -61,6 +62,8 @@ Author: Daniel Kroening, [email protected]
6162
#include <analyses/constant_propagator.h>
6263
#include <analyses/is_threaded.h>
6364

65+
#include <util/file_util.h>
66+
6467
#include <cbmc/version.h>
6568

6669
#include "document_properties.h"
@@ -738,6 +741,32 @@ int goto_instrument_parse_optionst::doit()
738741
undefined_function_abort_path(goto_model);
739742
}
740743

744+
if(cmdline.isset("save-code-statistics"))
745+
{
746+
goto_statisticst stats;
747+
stats.extend(goto_model);
748+
const std::string out_json_file_pathname=
749+
cmdline.get_value("save-code-statistics");
750+
if(fileutl_is_directory(out_json_file_pathname))
751+
{
752+
error() << "The path-name '" << cmdline.args[1]
753+
<< "'passed to the option '--save-code-statistics' "
754+
"represents an existing directory."
755+
<< eom;
756+
return 12;
757+
}
758+
if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json")
759+
{
760+
error() << "The file of the path-name '" << cmdline.args[1]
761+
<< "'passed to the option '--save-code-statistics' does "
762+
"not have '.json' extension."
763+
<< eom;
764+
return 13;
765+
}
766+
std::ofstream ofile(out_json_file_pathname);
767+
ofile << to_json(stats);
768+
}
769+
741770
// write new binary?
742771
if(cmdline.args.size()==2)
743772
{
@@ -1450,6 +1479,9 @@ void goto_instrument_parse_optionst::help()
14501479
" --list-calls-args list all function calls with their arguments\n"
14511480
// NOLINTNEXTLINE(whitespace/line_length)
14521481
" --print-path-lengths print statistics about control-flow graph paths\n"
1482+
" --save-code-statistics saves a json file with basic statistical data of"
1483+
" the analysed program after all analyses and\n"
1484+
" transformations have been performed on it.\n"
14531485
"\n"
14541486
"Safety checks:\n"
14551487
" --no-assertions ignore user assertions\n"

src/goto-instrument/goto_instrument_parse_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Author: Daniel Kroening, [email protected]
5959
"(show-uninitialized)(show-locations)" \
6060
"(full-slice)(reachability-slice)(slice-global-inits)" \
6161
"(inline)(partial-inline)(function-inline):(log):(no-caching)" \
62+
"(save-code-statistics):" \
6263
OPT_REMOVE_CONST_FUNCTION_POINTERS \
6364
"(print-internal-representation)" \
6465
"(remove-function-pointers)" \

0 commit comments

Comments
 (0)