summaryrefslogtreecommitdiff
path: root/src/MiniTrace.cpp
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2022-09-20 19:01:38 +0200
committerJoel Rosdahl <joel@rosdahl.net>2022-09-21 17:06:32 +0200
commit653dde812ed117f3ff03bf05d97d086482aac0c9 (patch)
tree1ed0b5fa3a5f5fc330c8b59338986d5164f9dfeb /src/MiniTrace.cpp
parent4d560848f1c3bd95f8aa338f1b38cae2cdb6d44e (diff)
downloadccache-653dde812ed117f3ff03bf05d97d086482aac0c9.tar.gz
refactor: Use util::TimePoint for timestamps
Diffstat (limited to 'src/MiniTrace.cpp')
-rw-r--r--src/MiniTrace.cpp22
1 files changed, 4 insertions, 18 deletions
diff --git a/src/MiniTrace.cpp b/src/MiniTrace.cpp
index 07f495ad..90ffcc4b 100644
--- a/src/MiniTrace.cpp
+++ b/src/MiniTrace.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
@@ -24,10 +24,7 @@
#include "fmtmacros.hpp"
#include <core/wincompat.hpp>
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
+#include <util/TimePoint.hpp>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
@@ -53,18 +50,6 @@ get_system_tmp_dir()
return "/tmp";
}
-double
-time_seconds()
-{
-#ifdef HAVE_GETTIMEOFDAY
- struct timeval tv;
- gettimeofday(&tv, nullptr);
- return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
-#else
- return (double)time(nullptr);
-#endif
-}
-
} // namespace
MiniTrace::MiniTrace(const ArgsInfo& args_info)
@@ -75,7 +60,8 @@ MiniTrace::MiniTrace(const ArgsInfo& args_info)
m_tmp_trace_file = tmp_file.path;
mtr_init(m_tmp_trace_file.c_str());
- m_start_time = FMT("{:f}", time_seconds());
+ auto now = util::TimePoint::now();
+ m_start_time = FMT("{}.{:06}", now.sec(), now.nsec_decimal_part() / 1000);
MTR_INSTANT_C("", "", "time", m_start_time.c_str());
MTR_META_PROCESS_NAME("ccache");
MTR_START("program", "ccache", m_trace_id);