qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kp...@apache.org
Subject svn commit: r1098554 - in /qpid/trunk/qpid/cpp: include/qpid/log/Logger.h include/qpid/log/Options.h include/qpid/sys/Time.h src/qpid/log/Logger.cpp src/qpid/log/Options.cpp src/qpid/sys/posix/Time.cpp src/qpid/sys/windows/Time.cpp
Date Mon, 02 May 2011 13:20:36 GMT
Author: kpvdr
Date: Mon May  2 13:20:36 2011
New Revision: 1098554

URL: http://svn.apache.org/viewvc?rev=1098554&view=rev
Log:
QPID-3236 - Add high-resolution timestamps to log files for debug situations. Windows impl
has a stub only.

Modified:
    qpid/trunk/qpid/cpp/include/qpid/log/Logger.h
    qpid/trunk/qpid/cpp/include/qpid/log/Options.h
    qpid/trunk/qpid/cpp/include/qpid/sys/Time.h
    qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp
    qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp

Modified: qpid/trunk/qpid/cpp/include/qpid/log/Logger.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/log/Logger.h?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/log/Logger.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/log/Logger.h Mon May  2 13:20:36 2011
@@ -36,7 +36,7 @@ namespace log {
 class Logger : private boost::noncopyable {
   public:
     /** Flags indicating what to include in the log output */
-    enum FormatFlag { FILE=1, LINE=2, FUNCTION=4, LEVEL=8, TIME=16, THREAD=32};
+    enum FormatFlag { FILE=1, LINE=2, FUNCTION=4, LEVEL=8, TIME=16, THREAD=32, HIRES=64};
 
     /**
      * Logging output sink.

Modified: qpid/trunk/qpid/cpp/include/qpid/log/Options.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/log/Options.h?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/log/Options.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/log/Options.h Mon May  2 13:20:36 2011
@@ -39,7 +39,7 @@ struct Options : public qpid::Options {
     std::string argv0;
     std::string name;
     std::vector<std::string> selectors;
-    bool time, level, thread, source, function;
+    bool time, level, thread, source, function, hiresTs;
     bool trace;
     std::string prefix;
     std::auto_ptr<SinkOptions> sinkOptions;

Modified: qpid/trunk/qpid/cpp/include/qpid/sys/Time.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/sys/Time.h?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/sys/Time.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/sys/Time.h Mon May  2 13:20:36 2011
@@ -167,6 +167,9 @@ QPID_COMMON_EXTERN void usleep(uint64_t 
 /** Output formatted date/time for now*/
 void outputFormattedNow(std::ostream&);
 
+/** Output unformatted nanosecond-resolution time for now */
+void outputHiresNow(std::ostream&);
+
 }}
 
 #endif  /*!_sys_Time_h*/

Modified: qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp Mon May  2 13:20:36 2011
@@ -79,8 +79,12 @@ void Logger::log(const Statement& s, con
     std::ostringstream os;
     if (!prefix.empty())
         os << prefix << ": ";
-    if (flags&TIME)
-		qpid::sys::outputFormattedNow(os);
+    if (flags&TIME) {
+        if (flags&HIRES)
+            qpid::sys::outputHiresNow(os);
+        else
+		    qpid::sys::outputFormattedNow(os);
+    }
     if (flags&LEVEL)
         os << LevelTraits::name(s.level) << " ";
     if (flags&THREAD)
@@ -129,7 +133,8 @@ int Logger::format(const Options& opts) 
         bitIf(opts.time, TIME) |
         bitIf(opts.source, (FILE|LINE)) |
         bitIf(opts.function, FUNCTION) |
-        bitIf(opts.thread, THREAD);
+        bitIf(opts.thread, THREAD) |
+        bitIf(opts.hiresTs, HIRES);
     format(flags);
     return flags;
 }

Modified: qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp Mon May  2 13:20:36 2011
@@ -38,6 +38,7 @@ Options::Options(const std::string& argv
     thread(false),
     source(false),
     function(false),
+    hiresTs(false),
     trace(false),
     sinkOptions (SinkOptions::create(argv0_))
 {
@@ -65,6 +66,7 @@ Options::Options(const std::string& argv
         ("log-source", optValue(source,"yes|no"), "Include source file:line in log messages")
         ("log-thread", optValue(thread,"yes|no"), "Include thread ID in log messages")
         ("log-function", optValue(function,"yes|no"), "Include function signature in log
messages")
+        ("log-hires-timestamp", optValue(hiresTs,"yes|no"), "Use unformatted hi-res timestamp
in log messages")
         ("log-prefix", optValue(prefix,"STRING"), "Prefix to append to all log messages")
         ;
     add(*sinkOptions);
@@ -80,6 +82,7 @@ Options::Options(const Options &o) :
     thread(o.thread),
     source(o.source),
     function(o.function),
+    hiresTs(o.hiresTs),
     trace(o.trace),
     prefix(o.prefix),
     sinkOptions (SinkOptions::create(o.argv0))
@@ -97,6 +100,7 @@ Options& Options::operator=(const Option
         thread = x.thread;
         source = x.source;
         function = x.function;
+        hiresTs = x.hiresTs;
         trace = x.trace;
         prefix = x.prefix;
         *sinkOptions = *x.sinkOptions;

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp Mon May  2 13:20:36 2011
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <sys/time.h>
 #include <unistd.h>
+#include <iomanip>
 
 namespace {
 int64_t max_abstime() { return std::numeric_limits<int64_t>::max(); }
@@ -103,6 +104,12 @@ void outputFormattedNow(std::ostream& o)
     o << " ";
 }
 
+void outputHiresNow(std::ostream& o) {
+    ::timespec time;
+    ::clock_gettime(CLOCK_REALTIME, &time);
+    o << time.tv_sec << "." << std::setw(9) << std::setfill('0')
<< time.tv_nsec << "s ";
+}
+
 void sleep(int secs) {
     ::sleep(secs);
 }

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp?rev=1098554&r1=1098553&r2=1098554&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/Time.cpp Mon May  2 13:20:36 2011
@@ -97,4 +97,13 @@ void outputFormattedNow(std::ostream& o)
                &timeinfo);
     o << time_string << " ";
 }
+
+void outputHiresNow(std::ostream& o) {
+// TODO: This is a stub - replace with windows code that will do the equivalent
+// of the Linux code commented out below.  (kpvdr)
+//    ::timespec time;
+//    ::clock_gettime(CLOCK_REALTIME, &time);
+//    o << time.tv_sec << "." << std::setw(9) << std::setfill('0')
<< time.tv_nsec << "s ";
+    o << "XXXXXXXXX.XXXXXXXXXs ";
+}
 }}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message