Przeglądaj źródła

Added distinction between kernel trace and user trace.
Restricted access to kernel traces.

gbeurier 7 lat temu
rodzic
commit
2f1656a001

+ 35 - 16
src/artis/kernel/AbstractAtomicModel.hpp

@@ -49,6 +49,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
+                   true,
                    boost::core::demangle(typeid(T).name()).erase(0,6),
                    utils::DoubleTime::null,
                    utils::CONSTRUCT);
@@ -59,7 +60,7 @@ public:
     virtual ~AbstractAtomicModel()
     {
 #ifdef WITH_TRACE
-        trace_element(utils::DoubleTime::null,
+        trace_element(true, utils::DoubleTime::null,
                       utils::CONSTRUCT);
 #endif
     }
@@ -71,8 +72,8 @@ public:
     {
 
 #ifdef WITH_TRACE
-        trace_element(t, utils::AFTER_COMPUTE);
-        trace_internals(t, utils::AFTER_COMPUTE);
+        trace_element(true, t, utils::AFTER_COMPUTE);
+        trace_internals(true, t, utils::AFTER_COMPUTE);
 #else
         (void) t;
 #endif
@@ -83,9 +84,9 @@ public:
     {
 
 #ifdef WITH_TRACE
-        trace_element(t, utils::BEFORE_COMPUTE);
-        trace_internals(t, utils::BEFORE_COMPUTE);
-        trace_externals(t, utils::BEFORE_COMPUTE);
+        trace_element(true, t, utils::BEFORE_COMPUTE);
+        trace_internals(true, t, utils::BEFORE_COMPUTE);
+        trace_externals(true, t, utils::BEFORE_COMPUTE);
 #else
         (void) t;
 #endif
@@ -174,22 +175,40 @@ public:
         state.last_time(type::last_time);
     }
 
-    virtual void trace_element(typename U::type t, utils::TraceType type = utils::KERNEL, std::string comment = "") const
+    virtual void stable()
+    { Externals < T, U, V >::updated = false; }
+
+    virtual void trace_element(typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const
+    {trace_element(false, t, type, comment);}
+
+    virtual void trace_internals(typename U::type t, utils::TraceType type) const
+    {trace_internals(false, t, type);}
+
+    virtual void trace_externals(typename U::type t, utils::TraceType type = utils::NONE) const
+    {trace_externals(false, t, type);}
+
+    virtual void trace_model(typename U::type t, utils::TraceType type = utils::NONE) const
+    {trace_model(false, t, type);}
+
+private:
+    void trace_element(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const
     {
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
+                   from_kernel,
                   AbstractAtomicModel < T, U, V >::path(this),
                    t, type)
-            << comment;;
+            << comment;
         utils::Trace < utils::DoubleTime >::trace().flush();
     }
 
-    virtual void trace_internals(typename U::type t, utils::TraceType type) const
+    void trace_internals(bool from_kernel, typename U::type t, utils::TraceType type) const
     {
         for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
             if (not Internals < T, U, V >::get(i).is_null()) {
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >(
+                               from_kernel,
                               AbstractAtomicModel < T, U, V >::path(this),
                                t, type)
                         << utils::KernelInfo(
@@ -202,12 +221,13 @@ public:
         }
     }
 
-    virtual void trace_externals(typename U::type t, utils::TraceType type = utils::KERNEL) const
+    void trace_externals(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
     {
         for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
             if (not Externals < T, U, V >::get(i).is_null()) {
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >(
+                               from_kernel,
                               AbstractAtomicModel < T, U, V >::path(this),
                                t, type)
                         << utils::KernelInfo(
@@ -220,15 +240,14 @@ public:
         }
     }
 
-    virtual void trace_model(typename U::type t, utils::TraceType type = utils::KERNEL) const
+    void trace_model(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
     {
-        trace_element(t, type);
-        trace_internals(t, type);
-        trace_externals(t, type);
+        trace_element(from_kernel, t, type);
+        trace_internals(from_kernel, t, type);
+        trace_externals(from_kernel, t, type);
     }
 
-    virtual void stable()
-    { Externals < T, U, V >::updated = false; }
+
 };
 
 } }

+ 56 - 31
src/artis/kernel/AbstractCoupledModel.hpp

@@ -49,6 +49,11 @@ class AbstractCoupledModel : public AbstractModel < U, V >,
     typedef std::map < int, std::pair < type*,
                                         int > > SubModelInternals;
 
+#ifdef WITH_TRACE
+    template < typename T, typename U, typename V, typename W >
+    friend class Simulator;
+#endif
+
 public:
     struct Var
     {
@@ -70,6 +75,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
+                   true,
                    boost::core::demangle(typeid(T).name()).erase(0,6),
                    utils::DoubleTime::null,
                    utils::CONSTRUCT);
@@ -80,7 +86,7 @@ public:
     virtual ~AbstractCoupledModel()
     {
 #ifdef WITH_TRACE
-        trace_element(utils::DoubleTime::null,
+        trace_element(true, utils::DoubleTime::null,
                       utils::DESTRUCT);
 #endif
     }
@@ -89,8 +95,8 @@ public:
     {
 
 #ifdef WITH_TRACE
-        trace_element(t, utils::AFTER_COMPUTE);
-        trace_internals(t, utils::AFTER_COMPUTE);
+        trace_element(true, t, utils::AFTER_COMPUTE);
+        trace_internals(true, t, utils::AFTER_COMPUTE);
 #else
         (void) t;
 #endif
@@ -113,9 +119,9 @@ public:
     {
 
 #ifdef WITH_TRACE
-        trace_element(t, utils::BEFORE_COMPUTE);
-        trace_internals(t, utils::BEFORE_COMPUTE);
-        trace_externals(t, utils::BEFORE_COMPUTE);
+        trace_element(true, t, utils::BEFORE_COMPUTE);
+        trace_internals(true, t, utils::BEFORE_COMPUTE);
+        trace_externals(true, t, utils::BEFORE_COMPUTE);
 #else
         (void) t;
 #endif
@@ -324,22 +330,50 @@ public:
         Externals < T, U, V >::save(this, state);
     }
 
-    virtual void trace_element(typename U::type t, utils::TraceType type = utils::KERNEL, std::string comment = "") const
+    virtual void stable()
+    { Externals < T, U, V >::updated = false; }
+
+    void submodel(unsigned int index, type* model)
+    {
+        if (model) {
+            submodels[index] = model;
+            model->set_parent(this);
+        } else {
+            submodels[index] = 0;
+        }
+    }
+
+    virtual void trace_element(typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const
+    {trace_element(false, t, type, comment);}
+
+    virtual void trace_internals(typename U::type t, utils::TraceType type) const
+    {trace_internals(false, t, type);}
+
+    virtual void trace_externals(typename U::type t, utils::TraceType type = utils::NONE) const
+    {trace_externals(false, t, type);}
+
+    virtual void trace_model(typename U::type t, utils::TraceType type = utils::NONE) const
+    {trace_model(false, t, type);}
+
+private:
+    void trace_element(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE, std::string comment = "") const
     {
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >(
+                   from_kernel,
                   AbstractCoupledModel < T, U, V, W >::path(this),
                    t, type)
             << comment;
         utils::Trace < utils::DoubleTime >::trace().flush();
     }
 
-    virtual void trace_internals(typename U::type t, utils::TraceType type) const
+    void trace_internals(bool from_kernel, typename U::type t, utils::TraceType type) const
     {
         for (size_t i = 0; i < Internals < T, U, V >::size(); ++i) {
             if (not Internals < T, U, V >::get(i).is_null()) {
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >(
+                               from_kernel,
                               AbstractCoupledModel < T, U, V, W >::path(this),
                                t, type)
                         << utils::KernelInfo(
@@ -352,12 +386,13 @@ public:
         }
     }
 
-    virtual void trace_externals(typename U::type t, utils::TraceType type = utils::KERNEL) const
+    void trace_externals(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
     {
         for (size_t i = 0; i < Externals < T, U, V >::size(); ++i) {
             if (not Externals < T, U, V >::get(i).is_null()) {
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >(
+                               from_kernel,
                               AbstractCoupledModel < T, U, V, W >::path(this),
                                t, type)
                         << utils::KernelInfo(
@@ -370,32 +405,18 @@ public:
         }
     }
 
-    virtual void trace_model(typename U::type t, utils::TraceType type = utils::KERNEL) const
+    void trace_model(bool from_kernel, typename U::type t, utils::TraceType type = utils::NONE) const
     {
-        trace_element(t, type);
-        trace_internals(t, type);
-        trace_externals(t, type);
+        trace_element(from_kernel, t, type);
+        trace_internals(from_kernel, t, type);
+        trace_externals(from_kernel, t, type);
         typename AbstractCoupledModel::Submodels::const_iterator it =
                 submodels.begin();
 
-        while (it != submodels.end()) {
-            it->second->trace_model(t, type);
-            ++it;
-        }
-    }
-
-
-    virtual void stable()
-    { Externals < T, U, V >::updated = false; }
-
-    void submodel(unsigned int index, type* model)
-    {
-        if (model) {
-            submodels[index] = model;
-            model->set_parent(this);
-        } else {
-            submodels[index] = 0;
-        }
+//        while (it != submodels.end()) {
+//            it->second->trace_model(from_kernel, t, type);
+//            ++it;
+//        }
     }
 
 protected:
@@ -425,6 +446,7 @@ protected:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                       AbstractCoupledModel < T, U, V, W >::path(this),
                       utils::DoubleTime::null,
                       utils::INTERNAL_LINK)
@@ -448,6 +470,7 @@ protected:
 #ifdef WITH_TRACE
             utils::Trace < utils::DoubleTime >::trace()
                     << utils::TraceElement < utils::DoubleTime >(
+                           true,
                           AbstractCoupledModel < T, U, V, W >::path(this),
                           utils::DoubleTime::null,
                           utils::INTERNAL_LINK)
@@ -472,6 +495,7 @@ protected:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                        AbstractCoupledModel < T, U, V, W >::path(this),
                        utils::DoubleTime::null,
                        utils::SUBMODEL_ADD)
@@ -494,6 +518,7 @@ protected:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                        AbstractCoupledModel < T, U, V, W >::path(this),
                        utils::DoubleTime::null,
                        utils::SUBMODEL_ADD)

+ 6 - 1
src/artis/kernel/AbstractModel.hpp

@@ -82,7 +82,12 @@ public:
         if (check(t) and (last_time != t or
                           (last_time == t and is_updated()))) {
 #ifdef WITH_TRACE
-        trace_element(t, utils::COMPUTE);
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >(
+                   true,
+                  AbstractModel < Time, Parameters >::path(this),
+                   t, utils::COMPUTE);
+        utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
             compute(t, last_time == t);
             last_time = t;

+ 3 - 0
src/artis/kernel/Externals.hpp

@@ -89,6 +89,7 @@ public:
 #ifdef WITH_TRACE
             utils::Trace < utils::DoubleTime >::trace()
                     << utils::TraceElement < utils::DoubleTime >(
+                           true,
                            dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
                            utils::DoubleTime::null,
                            utils::EXTERNAL_DECL)
@@ -111,6 +112,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                        dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
                        utils::DoubleTime::null,
                        utils::EXTERNAL_DECL)
@@ -143,6 +145,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                        dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
                        t, utils::PUT)
                 << utils::KernelInfo(external_names[index], true,

+ 2 - 0
src/artis/kernel/Internals.hpp

@@ -71,6 +71,7 @@ public:
 #ifdef WITH_TRACE
             utils::Trace < utils::DoubleTime >::trace()
                     << utils::TraceElement < utils::DoubleTime >(
+                           true,
                            dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
                            utils::DoubleTime::null,
                            utils::INTERNAL_DECL)
@@ -94,6 +95,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
                 << utils::TraceElement < utils::DoubleTime >(
+                       true,
                        dynamic_cast<T*>(this)->path(dynamic_cast<T*>(this)),
                        utils::DoubleTime::null,
                        utils::INTERNAL_DECL)

+ 2 - 3
src/artis/kernel/Simulator.hpp

@@ -57,9 +57,8 @@ public:
         _observer.init();
 
 #ifdef WITH_TRACE
-        _model->trace_element(utils::DoubleTime::null,
-                              utils::INIT);
-        _model->trace_model(utils::DoubleTime::null,
+        _model->trace_model(true,
+                            utils::DoubleTime::null,
                             utils::INIT);
 #endif
     }

+ 45 - 4
src/artis/utils/Trace.hpp

@@ -38,6 +38,22 @@
 #include <iso646.h>
 #endif
 
+#ifdef WITH_TRACE
+//fwd decl for friend classes in TraceElement
+namespace artis { namespace kernel {
+    template < typename T, typename U, typename V, typename W >
+    class AbstractCoupledModel;
+    template < typename T, typename U, typename V >
+    class AbstractAtomicModel;
+    template < typename Time, typename Parameters >
+    class AbstractModel;
+    template < typename T, typename U, typename V >
+    class Internals;
+    template < typename T, typename U, typename V >
+    class Externals;
+}}
+#endif
+
 namespace artis { namespace utils {
 
 enum TraceType { NONE = 0, CHECK, CONSTRUCT, SUBMODEL_ADD, INTERNAL_DECL,
@@ -125,12 +141,14 @@ template < class Time >
 class TraceElement
 {
 public:
-    TraceElement() : _time(Time::null), _type(NONE)
+    TraceElement() : _time(Time::null), _type(NONE),
+                     _from_kernel(false)
     { }
 
     TraceElement(const std::string& model_name, typename Time::type time,
                  TraceType type) :
-        _model_name(model_name), _time(time), _type(type)
+        _model_name(model_name), _time(time), _type(type),
+        _from_kernel(false)
     { }
 
     virtual ~TraceElement()
@@ -154,6 +172,9 @@ public:
     void set_comment(const std::string& comment)
     { _comment = comment; }
 
+    bool from_kernel() const
+    { return _from_kernel; }
+
     void set_kernel_info(const KernelInfo& info)
     { _kernel_info = info; }
 
@@ -163,6 +184,26 @@ private:
     TraceType           _type;
     std::string         _comment;
     KernelInfo         _kernel_info;
+    bool _from_kernel;
+
+#ifdef WITH_TRACE
+    template < typename T, typename U, typename V, typename W >
+    friend class artis::kernel::AbstractCoupledModel;
+    template < typename T, typename U, typename V >
+    friend class artis::kernel::AbstractAtomicModel;
+    template < typename Time, typename Parameters >
+    friend class artis::kernel::AbstractModel;
+    template < typename T, typename U, typename V >
+    friend class artis::kernel::Internals;
+    template < typename T, typename U, typename V >
+    friend class artis::kernel::Externals;
+private:
+    TraceElement(bool from_kernel, const std::string& model_name, typename Time::type time,
+                 TraceType type) :
+        _model_name(model_name), _time(time), _type(type),
+        _from_kernel(from_kernel)
+    { }
+#endif
 };
 
 template < class Time >
@@ -215,7 +256,7 @@ public:
         for (typename TraceElements < Time >::const_iterator it =
              TraceElements < Time >::begin();
              it != TraceElements < Time >::end(); ++it) {
-            ss << "TRACE";
+            ss << (it->from_kernel() ? "KERNEL" : "TRACE");
             if(it->get_time() != Time::null) {
                ss << "(" << utils::DateTime::toJulianDayFmt(it->get_time(), date_format) << ")";
             }
@@ -244,7 +285,7 @@ public:
     static Trace& trace()
     {
         std::call_once(_flag, [] ()
-        { _instance.reset(new Trace()); std::cout << "Trace singleton done" << std::endl;}
+        { _instance.reset(new Trace());}
         );
         return *_instance;
     }

+ 0 - 2
src/test/models.hpp

@@ -203,9 +203,7 @@ public:
 
         ++_n;
 
-
         this->trace_element(t, artis::utils::COMPUTE, "Stop");
-
     }
 
     void init(double t, const ModelParameters& parameters)