Skip to content

Commit 0844ad7

Browse files
Add option to print statistics about the VS domain
1 parent e0e1c33 commit 0844ad7

File tree

6 files changed

+101
-10
lines changed

6 files changed

+101
-10
lines changed

src/analyses/ai.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ bool ai_baset::do_function_call(
515515
progress_data.max_stack_depth
516516
= std::max(progress_data.max_stack_depth, progress_data.stack.size());
517517

518-
print_progress_interval();
518+
print_progress_interval(ns);
519519

520520
fixedpoint(goto_function.body, goto_functions, ns);
521521

522522
progress_data.functions_returned.insert(id);
523523
progress_data.num_functions_returned++;
524524
progress_data.stack.pop_front();
525525

526-
print_progress_interval();
526+
print_progress_interval(ns);
527527
}
528528
}
529529

@@ -756,20 +756,30 @@ void ai_baset::print_progress() const
756756
progress() << std::flush;
757757
}
758758

759-
void ai_baset::print_progress_interval() const
759+
void ai_baset::print_progress_interval(const namespacet &ns) const
760760
{
761761
using namespace std::chrono;
762762

763763
system_clock::time_point now = system_clock::now();
764764
auto diff = now - last_progress_output;
765-
766-
if(config.print_progress && diff >= config.progress_interval)
765+
if(diff >= config.progress_interval)
767766
{
768-
print_progress();
769767
last_progress_output = now;
768+
if(config.print_progress)
769+
{
770+
print_progress();
771+
}
772+
if(config.print_memory_usage)
773+
{
774+
print_memory_usage(ns);
775+
}
770776
}
771777
}
772778

779+
void ai_baset::print_memory_usage(const namespacet &ns) const
780+
{
781+
}
782+
773783
ai_configt ai_configt::from_options(const optionst &options)
774784
{
775785
ai_configt result = {};
@@ -779,6 +789,8 @@ ai_configt ai_configt::from_options(const optionst &options)
779789
result.progress_interval = ai_configt::secondst(
780790
std::stof(options.get_option("vs-progress-interval")));
781791
}
792+
result.print_memory_usage =
793+
options.get_bool_option("vs-progress-memory-usage");
782794
return result;
783795
}
784796

src/analyses/ai.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ struct ai_configt
144144
{
145145
using secondst = std::chrono::duration<float>;
146146
bool print_progress = false;
147+
bool print_memory_usage = false;
148+
147149
secondst progress_interval = secondst(0.0f);
148150
bool periodic_task = false;
149151

@@ -347,7 +349,7 @@ class ai_baset
347349

348350
mutable std::chrono::system_clock::time_point last_progress_output;
349351

350-
void print_progress_interval() const;
352+
void print_progress_interval(const namespacet &ns) const;
351353

352354
const ai_configt config;
353355
// overload to add a factory
@@ -444,6 +446,19 @@ class ai_baset
444446
virtual statet &get_state(locationt l)=0;
445447
virtual const statet &find_state(locationt l) const=0;
446448
virtual std::unique_ptr<statet> make_temporary_state(const statet &s)=0;
449+
450+
virtual void print_memory_usage(const namespacet &ns) const;
451+
};
452+
453+
template <typename domainT>
454+
struct get_domain_statisticst
455+
{
456+
void add_entry(const domainT &domain, const namespacet &ns)
457+
{
458+
}
459+
void print(std::ostream &out) const
460+
{
461+
}
447462
};
448463

449464
// domainT is expected to be derived from ai_domain_baseT
@@ -545,6 +560,16 @@ class ait:public ai_baset
545560
sequential_fixedpoint(goto_functions, ns);
546561
}
547562

563+
void print_memory_usage(const namespacet &ns) const override
564+
{
565+
get_domain_statisticst<domainT> statistics;
566+
for(auto const &state_entry : state_map)
567+
{
568+
statistics.add_entry(state_entry.second, ns);
569+
}
570+
statistics.print(progress());
571+
}
572+
548573
private:
549574
// to enforce that domainT is derived from ai_domain_baset
550575
void dummy(const domainT &s) { const statet &x=s; (void)x; }

src/analyses/variable-sensitivity/variable_sensitivity_domain.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,8 @@ void variable_sensitivity_domaint::apply_domain(
592592
abstract_state.assign(symbol, value, ns);
593593
}
594594
}
595+
abstract_object_statisticst
596+
variable_sensitivity_domaint::gather_statistics(const namespacet &ns) const
597+
{
598+
return abstract_state.gather_statistics(ns);
599+
}

src/analyses/variable-sensitivity/variable_sensitivity_domain.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,49 @@ class variable_sensitivity_domaint:public ai_domain_baset
137137
const namespacet &ns);
138138

139139
abstract_environmentt abstract_state;
140+
141+
public:
142+
abstract_object_statisticst gather_statistics(const namespacet &ns) const;
143+
};
144+
145+
template <>
146+
struct get_domain_statisticst<variable_sensitivity_domaint>
147+
{
148+
abstract_object_statisticst total_statistics = {};
149+
void
150+
add_entry(const variable_sensitivity_domaint &domain, const namespacet &ns)
151+
{
152+
auto statistics = domain.gather_statistics(ns);
153+
total_statistics.number_of_interval_abstract_objects +=
154+
statistics.number_of_interval_abstract_objects;
155+
total_statistics.number_of_globals += statistics.number_of_globals;
156+
total_statistics.number_of_single_value_intervals +=
157+
statistics.number_of_single_value_intervals;
158+
total_statistics.number_of_constants += statistics.number_of_constants;
159+
total_statistics.number_of_pointers += statistics.number_of_constants;
160+
total_statistics.number_of_arrays += statistics.number_of_arrays;
161+
total_statistics.number_of_structs += statistics.number_of_arrays;
162+
total_statistics.objects_memory_usage += statistics.objects_memory_usage;
163+
}
164+
165+
void print(std::ostream &out) const
166+
{
167+
out << "<< Begin Variable Sensitivity Domain Statistics >>\n"
168+
<< " Memory Usage: "
169+
<< total_statistics.objects_memory_usage.to_string() << '\n'
170+
<< " Number of structs: " << total_statistics.number_of_structs << '\n'
171+
<< " Number of arrays: " << total_statistics.number_of_arrays << '\n'
172+
<< " Number of pointers: " << total_statistics.number_of_pointers
173+
<< '\n'
174+
<< " Number of constants: " << total_statistics.number_of_constants
175+
<< '\n'
176+
<< " Number of intervals: "
177+
<< total_statistics.number_of_interval_abstract_objects << '\n'
178+
<< " Number of single value intervals: "
179+
<< total_statistics.number_of_single_value_intervals << '\n'
180+
<< " Number of globals: " << total_statistics.number_of_globals << '\n'
181+
<< "<< End Variable Sensitivity Domain Statistics >>\n";
182+
}
140183
};
141184

142185
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_VARIABLE_SENSITIVITY_DOMAIN_H

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,18 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
266266
if(options.get_bool_option("general-analysis") || reachability_task)
267267
{
268268
options.set_option("vs-progress", cmdline.isset("vs-progress"));
269+
options.set_option(
270+
"vs-progress-memory-usage", cmdline.isset("vs-progress-memory-usage"));
269271
const char *vs_progress_interval = "vs-progress-interval";
270272

271273
if(cmdline.isset(vs_progress_interval))
272274
{
273-
std::string v(cmdline.get_value(vs_progress_interval));
275+
std::string interval_value = cmdline.get_value(vs_progress_interval);
274276

275277
try
276278
{
277279
// check if valid float
278-
std::stof(v);
280+
std::stof(interval_value);
279281
}
280282
catch(std::out_of_range)
281283
{
@@ -286,7 +288,7 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
286288
throw "argument to --vs-progress-interval is invalid";
287289
}
288290

289-
options.set_option(vs_progress_interval, v);
291+
options.set_option(vs_progress_interval, interval_value);
290292
}
291293

292294
// Abstract interpreter choice
@@ -1018,6 +1020,7 @@ void goto_analyzer_parse_optionst::help()
10181020
" --variable-sensitivity a highly configurable non-relational domain\n" // NOLINT(*)
10191021
" --vs-progress print variable sensitivity progress data\n"
10201022
" --vs-progress-interval minimum interval (in s) between progress reports\n" // NOLINT(*)
1023+
" --vs-progress-memory-usage display variable sensitivity memory usage along progress\n" // NOLINT(*)
10211024
"\n"
10221025
"Output options:\n"
10231026
" --text file_name output results in plain text to given file\n"

src/goto-analyzer/goto_analyzer_parse_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ class optionst;
163163
"(interval-values)" \
164164
"(vs-progress)" \
165165
"(vs-progress-interval):" \
166+
"(vs-progress-memory-usage)" \
166167
"(periodic-task)" \
168+
"(vs-progress-interval):" \
169+
"(vs-progress-interval):" \
167170
// clang-format on
168171

169172
class goto_analyzer_parse_optionst:

0 commit comments

Comments
 (0)