From c24b4b2ccaeacc54d55e27ff5951864f3eb60713 Mon Sep 17 00:00:00 2001 From: guido Date: Tue, 27 Feb 2001 10:06:38 +0000 Subject: [PATCH] logging off time differences git-svn-id: https://svn.dealii.org/trunk@4040 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/logstream.h | 43 ++++++++++++++++++++++----- deal.II/base/source/log.cc | 20 +++++++++++-- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index 221beacb36..ab00e14db6 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -108,6 +108,16 @@ class LogStream */ bool print_utime; + /** + * Flag for printing time differences. + */ + bool diff_utime; + + /** + * Time of last output line. + */ + double last_time; + public: /** * Standard constructor, since we @@ -115,13 +125,13 @@ class LogStream * @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 @@ -129,17 +139,17 @@ class LogStream * @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 @@ -153,7 +163,7 @@ class LogStream /** * Remove the last prefix. */ - void pop(); + void pop (); /** * Maximum number of levels to be @@ -185,8 +195,27 @@ class LogStream * 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. diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index 0e2753c289..be8ed7bf22 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -25,7 +25,8 @@ LogStream deallog; 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); @@ -94,21 +95,34 @@ LogStream::depth_file(unsigned n) 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(); -- 2.39.5