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

View file

@ -991,7 +991,7 @@ namespace
int int
process_automaton(const spot::const_parsed_aut_ptr& haut) override process_automaton(const spot::const_parsed_aut_ptr& haut) override
{ {
process_timer timer; spot::process_timer timer;
timer.start(); timer.start();
// If --stats or --name is used, duplicate the automaton so we // 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('F', &filename_);
declare('L', &location_); declare('L', &location_);
declare('R', &timer_); declare('R', &timer_);
declare('r', &timer_);
if (input != ltl_input) if (input != ltl_input)
declare('f', &filename_); // Override the formula printer. declare('f', &filename_); // Override the formula printer.
declare('h', &output_aut_); declare('h', &output_aut_);
@ -396,11 +397,11 @@ std::ostream&
hoa_stat_printer::print(const spot::const_parsed_aut_ptr& haut, hoa_stat_printer::print(const spot::const_parsed_aut_ptr& haut,
const spot::const_twa_graph_ptr& aut, const spot::const_twa_graph_ptr& aut,
spot::formula f, 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) const char* csv_prefix, const char* csv_suffix)
{ {
timer_ = ptimer.dt; timer_ = ptimer;
double run_time = ptimer.get_lap_sw();
filename_ = filename ? filename : ""; filename_ = filename ? filename : "";
csv_prefix_ = csv_prefix ? csv_prefix : ""; csv_prefix_ = csv_prefix ? csv_prefix : "";
@ -511,7 +512,7 @@ hoa_stat_printer::print(const spot::const_parsed_aut_ptr& haut,
if (has('x')) if (has('x'))
aut_ap_ = aut->ap(); 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 // Make sure we do not store the automaton until the next one is
// printed, as the registered APs will affect how the next // printed, as the registered APs will affect how the next
// automata are built. // automata are built.
@ -536,7 +537,7 @@ automaton_printer::automaton_printer(stat_style input)
void void
automaton_printer::print(const spot::twa_graph_ptr& aut, automaton_printer::print(const spot::twa_graph_ptr& aut,
// Time for statistics // Time for statistics
process_timer& ptimer, spot::process_timer& ptimer,
spot::formula f, spot::formula f,
// Input location for errors and statistics. // Input location for errors and statistics.
const char* filename, const char* filename,
@ -663,8 +664,16 @@ void printable_timer::print(std::ostream& os, const char* pos) const
if (*pos != '[') if (*pos != '[')
{ {
res = val_.get_uscp(true, true, true, true); if (*pos == 'r')
{
res = val_.walltime();
os << res;
}
else
{
res = val_.cputime(true, true, true, true);
os << res / clocks_per_sec; os << res / clocks_per_sec;
}
return; return;
} }
@ -700,12 +709,15 @@ void printable_timer::print(std::ostream& os, const char* pos) const
} }
while (*pos != ']'); while (*pos != ']');
if (*(pos + 1) == 'r')
percent_error(beg, pos-1);
if (!parent && !children) if (!parent && !children)
parent = children = true; parent = children = true;
if (!user && !system) if (!user && !system)
user = system = true; user = system = true;
res = val_.get_uscp(user, system, children, parent); res = val_.cputime(user, system, children, parent);
os << res / clocks_per_sec; 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; void print(std::ostream& os, const char* pos) const override;
}; };
struct printable_timer final: public spot::printable
struct process_timer
{ {
void start() protected:
spot::process_timer val_;
public:
printable_timer& operator=(const spot::process_timer& val)
{ {
sw.start(); val_ = val;
dt.start(); 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; void print(std::ostream& os, const char* pos) const override;
}; };
@ -166,7 +146,7 @@ public:
print(const spot::const_parsed_aut_ptr& haut, print(const spot::const_parsed_aut_ptr& haut,
const spot::const_twa_graph_ptr& aut, const spot::const_twa_graph_ptr& aut,
spot::formula f, 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); const char* csv_prefix, const char* csv_suffix);
private: private:
@ -210,7 +190,7 @@ public:
void void
print(const spot::twa_graph_ptr& aut, print(const spot::twa_graph_ptr& aut,
process_timer& ptimer, spot::process_timer& ptimer,
spot::formula f = nullptr, spot::formula f = nullptr,
// Input location for errors and statistics. // Input location for errors and statistics.
const char* filename = nullptr, const char* filename = nullptr,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,8 +25,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#define UNUSED(expr) do { (void)(expr); } while (0)
namespace spot namespace spot
{ {
class printable class printable
@ -88,15 +86,6 @@ namespace spot
} }
}; };
// This function was defined to avoid compilation error when
// instantiating function spot::printable_value<spot::timer>::print
// because of: os << val_;
std::ostream& operator<<(std::ostream& os, const timer& dt)
{
UNUSED(dt);
return os;
}
/// The default callback simply writes "%c". /// The default callback simply writes "%c".
class printable_id: public printable class printable_id: public printable
{ {

View file

@ -27,15 +27,6 @@
namespace spot namespace spot
{ {
/*
std::ostream& operator<<(std::ostream& os, const timer& dt)
{
os << "utime<" << dt.utime() << ">, cutime<" << dt.cutime()
<< ">, stime<" << dt.stime() << ">, cstime<" << dt.cstime() << '>';
return os;
}
*/
std::ostream& std::ostream&
timer_map::print(std::ostream& os) const timer_map::print(std::ostream& os) const

View file

@ -290,5 +290,38 @@ namespace spot
tm_type tm; tm_type tm;
}; };
/// \brief Struct used to start and stop both timer and stopwatch clocks.
typedef struct process_timer
{
void start()
{
walltimer.start();
cputimer.start();
}
// 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.
void stop()
{
walltime_lap_ = walltimer.stop();
cputimer.stop();
}
double walltime() const
{
return walltime_lap_;
}
clock_t cputime(bool user, bool system, bool children, bool parent) const
{
return cputimer.get_uscp(user, system, children, parent);
}
private:
spot::timer cputimer;
spot::stopwatch walltimer;
double walltime_lap_ = 0;
} process_timer;
/// @} /// @}
} }

View file

@ -343,7 +343,6 @@ namespace spot
declare('g', &gen_acc_); declare('g', &gen_acc_);
declare('n', &nondetstates_); declare('n', &nondetstates_);
declare('p', &complete_); declare('p', &complete_);
declare('r', &run_time_);
declare('s', &states_); declare('s', &states_);
declare('S', &scc_); // Historical. Deprecated. Use %c instead. declare('S', &scc_); // Historical. Deprecated. Use %c instead.
declare('t', &trans_); declare('t', &trans_);
@ -353,11 +352,9 @@ namespace spot
} }
std::ostream& std::ostream&
stat_printer::print(const const_twa_graph_ptr& aut, stat_printer::print(const const_twa_graph_ptr& aut, formula f)
formula f, double run_time)
{ {
form_ = f; form_ = f;
run_time_ = run_time;
if (has('t')) if (has('t'))
{ {

View file

@ -103,8 +103,7 @@ namespace spot
/// The \a f argument is not needed if the Formula does not need /// The \a f argument is not needed if the Formula does not need
/// to be output, and so is \a run_time). /// to be output, and so is \a run_time).
std::ostream& std::ostream&
print(const const_twa_graph_ptr& aut, formula f = nullptr, print(const const_twa_graph_ptr& aut, formula f = nullptr);
double run_time = -1.);
private: private:
const char* format_; const char* format_;
@ -118,7 +117,6 @@ namespace spot
printable_value<unsigned> nondetstates_; printable_value<unsigned> nondetstates_;
printable_value<unsigned> deterministic_; printable_value<unsigned> deterministic_;
printable_value<unsigned> complete_; printable_value<unsigned> complete_;
printable_value<double> run_time_;
printable_value<std::string> gen_acc_; printable_value<std::string> gen_acc_;
}; };