Quellcode durchsuchen

Added details to trace elements (KernelInfo)

gbeurier vor 7 Jahren
Ursprung
Commit
7c830e7827
1 geänderte Dateien mit 113 neuen und 39 gelöschten Zeilen
  1. 113 39
      src/artis/utils/Trace.hpp

+ 113 - 39
src/artis/utils/Trace.hpp

@@ -36,24 +36,61 @@
 
 namespace artis { namespace utils {
 
-enum TraceType { NONE = 0, CHECK, COMPUTE, INIT, KERNEL, PUT };
+enum TraceType { NONE = 0, CHECK, CONSTRUCT, SUBMODEL_ADD, INTERNAL_DECL,
+                 EXTERNAL_DECL, INTERNAL_LINK, INIT, START, BEFORE_COMPUTE,
+                 COMPUTE, PUT, AFTER_COMPUTE, DESTRUCT, KERNEL};
 
-enum InformationType { CONSTRUCTION, DESTRUCTION,
-                       BEFORE_COMPUTE, AFTER_COMPUTE, INTERNAL_VALUE,
-                       EXTERNAL_VALUE, PUT_TO_EXTERNAL, LINK_INTERNAL };
-
-struct TraceInfo
+struct KernelInfo
 {
+    std::string         _var;
+    bool                _internal_var;
+    std::string         _value;
+    std::string         _tgt_model;
+    std::string         _tgt_internal_var;
+
+    KernelInfo(const std::string& var, bool internal_var,
+               const std::string& value) :
+        _var(var), _internal_var(internal_var), _value(value),
+        _tgt_model(""), _tgt_internal_var("")
+    { }
+
+    KernelInfo(const std::string& var, const std::string& tgt_model,
+               const std::string& tgt_internal_var) :
+        _var(var), _internal_var(true), _value(""),
+        _tgt_model(tgt_model), _tgt_internal_var(tgt_internal_var)
+    { }
 
-    std::string         _src_model_name;
-    artis::kernel::Any  _value;
-    InformationType     _type;
-    std::string         _tgt_model_model;
+    KernelInfo(const std::string& var, bool internal_var) :
+        _var(var), _internal_var(internal_var), _value(""),
+        _tgt_model(""), _tgt_internal_var("")
+    { }
 
-    TraceInfo(const std::string& src_model_name, artis::kernel::Any value,
-                 InformationType type, const std::string& tgt_model_model = "") :
-        _src_model_name(src_model_name), _value(value), _type(type), _tgt_model_model(tgt_model_model)
+    KernelInfo(const std::string& tgt_model) :
+        _var(""), _internal_var(false), _value(""),
+        _tgt_model(tgt_model), _tgt_internal_var("")
     { }
+
+    const std::string& to_string() const {
+        std::ostringstream ss;
+        if( not _var.empty() ){
+            ss << ":";
+            if (not _internal_var)
+                ss << "*";
+            ss << _var;
+        }
+
+        if( not _value.empty()) {
+            ss << "=" << _value;
+        }
+        if(not _tgt_model.empty()) {
+            ss << " " << _tgt_model;
+            if(not _tgt_internal_var.empty()) {
+                ss << ":" << _tgt_internal_var;
+            }
+        }
+
+        return ss.str();
+    }
 };
 
 template < class Time >
@@ -83,14 +120,21 @@ public:
     TraceType get_type() const
     { return _type; }
 
+    const std::vector< KernelInfo >& get_kernel_info() const
+    { return _kernel_info; }
+
     void set_comment(const std::string& comment)
     { _comment = comment; }
 
+    void add_kernel_info(const KernelInfo& info)
+    { _kernel_info.push_back(info); }
+
 private:
     std::string         _model_name;
     typename Time::type _time;
     TraceType           _type;
     std::string         _comment;
+    std::vector< KernelInfo > _kernel_info;
 };
 
 template < class Time >
@@ -103,14 +147,14 @@ public:
     { }
 
     TraceElements filter_model_name(
-        const std::string& model_name) const
+            const std::string& model_name) const
     {
         TraceElements < Time > result;
 
         std::copy_if(TraceElements < Time >::begin(),
                      TraceElements < Time >::end(), std::back_inserter(result),
                      [model_name](TraceElement < Time > const & x)
-                     { return x.get_model_name() == model_name; });
+        { return x.get_model_name() == model_name; });
         return result;
     }
 
@@ -121,7 +165,7 @@ public:
         std::copy_if(TraceElements < Time >::begin(),
                      TraceElements < Time >::end(), std::back_inserter(result),
                      [time](TraceElement < Time > const & x)
-                     { return x.get_time() == time; });
+        { return x.get_time() == time; });
         return result;
     }
 
@@ -132,35 +176,51 @@ public:
         std::copy_if(TraceElements < Time >::begin(),
                      TraceElements < Time >::end(), std::back_inserter(result),
                      [type](TraceElement < Time > const & x)
-                     { return x.get_type() == type; });
+        { return x.get_type() == type; });
         return result;
     }
 
-    std::string to_string() const
+    std::string to_string(artis::utils::DateFormat date_format = artis::utils::DATE_FORMAT_EXTENDED) const
     {
         std::ostringstream ss;
 
         for (typename TraceElements < Time >::const_iterator it =
-                 TraceElements < Time >::begin();
+             TraceElements < Time >::begin();
              it != TraceElements < Time >::end(); ++it) {
-            std::string date = it->get_time() == -1 ? "construction" :
-                                    it->get_time() == 0 ? "initialization" :
-                                         utils::DateTime::toJulianDay(it->get_time());
-            ss << "TRACE: " << it->get_model_name() << " at "
-               << date << " <";
+            ss << "TRACE: ";
+            std::string time = "";
+            if(it->get_time() != Time::null) {
+                std::string date = utils::DateTime::toJulianDayFmt(it->get_time(), date_format);
+                time = "(" + date + ")";
+            }
+            ss << time;
+            std::string type = "none";
             switch (it->get_type())
             {
-            case NONE: ss << "none"; break;
-            case CHECK: ss << "check"; break;
-            case COMPUTE:  ss << "compute"; break;
-            case INIT: ss << "init"; break;
-            case KERNEL: ss << "kernel"; break;
-            case PUT: ss << "put"; break;
+            case NONE: type = "none"; break;
+            case CONSTRUCT: type = "construct"; break;
+            case DESTRUCT: type = "destruct"; break;
+            case CHECK: type = "check"; break;
+            case COMPUTE:  type = "compute"; break;
+            case INIT: type = "init"; break;
+            case KERNEL: type = "kernel"; break;
+            case PUT: type = "put"; break;
             };
-            ss << ">";
+            type = "<" + type + ">";
+            ss << type;
+            std::string model_name = it->get_model_name();
+            ss << " " << model_name;
+
             if (not it->get_comment().empty()) {
                 ss << " => " << it->get_comment();
             }
+
+            for (std::vector < KernelInfo >::const_iterator itk = it->get_kernel_info().begin(); itk != it->get_kernel_info().end(); ++itk) {
+                ss << std::endl;
+                ss << "TRACE: ";
+                ss << time << type << " " << model_name;
+                ss << itk->to_string();
+            }
             ss << std::endl;
         }
         return ss.str();
@@ -177,8 +237,8 @@ public:
     static Trace& trace()
     {
         std::call_once(_flag, [] ()
-                       { _instance.reset(new Trace()); std::cout << "Trace singleton done" << std::endl;}
-            );
+        { _instance.reset(new Trace()); std::cout << "Trace singleton done" << std::endl;}
+        );
         return *_instance;
     }
 
@@ -204,6 +264,9 @@ public:
     void set_element(const TraceElement < Time >& element)
     { _element = element; }
 
+    void add_kernel_info(const KernelInfo& info)
+    { _element.add_kernel_info(info); }
+
     std::ostringstream& sstream()
     {
         if (_sstream == 0) {
@@ -229,8 +292,8 @@ private:
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    const artis::utils::TraceElement < Time >& e)
+        artis::utils::Trace < Time >& trace,
+        const artis::utils::TraceElement < Time >& e)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());
 
@@ -240,8 +303,19 @@ artis::utils::Trace < Time >& operator<<(
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    const std::string& str)
+        artis::utils::Trace < Time >& trace,
+        const artis::utils::KernelInfo& info)
+{
+    std::lock_guard < std::mutex > lock(trace.mutex());
+
+    trace.add_kernel_info(info);
+    return trace;
+}
+
+template < class Time >
+artis::utils::Trace < Time >& operator<<(
+        artis::utils::Trace < Time >& trace,
+        const std::string& str)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());
 
@@ -251,8 +325,8 @@ artis::utils::Trace < Time >& operator<<(
 
 template < class Time >
 artis::utils::Trace < Time >& operator<<(
-    artis::utils::Trace < Time >& trace,
-    typename Time::type t)
+        artis::utils::Trace < Time >& trace,
+        typename Time::type t)
 {
     std::lock_guard < std::mutex > lock(trace.mutex());