sal/osl/all/log.cxx |   37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

New commits:
commit e2d8474857e8b39efcdf21441c95ad51a8aef6e8
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Tue Feb 14 16:25:45 2023 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Tue Feb 14 17:23:59 2023 +0000

    Let +TIMESTAMP and +RELATIVETIMER use the same osl_getSystemTime
    
    ...so that the reported numbers add up if you specify both in SAL_LOG.  Also
    make the code look more symmetric.
    
    Change-Id: I8b24dbe7cfa4d7aaebd2069db87a4e9d5fe6e3f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147017
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 235c7267d22e..e9895e14cb7b 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -207,13 +207,17 @@ void maybeOutputTimestamp(std::ostringstream &s) {
     static const std::pair<bool, bool> aEnvFlags = 
getTimestampFlags(getLogLevelEnvVar());
     const auto& [outputTimestamp, outputRelativeTimer] = (pLogSelector == 
nullptr ? aEnvFlags : getTimestampFlags(pLogSelector));
 
+    if (!(outputTimestamp || outputRelativeTimer)) {
+        return;
+    }
+    TimeValue now;
+    osl_getSystemTime(&now);
+
     if (outputTimestamp)
     {
         char ts[100];
-        TimeValue systemTime;
-        osl_getSystemTime(&systemTime);
         TimeValue localTime;
-        osl_getLocalTimeFromSystemTime(&systemTime, &localTime);
+        osl_getLocalTimeFromSystemTime(&now, &localTime);
         oslDateTime dateTime;
         osl_getDateTimeFromTimeValue(&localTime, &dateTime);
         struct tm tm;
@@ -231,23 +235,22 @@ void maybeOutputTimestamp(std::ostringstream &s) {
                  static_cast<unsigned>(dateTime.NanoSeconds / 1000000));
         s << ts << '.' << milliSecs << ':';
     }
-    if (!outputRelativeTimer)
-        return;
 
-    TimeValue now;
-    osl_getSystemTime(&now);
-    int seconds = now.Seconds - aStartTime.aTime.Seconds;
-    int milliSeconds;
-    if (now.Nanosec < aStartTime.aTime.Nanosec)
+    if (outputRelativeTimer)
     {
-        seconds--;
-        milliSeconds = 1000 - (aStartTime.aTime.Nanosec - now.Nanosec) / 
1000000;
+        int seconds = now.Seconds - aStartTime.aTime.Seconds;
+        int milliSeconds;
+        if (now.Nanosec < aStartTime.aTime.Nanosec)
+        {
+            seconds--;
+            milliSeconds = 1000 - (aStartTime.aTime.Nanosec - now.Nanosec) / 
1000000;
+        }
+        else
+            milliSeconds = (now.Nanosec - aStartTime.aTime.Nanosec) / 1000000;
+        char relativeTimestamp[100];
+        snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", 
seconds, milliSeconds);
+        s << relativeTimestamp << ':';
     }
-    else
-        milliSeconds = (now.Nanosec - aStartTime.aTime.Nanosec) / 1000000;
-    char relativeTimestamp[100];
-    snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", seconds, 
milliSeconds);
-    s << relativeTimestamp << ':';
 }
 
 #endif

Reply via email to