Add time zone information to tracelog
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Tue, 5 Jun 2018 20:40:09 +0000 (23:40 +0300)
committerPetr Bred/AI Ecosystem Lab /SRR/Staff Engineer/삼성전자 <p.bred@samsung.com>
Mon, 20 Aug 2018 15:53:35 +0000 (18:53 +0300)
doc/tracelog-format.md
src/CMakeLists.txt
src/misc/localtime.cpp
src/misc/localtime.h
src/profiler.cpp
src/tracelog/tracefmt.h
src/tracelog/tracelog.cpp
src/tracelog/tracelog.h

index 8e4a4225d033e3df5a6487d84d68bf9d1d228cf3..f152542fc91af07e68e81c8a2cff16c25d93dee6 100644 (file)
@@ -65,6 +65,7 @@ click) used in tables to avoid parser problems. -->
 | `<hex32>`      | `0x%08X`                                               | 32-bit hexadecimal number                                                         |
 | `<hex64>`      | `0x%016X`                                              | 64-bit hexadecimal number                                                         |
 | `<systime>`    | `%Y-%m-%d %H:%M:%S.%03f`                               | System time in format of year, month, day, hour, minute, seconds and milliseconds |
+| `<bias>`       | `+%H:%M` or `-%H:%M`                                   | Signed tize zone offset as hour and minute                                        |
 | `<ms>`         | `<num>`                                                | Time (in milliseconds)                                                            |
 | `<us>`         | `<num>`                                                | Time (in microseconds)                                                            |
 | `<ptr>`        | `<hex64>`                                              | Memory pointer                                                                    |
@@ -92,10 +93,11 @@ after end of object lifetime, and, in fact, represented by memory pointers.
 ### Profiler Start Time: `prf stm`
 
 ```
-prf stm <systime>
+prf stm <systime> <bias>
 ```
 
-Local time of the profiling session start-up.
+Time of the profiling session start-up. Present as local time value and time
+offset relative to UTC: `UTC = local time + bias`.
 
 ### Profiler Configuration: `prf cfg`
 
index d36b09ebe1ad448515c1f5829fa4543c6b74d88d..8d7e65ea0f1f76ef6df25a634808e9bed7c56014 100644 (file)
@@ -42,6 +42,12 @@ add_library(coreprof
   arch/${ARCH_SOURCES_DIR}/archhelpers.cpp
 )
 
+set_property(
+  SOURCE misc/localtime.cpp
+  PROPERTY COMPILE_DEFINITIONS
+  _GNU_SOURCE
+)
+
 target_link_libraries(coreprof
   libcorguids
   # utilcodestaticnohost
index e74264ab0c12fbd22d5739e2259368891374f20c..2500735dff1a4250689bd2ec9efe87f54f67702d 100644 (file)
 
 #include "localtime.h"
 
-VOID
-PALAPI
-GetLocalTime(OUT LPSYSTEMTIME lpLocalTime)
+void GetLocalTimeAndBias(SYSTEMTIME *localTime, LONG *bias)
 {
-    time_t tt;
-    struct tm ut;
-    struct tm *utPtr;
+    int errc = 0;
     struct timeval timeval;
-    int timeofday_retval;
-
-    tt = time(NULL);
+    struct tm ut;
+    struct tm *utPtr = NULL;
 
     /* We can't get millisecond resolution from time(), so we get it from
        gettimeofday() */
-    timeofday_retval = gettimeofday(&timeval, NULL);
-
-    utPtr = &ut;
-    if (localtime_r(&tt, utPtr) == NULL)
+    errc = gettimeofday(&timeval, NULL);
+    if(errc == -1)
     {
         throw std::system_error(errno, std::system_category(),
-            "localtime_r() failed");
+            "gettimeofday() failed");
     }
 
-    lpLocalTime->wYear = 1900 + utPtr->tm_year;
-    lpLocalTime->wMonth = utPtr->tm_mon + 1;
-    lpLocalTime->wDayOfWeek = utPtr->tm_wday;
-    lpLocalTime->wDay = utPtr->tm_mday;
-    lpLocalTime->wHour = utPtr->tm_hour;
-    lpLocalTime->wMinute = utPtr->tm_min;
-    lpLocalTime->wSecond = utPtr->tm_sec;
-
-    if(-1 == timeofday_retval)
+    utPtr = localtime_r(&timeval.tv_sec, &ut);
+    if (utPtr == NULL)
     {
-        lpLocalTime->wMilliseconds = 0;
         throw std::system_error(errno, std::system_category(),
-            "gettimeofday() failed");
+            "localtime_r() failed");
     }
-    else
-    {
-        int old_seconds;
-        int new_seconds;
-
-        lpLocalTime->wMilliseconds = timeval.tv_usec / 1000;
 
-        old_seconds = utPtr->tm_sec;
-        new_seconds = timeval.tv_sec%60;
+    localTime->wYear = 1900 + ut.tm_year;
+    localTime->wMonth = ut.tm_mon + 1;
+    localTime->wDayOfWeek = ut.tm_wday;
+    localTime->wDay = ut.tm_mday;
+    localTime->wHour = ut.tm_hour;
+    localTime->wMinute = ut.tm_min;
+    localTime->wSecond = ut.tm_sec;
+    localTime->wMilliseconds = timeval.tv_usec / 1000;
 
-        /* just in case we reached the next second in the interval between
-           time() and gettimeofday() */
-        if(old_seconds != new_seconds)
-        {
-            lpLocalTime->wMilliseconds = 999;
-        }
-    }
+    *bias = ut.tm_gmtoff / 60;
 }
index 647c36f8462bd4cfb335cd562ff299235787615e..d240855942872b2aff0981d7899a4372b11264fa 100644 (file)
@@ -16,7 +16,5 @@
 
 #include <pal.h>
 
-PALIMPORT
-VOID
-PALAPI
-GetLocalTime(OUT LPSYSTEMTIME lpLocalTime);
+// Returns local time structure and bias in minutes: local time = UTC + bias.
+void GetLocalTimeAndBias(SYSTEMTIME *localTime, LONG *bias);
index a259cf112a18092c1a4c9caafd607631ecc9ff29..90654a135575e3eae877ca3367ae93a2da73e5d6 100644 (file)
@@ -365,7 +365,8 @@ HRESULT STDMETHODCALLTYPE Profiler::Initialize(
     _ASSERTE(m_initialized == false);
 
     SYSTEMTIME systime;
-    GetLocalTime(&systime);
+    LONG bias;
+    GetLocalTimeAndBias(&systime, &bias);
     m_firstTickCount = GetTickCount();
 
     HRESULT hr = S_OK;
@@ -397,7 +398,7 @@ HRESULT STDMETHODCALLTYPE Profiler::Initialize(
         // Announce start time.
         //
 
-        TRACE().DumpStartTime(systime);
+        TRACE().DumpStartTime(systime, bias);
 
         //
         // Initializing the Profiler Info.
index f8f8fcbdf45537a8e82da88a4ee709be91567ef7..8df70f5bc0a4cf0a30725fa9c1f55cb34bf87bc6 100644 (file)
@@ -25,6 +25,8 @@
 #include <memory>
 #include <mutex>
 
+#include <stdlib.h>
+
 #include <windows.h>
 
 #include <cor.h>
@@ -192,16 +194,39 @@ private:
             sep();
             *m_stream
                 << std::setw(4) << systime.wYear
-                << '-'   << std::setw(2) << systime.wMonth
-                << '-'   << std::setw(2) << systime.wDay
-                << ' '   << std::setw(2) << systime.wHour
-                << ':'   << std::setw(2) << systime.wMinute
-                << ':'   << std::setw(2) << systime.wSecond
-                << '.'   << std::setw(3) << systime.wMilliseconds;
+                << '-' << std::setw(2) << systime.wMonth
+                << '-' << std::setw(2) << systime.wDay
+                << ' ' << std::setw(2) << systime.wHour
+                << ':' << std::setw(2) << systime.wMinute
+                << ':' << std::setw(2) << systime.wSecond
+                << '.' << std::setw(3) << systime.wMilliseconds;
             m_stream->fill(fill);
             return *this;
         }
 
+        record& bias(LONG bias)
+        {
+            char fill = m_stream->fill('0');
+            char sign = '+';
+
+            if (bias < 0)
+            {
+                sign = '-';
+                bias = -bias;
+            }
+
+            ldiv_t hour_minute = ldiv(bias, 60);
+
+            sep();
+            *m_stream
+                << sign
+                << std::setw(2) << hour_minute.quot
+                << ':' << std::setw(2) << hour_minute.rem;
+            m_stream->fill(fill);
+
+            return *this;
+        }
+
         template<typename T>
         record& config(T&& value)
         {
index f7373f9c04b4d60018c5bc8b0942a5ee96aef35a..67734610b09d59605d205571c5a0782072f82ea0 100644 (file)
@@ -77,9 +77,10 @@ public:
     //
 
     virtual void DumpStartTime(
-        const SYSTEMTIME &systime) override
+        const SYSTEMTIME &systime,
+        LONG        bias) override
     {
-        m_tracefmt.log("prf stm").systime(systime);
+        m_tracefmt.log("prf stm").systime(systime).bias(bias);
     }
 
     virtual void DumpProfilerConfig(
index 517390e9b1048a45b51bbeeaa36fbdd6a49785f9..cc8ab26612d11aaa3a139357e3933d66af9e69d7 100644 (file)
@@ -64,7 +64,8 @@ public:
     //
 
     virtual void DumpStartTime(
-        const SYSTEMTIME &systime) = 0;
+        const SYSTEMTIME &systime,
+        LONG        bias) = 0;
 
     virtual void DumpProfilerConfig(
         const ProfilerConfig &config) = 0;