In the trace record the time value is generated
after acquiring the mutex. The time accuracy is improved
when generated before seizing the mutext.
---
 src/base/logtrace.cc        |  2 +-
 src/base/logtrace_client.cc | 15 ++++++++-------
 src/base/logtrace_client.h  |  9 +++++----
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/base/logtrace.cc b/src/base/logtrace.cc
index 8908c1ff3..9822879ab 100644
--- a/src/base/logtrace.cc
+++ b/src/base/logtrace.cc
@@ -97,7 +97,7 @@ void trace_output(const char *file, unsigned line, unsigned 
priority,
     if (!entry) {
       entry = gl_local_thread_trace->CreateLogEntry(
           static_cast<base::LogMessage::Severity>(priority),
-          preamble, ap);
+          base::ReadRealtimeClock(), preamble, ap);
     }
     gl_thread_buffer.WriteToBuffer(entry);
   }
diff --git a/src/base/logtrace_client.cc b/src/base/logtrace_client.cc
index e22112a43..104e08ce1 100644
--- a/src/base/logtrace_client.cc
+++ b/src/base/logtrace_client.cc
@@ -96,32 +96,33 @@ const char* LogTraceClient::Log(LogTraceClient* tracelog,
 const char* LogTraceClient::Log(base::LogMessage::Severity severity,
     const char *fmt, va_list ap) {
   if (log_socket_ != nullptr && log_mutex_ != nullptr) {
-    return LogInternal(severity, fmt, ap);
+    return LogInternal(severity, base::ReadRealtimeClock(), fmt, ap);
   }
   return nullptr;
 }
 
 const char* LogTraceClient::LogInternal(base::LogMessage::Severity severity,
-    const char *fmt, va_list ap) {
+    timespec time_spec, const char *fmt, va_list ap) {
   base::Lock lock(*log_mutex_);
-  CreateLogEntryInternal(severity, fmt, ap);
+  CreateLogEntryInternal(severity, time_spec, fmt, ap);
   log_socket_->Send(buffer_.data(), buffer_.size());
   return buffer_.data();
 }
 
 const char* LogTraceClient::CreateLogEntry(base::LogMessage::Severity severity,
-    const char *fmt, va_list ap) {
+    timespec time_spec, const char *fmt, va_list ap) {
   base::Lock lock(*log_mutex_);
-  return CreateLogEntryInternal(severity, fmt, ap);
+  return CreateLogEntryInternal(severity, time_spec, fmt, ap);
 }
 
 const char* LogTraceClient::CreateLogEntryInternal(
-    base::LogMessage::Severity severity, const char *fmt, va_list ap) {
+    base::LogMessage::Severity severity, timespec time_spec,
+    const char *fmt, va_list ap) {
   uint32_t id = sequence_id_;
   sequence_id_ = id < kMaxSequenceId ? id + 1 : 1;
   buffer_.clear();
   base::LogMessage::Write(
-      base::LogMessage::Facility::kLocal1, severity, base::ReadRealtimeClock(),
+      base::LogMessage::Facility::kLocal1, severity, time_spec,
       fqdn_, app_name_, proc_id_, msg_id_,
       {{base::LogMessage::SdName{"meta"},
         {base::LogMessage::Parameter{base::LogMessage::SdName{"sequenceId"},
diff --git a/src/base/logtrace_client.h b/src/base/logtrace_client.h
index 5b165e528..1ccb44d06 100644
--- a/src/base/logtrace_client.h
+++ b/src/base/logtrace_client.h
@@ -44,7 +44,7 @@ class LogTraceClient {
   const char* Log(base::LogMessage::Severity severity, const char *fmt,
                   va_list ap);
   const char* CreateLogEntry(base::LogMessage::Severity severity,
-      const char *fmt, va_list ap);
+      timespec time_spec, const char *fmt, va_list ap);
   void AddExternalBuffer(int64_t tid, LogTraceBuffer* buffer);
   void RemoveExternalBuffer(int64_t tid);
   void RequestFlushExternalBuffer();
@@ -56,10 +56,11 @@ class LogTraceClient {
 
  private:
   bool Init(const char *msg_id, WriteMode mode);
-  const char* LogInternal(base::LogMessage::Severity severity, const char *fmt,
-      va_list ap);
+
+  const char* LogInternal(base::LogMessage::Severity severity,
+      timespec time_spec, const char *fmt, va_list ap);
   const char* CreateLogEntryInternal(base::LogMessage::Severity severity,
-      const char *fmt, va_list ap);
+      timespec time_spec, const char *fmt, va_list ap);
   static constexpr const uint32_t kMaxSequenceId = uint32_t{0x7fffffff};
   base::LogMessage::HostName fqdn_{""};
   base::LogMessage::AppName app_name_{""};
-- 
2.25.0



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to