summaryrefslogtreecommitdiff
path: root/libartbase/base/time_utils.cc
diff options
context:
space:
mode:
author Elliott Hughes <enh@google.com> 2020-07-24 13:22:37 -0700
committer Elliott Hughes <enh@google.com> 2020-07-28 18:21:37 +0000
commit43d7c65d8ff3097122acf9fcb4c45ae6ccd71f3a (patch)
tree2d906752379b283cd691f7d1c5e5a569f1a6e852 /libartbase/base/time_utils.cc
parent2d4552035130474bdad7f7f30ffe50bc5f9d5d85 (diff)
Match debuggerd timestamps in SIGQUIT dumps.
An OEM asked for sub-second granularity for debuggerd and ART. While I'm here, add the UTC offset that's in the debuggerd timestamps but not in the ART ones. Bug: https://issuetracker.google.com/161860597 Test: kill -QUIT zygote Change-Id: I6b834689bd71bf7f4b2a74cc0045f60d1c6af020
Diffstat (limited to 'libartbase/base/time_utils.cc')
-rw-r--r--libartbase/base/time_utils.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/libartbase/base/time_utils.cc b/libartbase/base/time_utils.cc
index aa6c987669..d38d885f5d 100644
--- a/libartbase/base/time_utils.cc
+++ b/libartbase/base/time_utils.cc
@@ -131,17 +131,24 @@ std::string FormatDuration(uint64_t nano_duration, TimeUnit time_unit,
}
std::string GetIsoDate() {
- time_t now = time(nullptr);
tm tmbuf;
+ int ns;
#ifdef _WIN32
+ time_t now = time(nullptr);
localtime_s(&tmbuf, &now);
tm* ptm = &tmbuf;
+ ns = 0;
#else
- tm* ptm = localtime_r(&now, &tmbuf);
+ timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+ tm* ptm = localtime_r(&now.tv_sec, &tmbuf);
+ ns = now.tv_nsec;
#endif
- return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d",
+ char zone[16] = {};
+ strftime(zone, sizeof(zone), "%z", ptm);
+ return StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%09d%s",
ptm->tm_year + 1900, ptm->tm_mon+1, ptm->tm_mday,
- ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
+ ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ns, zone);
}
uint64_t MilliTime() {