* mln/trace/entering.hh,
* mln/trace/exiting.hh,
* mln/trace/quiet.hh:
Avoid useless ends of line and add a timer.
---
milena/ChangeLog | 9 +++++++++
milena/mln/trace/entering.hh | 10 ++++++++--
milena/mln/trace/exiting.hh | 25 +++++++++++++++++++++----
milena/mln/trace/quiet.hh | 5 +++++
4 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 8dfe0f2..151dd22 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2008-10-30 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve trace output.
+
+ * mln/trace/entering.hh,
+ * mln/trace/exiting.hh,
+ * mln/trace/quiet.hh:
+ Avoid useless ends of line and add a timer.
+
+2008-10-30 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add trace::stop and trace::resume.
* mln/trace/all.hh: add new includes.
diff --git a/milena/mln/trace/entering.hh b/milena/mln/trace/entering.hh
index 3737a1c..20fc58d 100644
--- a/milena/mln/trace/entering.hh
+++ b/milena/mln/trace/entering.hh
@@ -54,10 +54,16 @@ namespace mln
{
if (quiet)
return;
+
+ if ((tab != 0) && (internal::max_tab == tab))
+ std::cout << std::endl;
+
for (unsigned i = 0; i < tab; ++i)
std::cout << " ";
- std::cout << scope << " {" << std::endl;
- ++tab;
+ std::cout << scope << " {";
+
+ internal::max_tab = ++tab;
+ gettimeofday(&internal::start_time, 0);
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/trace/exiting.hh b/milena/mln/trace/exiting.hh
index 4ea9afb..9b7e9f5 100644
--- a/milena/mln/trace/exiting.hh
+++ b/milena/mln/trace/exiting.hh
@@ -50,14 +50,31 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
inline
- void exiting(const std::string& str)
+ void exiting(const std::string& scope)
{
if (quiet)
return;
+
+ timeval after_time;
+ gettimeofday(&after_time, 0);
+ bool has_inner_trace = (internal::max_tab == tab);
--tab;
- for (unsigned i = 0; i < tab; ++i)
- std::cout << " ";
- std::cout << "} " << str << std::endl;
+
+ if (!has_inner_trace)
+ for (unsigned i = 0; i < tab; ++i)
+ std::cout << " ";
+
+ std::cout << "} ";
+
+ if (!has_inner_trace)
+ std::cout << scope << " ";
+
+ std::cout << "- "
+ << (after_time.tv_usec - internal::start_time.tv_usec) / 1000.
+ << "ms ";
+
+ if (has_inner_trace || (internal::max_tab - tab > 1))
+ std::cout << std::endl;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/trace/quiet.hh b/milena/mln/trace/quiet.hh
index 0a98bd4..e7467f0 100644
--- a/milena/mln/trace/quiet.hh
+++ b/milena/mln/trace/quiet.hh
@@ -33,6 +33,8 @@
* \brief Definition of the trace quiet Boolean value.
*/
+# include <ctime>
+# include <sys/time.h>
namespace mln
{
@@ -44,9 +46,12 @@ namespace mln
static unsigned tab = 0;
static bool full_trace = false;
+
namespace internal
{
+ static unsigned max_tab = 0;
+ static timeval start_time;
static bool is_quiet = quiet;
} // end of namespace mln::trace::internal
--
1.5.6.5