瀏覽代碼

Added construction, destruction and submodels traces

gbeurier 7 年之前
父節點
當前提交
dcbc3cd552

+ 10 - 1
src/artis/kernel/AbstractAtomicModel.hpp

@@ -45,7 +45,16 @@ class AbstractAtomicModel : public AbstractModel < U, V >,
 
 public:
     AbstractAtomicModel(const type* parent = 0) : type(parent)
-    { }
+    {
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                         utils::KERNEL)
+            << "NEW ATOMIC MODEL - "
+            << typeid(T).name();
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
+    }
 
     virtual ~AbstractAtomicModel()
     { }

+ 44 - 2
src/artis/kernel/AbstractCoupledModel.hpp

@@ -62,10 +62,28 @@ public:
     };
 
     AbstractCoupledModel(const type* parent = 0) : type(parent)
-    { }
+    {
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                         utils::KERNEL)
+            << "NEW COUPLED MODEL - "
+            << typeid(T).name();
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
+    }
 
     virtual ~AbstractCoupledModel()
-    { }
+    {
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", 0,
+                                                         utils::KERNEL)
+            << "DESTRUCTION - "
+            << AbstractCoupledModel < T, U, V, W >::path(this);
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
+    }
 
     virtual void after(typename U::type t)
     {
@@ -378,6 +396,7 @@ protected:
     {
         for (typename std::initializer_list < Var >::iterator it =
                  internals.begin(); it != internals.end(); ++it) {
+
             submodel_internals[it->index] =
                 std::pair < type*, int >(it->model, it->sub_index);
         }
@@ -391,6 +410,18 @@ protected:
                  models.begin(); it != models.end(); ++it) {
             submodels[it->first] = it->second;
             it->second->set_parent(this);
+
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                         utils::KERNEL)
+            << "ADD SUBMODEL - "
+            << AbstractCoupledModel < T, U, V, W >::path(it->second)
+            << " to "
+            << AbstractCoupledModel < T, U, V, W >::path(this);
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
+
         }
     }
 
@@ -401,6 +432,17 @@ protected:
         }
         setsubmodels[index].push_back(model);
         model->set_parent(this);
+
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
+                                                         utils::KERNEL)
+            << "ADD SUBMODEL - "
+            << AbstractCoupledModel < T, U, V, W >::path(model)
+            << " to "
+            << AbstractCoupledModel < T, U, V, W >::path(this);
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
     }
 
 private:

+ 5 - 2
src/artis/utils/Trace.hpp

@@ -124,8 +124,11 @@ public:
         for (typename TraceElements < Time >::const_iterator it =
                  TraceElements < Time >::begin();
              it != TraceElements < Time >::end(); ++it) {
+            std::string date = it->get_time() == -1 ? "Start" :
+                                    it->get_time() == 0 ? "End" :
+                                                 utils::DateTime::toJulianDay(it->get_time());
             ss << "TRACE: " << it->get_model_name() << " at "
-               << utils::DateTime::toJulianDay(it->get_time()) << " <";
+               << date << " <";
             switch (it->get_type())
             {
             case NONE: ss << "none"; break;
@@ -155,7 +158,7 @@ public:
     static Trace& trace()
     {
         std::call_once(_flag, [] ()
-                       { _instance.reset(new Trace()); }
+                       { _instance.reset(new Trace()); std::cout << "Trace singleton done" << std::endl;}
             );
         return *_instance;
     }

+ 9 - 4
src/test/test-context.cpp

@@ -50,10 +50,10 @@ int main()
                      artis::utils::DateTime::toJulianDayNumber("2016-1-5"));
 
     {
-        ASimulator simulator(new RootModel, globalParameters);
-
         ::Trace::trace().clear();
 
+        ASimulator simulator(new RootModel, globalParameters);
+
         simulator.init(artis::utils::DateTime::toJulianDayNumber("2016-1-1"),
                        modelParameters);
         simulator.run(context);
@@ -71,10 +71,12 @@ int main()
     std::cout << "==== PAUSE ====" << std::endl;
 
     {
+        ::Trace::trace().clear();
+
         AContext new_context(context);
+
         ASimulator simulator(new RootModel, globalParameters);
 
-        ::Trace::trace().clear();
         new_context.begin(
             artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
         new_context.end(
@@ -87,15 +89,18 @@ int main()
     std::cout << "==== PAUSE ====" << std::endl;
 
     {
+        ::Trace::trace().clear();
+
         AContext new_context;
+
         ASimulator simulator(new RootModel, globalParameters);
 
         std::ifstream is("state");
+
         boost::archive::binary_iarchive ia(is);
 
         ia >> new_context;
 
-        ::Trace::trace().clear();
         new_context.begin(
             artis::utils::DateTime::toJulianDayNumber("2016-1-6"));
         new_context.end(