2
0

3 Коммиты f63de1361e ... 7c830e7827

Автор SHA1 Сообщение Дата
  gbeurier 7c830e7827 Added details to trace elements (KernelInfo) 7 лет назад
  gbeurier ccb7039f15 Changed TraceType meaning and trace syntax (to confirm) 7 лет назад
  gbeurier 89ec0e2ff3 Added public toJulianDay format 7 лет назад

+ 15 - 5
src/artis/kernel/AbstractAtomicModel.hpp

@@ -48,16 +48,25 @@ public:
     {
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
-                                                         utils::KERNEL)
-            << "NEW ATOMIC MODEL - "
-            << typeid(T).name();
+            << utils::TraceElement < utils::DoubleTime >(
+                   boost::core::demangle(typeid(T).name()).erase(0,6),
+                   utils::DoubleTime::null,
+                   utils::CONSTRUCT);
         utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
     }
 
     virtual ~AbstractAtomicModel()
-    { }
+    {
+#ifdef WITH_TRACE
+        utils::Trace < utils::DoubleTime >::trace()
+            << utils::TraceElement < utils::DoubleTime >(
+                   boost::core::demangle(typeid(T).name()).erase(0,6),
+                   utils::DoubleTime::null,
+                   utils::DESTRUCT);
+        utils::Trace < utils::DoubleTime >::trace().flush();
+#endif
+    }
 
     virtual const Node < U >* atomic(unsigned int /* index */) const
     { return this; }
@@ -88,6 +97,7 @@ public:
                                                          utils::KERNEL)
             << "BEFORE - "
             << AbstractAtomicModel < T, U, V >::path(this);
+        utils::Trace < utils::DoubleTime >::trace().flush();
        trace_model(t);
 #else
         (void) t;

+ 15 - 15
src/artis/kernel/AbstractCoupledModel.hpp

@@ -69,10 +69,10 @@ public:
     {
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
-            << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
-                                                         utils::KERNEL)
-            << "NEW COUPLED MODEL - "
-            << typeid(T).name();
+            << utils::TraceElement < utils::DoubleTime >(
+                   boost::core::demangle(typeid(T).name()).erase(0,6),
+                   utils::DoubleTime::null,
+                   utils::CONSTRUCT);
         utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
     }
@@ -81,10 +81,10 @@ public:
     {
 #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::TraceElement < utils::DoubleTime >(
+                   boost::core::demangle(typeid(T).name()).erase(0,6),
+                   utils::DoubleTime::null,
+                   utils::DESTRUCT);
         utils::Trace < utils::DoubleTime >::trace().flush();
 #endif
     }
@@ -95,7 +95,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
-                                                         utils::KERNEL)
+                                                         utils::AFTER_COMPUTE)
             << "AFTER - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
@@ -124,7 +124,7 @@ public:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", t,
-                                                         utils::KERNEL)
+                                                         utils::BEFORE_COMPUTE)
             << "BEFORE - "
             << AbstractCoupledModel < T, U, V, W >::path(this);
         utils::Trace < utils::DoubleTime >::trace().flush();
@@ -299,10 +299,10 @@ public:
                     "/[" + std::to_string(i) + "]" +
                     boost::core::demangle(typeid(*this).name());
             } else {
-                return p + "/" + boost::core::demangle(typeid(*this).name());
+                return p + "/" + boost::core::demangle(typeid(*this).name()).erase(0,6);
             }
         } else {
-            return boost::core::demangle(typeid(*this).name());
+            return boost::core::demangle(typeid(*this).name()).erase(0,6);
         }
     }
 
@@ -423,7 +423,7 @@ protected:
 #ifdef WITH_TRACE
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
-                                                                     utils::KERNEL)
+                                                                     utils::INTERNAL_LINK)
                         << "LINK INTERNAL "
                         << AbstractCoupledModel < T, U, V, W >::path(this)
                         << ":"
@@ -447,7 +447,7 @@ protected:
 #ifdef WITH_TRACE
                 utils::Trace < utils::DoubleTime >::trace()
                         << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
-                                                                     utils::KERNEL)
+                                                                     utils::INTERNAL_DECL)
                         << "LINK INTERNAL "
                         << AbstractCoupledModel < T, U, V, W >::path(this)
                         << ":"
@@ -473,7 +473,7 @@ protected:
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", -1,
-                                                         utils::KERNEL)
+                                                         utils::SUBMODEL_ADD)
             << "SUBMODEL - "
             << AbstractCoupledModel < T, U, V, W >::path(it->second)
             << " to "

+ 2 - 2
src/artis/kernel/AbstractModel.hpp

@@ -96,10 +96,10 @@ public:
         if (index >= 0) {
             return p +
                 "/[" + std::to_string(index) + "]" +
-                boost::core::demangle(typeid(*child).name());
+                boost::core::demangle(typeid(*child).name()).erase(0,6);
         } else {
             return (p.empty() ? "" : p + "/") +
-                boost::core::demangle(typeid(*child).name());
+                boost::core::demangle(typeid(*child).name()).erase(0,6);
         }
     }
 

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

@@ -53,14 +53,13 @@ public:
 
     void init(double time, const V& parameters)
     {
-        std::cout << "LAUNCH INIT" << std::endl;
         _model->init(time, parameters);
         _observer.init();
 
 #ifdef WITH_TRACE
         utils::Trace < utils::DoubleTime >::trace()
             << utils::TraceElement < utils::DoubleTime >("KERNEL", 0,
-                                                         utils::KERNEL)
+                                                         utils::INIT)
             << "GLOBAL VALUES - "
             << _model->path(_model);
         utils::Trace < utils::DoubleTime >::trace().flush();

+ 22 - 21
src/artis/utils/DateTime.cpp

@@ -86,12 +86,7 @@ struct intern_date
     long mminutes;
     long mseconds;
 
-    enum STR_FORMAT
-    {
-	extended, //"%Y-%m-%d %H:%M:%S"
-	ymd,      //"%Y-%m-%d"
-	hms       //"%H:%M:%S"
-    };
+
 
     intern_date() noexcept
 	: myear(1400)
@@ -133,11 +128,11 @@ struct intern_date
 	mseconds = std::floor(f);
     }
 
-    std::string toString(STR_FORMAT fmt) noexcept
+    std::string toString(DateFormat fmt) noexcept
     {
 	std::stringstream ss;
 
-	if (fmt != hms) {
+    if (fmt != DATE_FORMAT_HMS) {
 	    ss << myear << "-";
 	    if (mmonth < 10) {
 		ss << "0";
@@ -148,10 +143,10 @@ struct intern_date
 	    }
 	    ss << mday ;
 	}
-	if (fmt == extended) {
+    if (fmt == DATE_FORMAT_EXTENDED) {
 	    ss << " ";
 	}
-	if (fmt != ymd) {
+    if (fmt != DATE_FORMAT_YMD) {
 	    if (mhours < 10) {
 		ss << "0";
 	    }
@@ -173,11 +168,11 @@ struct intern_date
     //format : not extended = "%Y-%m-%d"
     //         extended     = "%Y-%m-%d %H:%M:%S"
     //return true if no error
-    bool fromString(const std::string& date, STR_FORMAT toparse) noexcept
+    bool fromString(const std::string& date, DateFormat toparse) noexcept
     {
 	bool error = false;
 
-	if (toparse == extended) {
+    if (toparse == DATE_FORMAT_EXTENDED) {
 	    //parse "%Y-%m-%d %H:%M:%S"
 	    try {
 		std::regex regex("([^\\s]+)\\s([^\\s]+)");
@@ -189,8 +184,8 @@ struct intern_date
 		    std::smatch match = *next;
 
 		    if (match.size() == 3) {
-			fromString(match[1].str(), ymd);
-			fromString(match[2].str(), hms);
+            fromString(match[1].str(), DATE_FORMAT_YMD);
+            fromString(match[2].str(), DATE_FORMAT_HMS);
 		    } else {
 			error = true;
 		    }
@@ -212,19 +207,19 @@ struct intern_date
 		    std::smatch match = *next;
 		    nbmatches++;
 		    if (nbmatches == 1) {
-			if (toparse == ymd) {
+            if (toparse == DATE_FORMAT_YMD) {
 			    myear = std::stol(match.str());
 			} else {
 			    mhours = std::stol(match.str());
 			}
 		    } else if (nbmatches == 3) {
-			if (toparse == ymd) {
+            if (toparse == DATE_FORMAT_YMD) {
 			    mmonth = std::stol(match.str());
 			} else {
 			    mminutes = std::stol(match.str());
 			}
 		    } else if (nbmatches == 5) {
-			if (toparse == ymd) {
+            if (toparse == DATE_FORMAT_YMD) {
 			    mday = std::stol(match.str());
 			} else {
 			    mseconds = std::stol(match.str());
@@ -596,7 +591,7 @@ std::string DateTime::toJulianDayNumber(unsigned long date)
 {
     intern_date d;
     d.fromJulianDay(static_cast<double>(date));
-    return d.toString(intern_date::ymd);
+    return d.toString(DATE_FORMAT_YMD);
 }
 
 
@@ -604,7 +599,7 @@ std::string DateTime::toJulianDayNumber(unsigned long date)
 long DateTime::toJulianDayNumber(const std::string& date)
 {
     intern_date d;
-    d.fromString(date, intern_date::ymd);
+    d.fromString(date, DATE_FORMAT_YMD);
     return d.julianDayNumber();
 }
 
@@ -613,7 +608,13 @@ std::string DateTime::toJulianDay(double date)
 {
     intern_date d;
     d.fromJulianDay(date);
-    return d.toString(intern_date::extended);
+    return d.toString(DATE_FORMAT_EXTENDED);
+}
+
+std::string DateTime::toJulianDayFmt(double date, DateFormat format){
+    intern_date d;
+    d.fromJulianDay(date);
+    return d.toString(format);
 }
 
 
@@ -622,7 +623,7 @@ double DateTime::toJulianDay(const std::string& date)
 {
 
     intern_date d;
-    d.fromString(date, intern_date::extended);
+    d.fromString(date, DATE_FORMAT_EXTENDED);
     return d.julianDay();
 }
 

+ 18 - 0
src/artis/utils/DateTime.hpp

@@ -46,6 +46,13 @@ enum DateTimeUnitOptions
     DATE_TIME_UNIT_YEAR
 };
 
+enum DateFormat
+{
+    DATE_FORMAT_EXTENDED, //"%Y-%m-%d %H:%M:%S"
+    DATE_FORMAT_YMD,      //"%Y-%m-%d"
+    DATE_FORMAT_HMS       //"%H:%M:%S"
+};
+
 class DateTime
 {
 public:
@@ -263,6 +270,17 @@ public:
      */
     static double toJulianDay(const std::string& date);
 
+    /**
+     * @brief Convert a julian date into a string in a given format.
+     * @code
+     * artis::utils::DateTime::toJulianDay(2454115.05486, DATE_FORMAT_YMD)) = "2001-10-9";
+     * @endcode
+     * @param date The date to convert.
+     * @param format The string format from enum artis::utils::DateFormat.
+     * @return A string representation of the julian day.
+     */
+    static std::string toJulianDayFmt(double date, artis::utils::DateFormat format);
+
                                   /* * * * */
 
     /**

+ 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());
 

+ 2 - 2
src/test/test-context.cpp

@@ -58,7 +58,7 @@ int main()
                        modelParameters);
         simulator.run(context);
 
-        std::cout << ::Trace::trace().elements().to_string() << std::endl;
+        std::cout << ::Trace::trace().elements().to_string(artis::utils::DATE_FORMAT_YMD) << std::endl;
 
         simulator.save(context);
 
@@ -83,7 +83,7 @@ int main()
             artis::utils::DateTime::toJulianDayNumber("2016-1-10"));
         simulator.run(new_context);
 
-        std::cout << ::Trace::trace().elements().to_string() << std::endl;
+        std::cout << ::Trace::trace().elements().filter_type(artis::utils::COMPUTE).to_string() << std::endl;
     }
 
     std::cout << "==== PAUSE ====" << std::endl;