spot: Add %R, %[..]R common option.

For #189.

* NEWS: Update.
* bin/autfilt.cc: Replace stopwatch with process_timer.
* bin/dstar2tgba.cc: Replace stopwatch with process_timer.
* bin/ltl2tgba.cc: Replace stopwatch with process_timer.
* bin/ltlcross.cc: Replace stopwatch with process_timer.
* bin/ltldo.cc: Replace stopwatch with process_timer.
* bin/randaut.cc: Replace stopwatch with process_timer.
* bin/common_aoutput.hh: Implement process_timer, integrate it.
* bin/common_aoutput.cc: Integrate process_timer and implement new
print method.
* spot/misc/timer.hh: Modify timer class and timeinfo struct
i.e. add cutime (children_utime) and cstime (children_stime).
* spot/misc/timer.cc: Help code to behave as before all this.
* spot/twaalgos/dtbasat.cc: Help print_log to behave as before
all this.
* spot/twaalgos/dtwasat.cc: Help print_log to behave as before
all this.
* spot/misc/formater.hh: Add operator<< for spot::timer.
This commit is contained in:
Alexandre GBAGUIDI AISSE 2016-10-24 17:46:26 +02:00 committed by Alexandre Duret-Lutz
parent 3eafbc823c
commit 6ed380709d
14 changed files with 277 additions and 79 deletions

View file

@ -20,10 +20,13 @@
#pragma once
#include <spot/misc/common.hh>
#include <spot/misc/timer.hh>
#include <iostream>
#include <string>
#include <vector>
#define UNUSED(expr) do { (void)(expr); } while (0)
namespace spot
{
class printable
@ -85,6 +88,15 @@ 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
{

View file

@ -27,6 +27,15 @@
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
@ -39,8 +48,11 @@ namespace spot
{
total.utime += i->second.first.utime();
total.stime += i->second.first.stime();
total.cutime += i->second.first.cutime();
total.cstime += i->second.first.cstime();
}
clock_t grand_total = total.utime + total.stime;
clock_t grand_total = total.utime + total.cutime
+ total.stime + total.cstime;
os << std::setw(23) << ""
<< "| user time | sys. time | total |"
@ -61,18 +73,21 @@ namespace spot
const char* sep = t.is_running() ? "+|" : " |";
os << std::setw(22) << name << sep
<< std::setw(6) << t.utime() << ' '
<< std::setw(6) << t.utime() + t.cutime() << ' '
<< std::setw(8) << (total.utime ?
100.0 * t.utime() / total.utime : 0.)
100.0 * (t.utime() + t.cutime())
/ (total.utime + total.cutime) : 0.)
<< sep
<< std::setw(6) << t.stime() << ' '
<< std::setw(6) << t.stime() + t.cstime() << ' '
<< std::setw(8) << (total.stime ?
100.0 * t.stime() / total.stime : 0.)
100.0 * (t.stime() +t.cstime())
/ (total.stime + total.cstime) : 0.)
<< sep
<< std::setw(6) << t.utime() + t.stime() << ' '
<< std::setw(6) << t.utime() + t.cutime() + t.stime()
+ t.cstime() << ' '
<< std::setw(8) << (grand_total ?
(100.0 * (t.utime() + t.stime()) /
grand_total) : 0.)
(100.0 * (t.utime() + t.cutime() + t.stime()
+ t.cstime()) / grand_total) : 0.)
<< sep
<< std::setw(4) << i->second.second
<< std::endl;
@ -80,10 +95,10 @@ namespace spot
os << std::setw(79) << std::setfill('-') << "" << std::setfill(' ')
<< std::endl
<< std::setw(22) << "TOTAL" << " |"
<< std::setw(6) << total.utime << ' '
<< std::setw(6) << total.utime + total.cutime << ' '
<< std::setw(8) << 100.
<< " |"
<< std::setw(6) << total.stime << ' '
<< std::setw(6) << total.stime + total.cstime << ' '
<< std::setw(8) << 100.
<< " |"
<< std::setw(6) << grand_total << ' '

View file

@ -66,19 +66,22 @@ namespace spot
}
};
/// A structure to record elapsed time in clock ticks.
struct time_info
{
time_info()
: utime(0), stime(0)
: utime(0), stime(0), cutime(0), cstime(0)
{
}
clock_t utime;
clock_t stime;
clock_t cutime;
clock_t cstime;
};
/// A timekeeper that accumulate interval of time.
/// A timekeeper that accumulate interval of time in a more detailed way.
/// For instance, you can get the time spent with or without children
/// processes.
class timer
{
public:
@ -96,8 +99,10 @@ namespace spot
#ifdef SPOT_HAVE_TIMES
struct tms tmp;
times(&tmp);
start_.utime = tmp.tms_utime + tmp.tms_cutime;
start_.stime = tmp.tms_stime + tmp.tms_cstime;
start_.utime = tmp.tms_utime;
start_.cutime = tmp.tms_cutime;
start_.stime = tmp.tms_stime;
start_.cstime = tmp.tms_cstime;
#else
start_.utime = clock();
#endif
@ -110,8 +115,10 @@ namespace spot
#ifdef SPOT_HAVE_TIMES
struct tms tmp;
times(&tmp);
total_.utime += tmp.tms_utime + tmp.tms_cutime - start_.utime;
total_.stime += tmp.tms_stime + tmp.tms_cstime - start_.stime;
total_.utime += tmp.tms_utime - start_.utime;
total_.cutime += tmp.tms_cutime - start_.cutime;
total_.stime += tmp.tms_stime - start_.stime;
total_.cstime += tmp.tms_cstime - start_.cstime;
#else
total_.utime += clock() - start_.utime;
#endif
@ -119,7 +126,8 @@ namespace spot
running = false;
}
/// \brief Return the user time of all accumulated interval.
/// \brief Return the user time of the current process (without children)
/// of all accumulated interval.
///
/// Any time interval that has been start()ed but not stop()ed
/// will not be accounted for.
@ -129,7 +137,18 @@ namespace spot
return total_.utime;
}
/// \brief Return the system time of all accumulated interval.
/// \brief Return the user time of children of all accumulated interval.
///
/// Any time interval that has been start()ed but not stop()ed
/// will not be accounted for.
clock_t
cutime() const
{
return total_.cutime;
}
/// \brief Return the system time of the current process (whithout children)
/// of all accumulated interval.
///
/// Any time interval that has been start()ed but not stop()ed
/// will not be accounted for.
@ -139,6 +158,34 @@ namespace spot
return total_.stime;
}
/// \brief Return the system time of children of all accumulated interval.
///
/// Any time interval that has been start()ed but not stop()ed
/// will not be accounted for.
clock_t
cstime() const
{
return total_.cstime;
}
clock_t get_uscp(bool user, bool system, bool children, bool parent) const
{
clock_t res = 0;
if (user && parent)
res += utime();
if (user && children)
res += cutime();
if (system && parent)
res += stime();
if (system && children)
res += cstime();
return res;
}
/// \brief Whether the timer is running.
bool
@ -153,6 +200,10 @@ namespace spot
bool running;
};
// This function declared here must be implemented in each file
// that includes this header, well, only if this operator is needed!
inline std::ostream& operator<<(std::ostream& os, const timer& dt);
/// \brief A map of timer, where each timer has a name.
///
/// Timer_map also keeps track of the number of measures each timer

View file

@ -794,8 +794,10 @@ namespace spot
}
out << ','
<< s.first << ',' << s.second << ','
<< te.utime() << ',' << te.stime() << ','
<< ts.utime() << ',' << ts.stime() << '\n';
<< te.utime() + te.cutime() << ','
<< te.stime() + te.cstime() << ','
<< ts.utime() + ts.cutime() << ','
<< ts.stime() + ts.cstime() << '\n';
}
static bool show = getenv("SPOT_SATSHOW");
if (show && res)

View file

@ -1173,8 +1173,10 @@ namespace spot
}
out << ','
<< s.first << ',' << s.second << ','
<< te.utime() << ',' << te.stime() << ','
<< ts.utime() << ',' << ts.stime() << '\n';
<< te.utime() + te.cutime() << ','
<< te.stime() + te.cstime() << ','
<< ts.utime() + ts.cutime() << ','
<< ts.stime() + ts.cstime() << '\n';
}
static bool show = getenv("SPOT_SATSHOW");
if (show && res)