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:
parent
302095ff9e
commit
ad9bc644ba
16 changed files with 89 additions and 81 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -663,8 +664,16 @@ void printable_timer::print(std::ostream& os, const char* pos) const
|
|||
|
||||
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;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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_;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace
|
|||
s.c_str());
|
||||
}
|
||||
|
||||
process_timer timer;
|
||||
spot::process_timer timer;
|
||||
timer.start();
|
||||
auto aut = trans.run(&f);
|
||||
timer.stop();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define UNUSED(expr) do { (void)(expr); } while (0)
|
||||
|
||||
namespace spot
|
||||
{
|
||||
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".
|
||||
class printable_id: public printable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,15 +27,6 @@
|
|||
|
||||
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&
|
||||
timer_map::print(std::ostream& os) const
|
||||
|
|
|
|||
|
|
@ -290,5 +290,38 @@ namespace spot
|
|||
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;
|
||||
|
||||
/// @}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -343,7 +343,6 @@ namespace spot
|
|||
declare('g', &gen_acc_);
|
||||
declare('n', &nondetstates_);
|
||||
declare('p', &complete_);
|
||||
declare('r', &run_time_);
|
||||
declare('s', &states_);
|
||||
declare('S', &scc_); // Historical. Deprecated. Use %c instead.
|
||||
declare('t', &trans_);
|
||||
|
|
@ -353,11 +352,9 @@ namespace spot
|
|||
}
|
||||
|
||||
std::ostream&
|
||||
stat_printer::print(const const_twa_graph_ptr& aut,
|
||||
formula f, double run_time)
|
||||
stat_printer::print(const const_twa_graph_ptr& aut, formula f)
|
||||
{
|
||||
form_ = f;
|
||||
run_time_ = run_time;
|
||||
|
||||
if (has('t'))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -103,8 +103,7 @@ namespace spot
|
|||
/// The \a f argument is not needed if the Formula does not need
|
||||
/// to be output, and so is \a run_time).
|
||||
std::ostream&
|
||||
print(const const_twa_graph_ptr& aut, formula f = nullptr,
|
||||
double run_time = -1.);
|
||||
print(const const_twa_graph_ptr& aut, formula f = nullptr);
|
||||
|
||||
private:
|
||||
const char* format_;
|
||||
|
|
@ -118,7 +117,6 @@ namespace spot
|
|||
printable_value<unsigned> nondetstates_;
|
||||
printable_value<unsigned> deterministic_;
|
||||
printable_value<unsigned> complete_;
|
||||
printable_value<double> run_time_;
|
||||
printable_value<std::string> gen_acc_;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue