misc/timer: Gather handling of %r and %R options

* bin/autcross.cc: Update.
* bin/autfilt.cc: Update.
* bin/common_aoutput.cc: Gather them. Move process_timer struct.
* bin/common_aoutput.hh: Gather them.
* bin/common_output.hh: Update.
* bin/dstar2tgba.cc: Update.
* bin/ltl2tgba.cc: Update.
* bin/ltlcross.cc: Update.
* bin/ltldo.cc: Update.
* bin/ltlfilt.cc: Update.
* bin/randaut.cc: Update.
* spot/misc/formater.hh: Remove an useless function.
* spot/misc/timer.hh: Add process_timer struct definition.
* spot/misc/timer.cc: Remove old dead code.
* spot/twaalgos/stats.cc: Update.
* spot/twaalgos/stats.hh: Update.
This commit is contained in:
Alexandre GBAGUIDI AISSE 2017-07-24 17:27:23 +02:00
parent 302095ff9e
commit ad9bc644ba
16 changed files with 89 additions and 81 deletions

View file

@ -52,6 +52,7 @@
#include <spot/twaalgos/remfin.hh>
#include <spot/twaalgos/product.hh>
#include <spot/misc/escape.hh>
#include <spot/misc/timer.hh>
const char argp_program_doc[] ="\
Call several tools that process automata and cross-compare their output \
@ -377,7 +378,7 @@ namespace
std::string cmd = command.str();
std::cerr << "Running [" << l << tool_num << "]: "
<< cmd << std::endl;
process_timer timer;
spot::process_timer timer;
timer.start();
int es = exec_with_timeout(cmd.c_str());
timer.stop();
@ -459,7 +460,7 @@ namespace
stats.status_str = status_str;
stats.status_code = es;
stats.time = timer.get_lap_sw();
stats.time = timer.walltime();
if (res)
{
stats.ok = true;

View file

@ -991,7 +991,7 @@ namespace
int
process_automaton(const spot::const_parsed_aut_ptr& haut) override
{
process_timer timer;
spot::process_timer timer;
timer.start();
// If --stats or --name is used, duplicate the automaton so we

View file

@ -384,6 +384,7 @@ hoa_stat_printer::hoa_stat_printer(std::ostream& os, const char* format,
declare('F', &filename_);
declare('L', &location_);
declare('R', &timer_);
declare('r', &timer_);
if (input != ltl_input)
declare('f', &filename_); // Override the formula printer.
declare('h', &output_aut_);
@ -396,11 +397,11 @@ std::ostream&
hoa_stat_printer::print(const spot::const_parsed_aut_ptr& haut,
const spot::const_twa_graph_ptr& aut,
spot::formula f,
const char* filename, int loc, process_timer& ptimer,
const char* filename, int loc,
spot::process_timer& ptimer,
const char* csv_prefix, const char* csv_suffix)
{
timer_ = ptimer.dt;
double run_time = ptimer.get_lap_sw();
timer_ = ptimer;
filename_ = filename ? filename : "";
csv_prefix_ = csv_prefix ? csv_prefix : "";
@ -511,7 +512,7 @@ hoa_stat_printer::print(const spot::const_parsed_aut_ptr& haut,
if (has('x'))
aut_ap_ = aut->ap();
auto& res = this->spot::stat_printer::print(aut, f, run_time);
auto& res = this->spot::stat_printer::print(aut, f);
// Make sure we do not store the automaton until the next one is
// printed, as the registered APs will affect how the next
// automata are built.
@ -536,7 +537,7 @@ automaton_printer::automaton_printer(stat_style input)
void
automaton_printer::print(const spot::twa_graph_ptr& aut,
// Time for statistics
process_timer& ptimer,
spot::process_timer& ptimer,
spot::formula f,
// Input location for errors and statistics.
const char* filename,
@ -662,11 +663,19 @@ void printable_timer::print(std::ostream& os, const char* pos) const
#endif
if (*pos != '[')
{
res = val_.get_uscp(true, true, true, true);
os << res / clocks_per_sec;
return;
}
{
if (*pos == 'r')
{
res = val_.walltime();
os << res;
}
else
{
res = val_.cputime(true, true, true, true);
os << res / clocks_per_sec;
}
return;
}
bool user = false;
bool system = false;
@ -700,12 +709,15 @@ void printable_timer::print(std::ostream& os, const char* pos) const
}
while (*pos != ']');
if (*(pos + 1) == 'r')
percent_error(beg, pos-1);
if (!parent && !children)
parent = children = true;
if (!user && !system)
user = system = true;
res = val_.get_uscp(user, system, children, parent);
res = val_.cputime(user, system, children, parent);
os << res / clocks_per_sec;
}

View file

@ -74,37 +74,17 @@ struct printable_automaton final:
void print(std::ostream& os, const char* pos) const override;
};
struct process_timer
struct printable_timer final: public spot::printable
{
void start()
protected:
spot::process_timer val_;
public:
printable_timer& operator=(const spot::process_timer& val)
{
sw.start();
dt.start();
val_ = val;
return *this;
}
void stop()
{
// sw.stop() --> It always returns the duration since the last call to
// start(). Therefore, it wont't stop timing, moreover, it can be called
// multiple times.
sw_lap_ = sw.stop();
dt.stop();
}
double get_lap_sw()
{
return sw_lap_;
}
spot::timer dt;
spot::stopwatch sw;
double sw_lap_ = 0;
};
struct printable_timer final:
public spot::printable_value<spot::timer>
{
using spot::printable_value<spot::timer>::operator=;
void print(std::ostream& os, const char* pos) const override;
};
@ -166,7 +146,7 @@ public:
print(const spot::const_parsed_aut_ptr& haut,
const spot::const_twa_graph_ptr& aut,
spot::formula f,
const char* filename, int loc, process_timer& ptimer,
const char* filename, int loc, spot::process_timer& ptimer,
const char* csv_prefix, const char* csv_suffix);
private:
@ -210,7 +190,7 @@ public:
void
print(const spot::twa_graph_ptr& aut,
process_timer& ptimer,
spot::process_timer& ptimer,
spot::formula f = nullptr,
// Input location for errors and statistics.
const char* filename = nullptr,

View file

@ -104,11 +104,10 @@ public:
std::ostream&
print(const spot::const_twa_graph_ptr& aut,
spot::formula f = nullptr,
double run_time = -1.)
spot::formula f = nullptr)
{
formula_ = f;
return this->spot::stat_printer::print(aut, f, run_time);
return this->spot::stat_printer::print(aut, f);
}
printable_formula formula_;

View file

@ -122,7 +122,7 @@ namespace
int
process_automaton(const spot::const_parsed_aut_ptr& haut) override
{
process_timer timer;
spot::process_timer timer;
timer.start();
auto nba = spot::to_generalized_buchi(haut->aut);
auto aut = post.run(nba, nullptr);

View file

@ -139,7 +139,7 @@ namespace
s.c_str());
}
process_timer timer;
spot::process_timer timer;
timer.start();
auto aut = trans.run(&f);
timer.stop();

View file

@ -519,7 +519,7 @@ namespace
std::string cmd = command.str();
std::cerr << "Running [" << l << translator_num << "]: "
<< cmd << std::endl;
process_timer timer;
spot::process_timer timer;
timer.start();
int es = exec_with_timeout(cmd.c_str());
timer.stop();
@ -603,7 +603,7 @@ namespace
statistics* st = &(*fstats)[translator_num];
st->status_str = status_str;
st->status_code = es;
st->time = timer.get_lap_sw();
st->time = timer.walltime();
// Compute statistics.
if (res)

View file

@ -190,7 +190,8 @@ namespace
}
spot::twa_graph_ptr
translate(unsigned int translator_num, bool& problem, process_timer& timer)
translate(unsigned int translator_num, bool& problem,
spot::process_timer& timer)
{
output.reset(translator_num);
@ -343,13 +344,13 @@ namespace
spot::twa_graph_ptr best_aut = nullptr;
std::string best_stats;
std::string best_cmdname;
process_timer best_timer;
spot::process_timer best_timer;
roundval = round;
for (unsigned t = 0; t < ts; ++t)
{
bool problem;
process_timer timer;
spot::process_timer timer;
auto aut = runner.translate(t, problem, timer);
if (problem)
{

View file

@ -36,6 +36,7 @@
#include "common_range.hh"
#include <spot/misc/hash.hh>
#include <spot/misc/timer.hh>
#include <spot/tl/simplify.hh>
#include <spot/tl/length.hh>
#include <spot/tl/relabel.hh>
@ -578,6 +579,10 @@ namespace
process_formula(spot::formula f,
const char* filename = nullptr, int linenum = 0) override
{
spot::process_timer timer;
timer.start();
if (opt_max_count >= 0 && match_count >= opt_max_count)
{
abort_run = true;
@ -773,6 +778,8 @@ namespace
if (unique && !unique_set.insert(f).second)
matched = false;
timer.stop();
if (matched)
{
if (opt->output_define

View file

@ -341,7 +341,7 @@ main(int argc, char** argv)
for (;;)
{
process_timer timer;
spot::process_timer timer;
timer.start();
if (ap_count_given.max > 0