*/
bool print_utime;
+ /**
+ * Flag for printing time differences.
+ */
+ bool diff_utime;
+
+ /**
+ * Time of last output line.
+ */
+ double last_time;
+
public:
/**
* Standard constructor, since we
* @p{deallog} in the library. Set the
* standard output stream to @p{std::cerr}.
*/
- LogStream();
+ LogStream ();
/**
* Enable output to a second
* stream @p{o}.
*/
- void attach(std::ostream& o);
+ void attach (std::ostream& o);
/**
* Disable output to the second
* @p{close} on the stream that was
* previously attached to this object.
*/
- void detach();
+ void detach ();
/**
* Gives the default stream (@p{std_out}).
*/
- std::ostream& get_console();
+ std::ostream& get_console ();
/**
* Gives the file stream.
*/
- std::ostream& get_file_stream();
+ std::ostream& get_file_stream ();
/**
* Push another prefix on the
/**
* Remove the last prefix.
*/
- void pop();
+ void pop ();
/**
* Maximum number of levels to be
* be prepended by the user time used
* by the running program so far.
*/
- void log_execution_time(bool flag);
+ void log_execution_time (bool flag);
+ /**
+ * Output time differences
+ * between consecutive logs. If
+ * this function is invoked with
+ * @p{true}, the time difference
+ * between the previous log line
+ * and the recent one is
+ * printed. If it is invoked with
+ * @p{false}, the accumulated
+ * time since start of the
+ * program is printed (default
+ * behavior).
+ *
+ * The measurement of times is
+ * not changed by this function,
+ * just the output.
+ */
+ void log_time_differences (bool flag);
+
/**
* Output a constant something through
* this stream.
LogStream::LogStream()
: std_out(&std::cerr), file(0), was_endl(true),
std_depth(10000), file_depth(10000),
- print_utime(false)
+ print_utime(false), diff_utime(false),
+ last_time (0.)
{
prefixes.push("DEAL:");
std_out->setf(std::ios::showpoint | std::ios::left);
void
-LogStream::log_execution_time(bool flag)
+LogStream::log_execution_time (bool flag)
{
print_utime = flag;
}
+void
+LogStream::log_time_differences (bool flag)
+{
+ diff_utime = flag;
+}
+
+
void
LogStream::print_line_head()
{
rusage usage;
- float utime = 0.;
+ double utime = 0.;
if (print_utime)
{
getrusage(RUSAGE_SELF, &usage);
utime = usage.ru_utime.tv_sec + 1.e-6 * usage.ru_utime.tv_usec;
+ if (diff_utime)
+ {
+ double diff = utime - last_time;
+ last_time = utime;
+ utime = diff;
+ }
}
const string& head = prefixes.top();