diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2023-02-14 16:25:45 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2023-02-14 17:23:59 +0000 |
commit | e2d8474857e8b39efcdf21441c95ad51a8aef6e8 (patch) | |
tree | fff255ab158453b8e98079624335c651ac776525 /sal | |
parent | 0e6e0270d25c4181ed15bd04123e20672f1e3a0b (diff) |
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 <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/all/log.cxx | 37 |
1 files changed, 20 insertions, 17 deletions
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 |