]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Log all communication, and replay upon death.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 1 Oct 2002 16:15:09 +0000 (16:15 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 1 Oct 2002 16:15:09 +0000 (16:15 +0000)
git-svn-id: https://svn.dealii.org/trunk@6574 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/contrib/hsl/source/detached_ma27.cc

index d0cbe3e251b70a772c2c575446ea9646c225a368..6a0a51e812a440cc1c8631bf936e5062437da0e2 100644 (file)
 #include <hsl/hsl.h>
 
 #include <vector>
+#include <list>
 #include <iostream>
 #include <cstdio>
 #include <cstdlib>
+#include <typeinfo>
 
 #include <unistd.h>
 #include <pthread.h>
 pid_t master_pid;
 
 
+namespace CommunicationsLog
+{
+  enum Direction { put, get };
+  
+  struct Record 
+  {
+      Direction             direction;
+      const std::type_info* type;
+      unsigned int          count;
+      unsigned int          completed;
+      std::string           description;
+  };
+
+  std::list<Record> communication_log;
+
+  
+  template <typename T>
+  void record_communication (const Direction    direction,
+                             const unsigned int count,
+                             const unsigned int completed,
+                             const std::string &descr)
+  {
+    Record record = {direction, &typeid(T), count, completed, descr};
+    communication_log.push_back (record);
+  };
+
+
+  void list_communication () 
+  {
+    std::cerr << "------------------------------" << std::endl
+              << "Communiction log history:" << std::endl;
+    
+    for (std::list<Record>::const_iterator i=communication_log.begin();
+         i!=communication_log.end(); ++i)
+      std::cerr << (i->direction == put ? "put" : "get")
+                << " "
+                << i->count << " objects of type "
+                << i->type->name()
+                << ", " << i->completed << " completed, description="
+                << i->description
+                << std::endl;
+    std::cerr << "------------------------------" << std::endl;
+  };  
+};
+
+
+
 /**
  * Output an error message and terminate the program.
  */
@@ -48,6 +97,7 @@ void die (const std::string &text)
 {
   std::cerr << "----- detached_ma27: " << text
             << std::endl;
+  CommunicationsLog::list_communication ();
   abort ();
 };
 
@@ -112,7 +162,7 @@ void * monitor_thread (void *)
  * Put a certain number of objects to the output stream.
  */
 template <typename T>
-void put (const T *t, const size_t N, const char */*debug_info*/)
+void put (const T *t, const size_t N, const char *debug_info)
 {
                                    // repeat writing until syscall is
                                    // not interrupted
@@ -127,6 +177,8 @@ void put (const T *t, const size_t N, const char */*debug_info*/)
     die ("not everything was written", ret, sizeof(T)*N);
 
   fflush (NULL);
+  CommunicationsLog::
+    record_communication<T> (CommunicationsLog::put, N, ret, debug_info);
 };
 
 
@@ -135,7 +187,7 @@ void put (const T *t, const size_t N, const char */*debug_info*/)
  * Read a certain number of objects from the input stream.
  */
 template <typename T>
-void get (T *t, const size_t N, const char */*debug_info*/)
+void get (T *t, const size_t N, const char *debug_info)
 {
   unsigned int count = 0;
   while (count < sizeof(T)*N)
@@ -151,6 +203,9 @@ void get (T *t, const size_t N, const char */*debug_info*/)
       else
         count += ret;
     };
+  
+  CommunicationsLog::
+    record_communication<T> (CommunicationsLog::get, N, count, debug_info);
 };
 
 

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.