]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
logging off time differences
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 27 Feb 2001 10:06:38 +0000 (10:06 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 27 Feb 2001 10:06:38 +0000 (10:06 +0000)
git-svn-id: https://svn.dealii.org/trunk@4040 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/logstream.h
deal.II/base/source/log.cc

index 221beacb363810a3b46365a8a43a41d5c01db2e3..ab00e14db67b3f6e9842ddc42240d91674a1f552 100644 (file)
@@ -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.
index 0e2753c289be57d5011b4e9a03cd29be88a69cf2..be8ed7bf22bbc0f394c83c0ac34df6ded0abda1e 100644 (file)
@@ -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();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.