Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: src/base/platform/time.cc

Issue 367033002: Reland "Linux perf tool support update + refactoring." (r22146, attempt #5) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: git cl format Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/base/platform/time.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/platform/time.cc
diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc
index f3442b51bdf79132bc37949efee573dadb7480b4..f8ff893288008a2d55cb60585803b6514fb5f2dc 100644
--- a/src/base/platform/time.cc
+++ b/src/base/platform/time.cc
@@ -5,6 +5,7 @@
#include "src/base/platform/time.h"
#if V8_OS_POSIX
+#include <fcntl.h> // for O_RDONLY
#include <sys/time.h>
#endif
#if V8_OS_MACOSX
@@ -516,6 +517,14 @@ bool TimeTicks::IsHighResolutionClockWorking() {
return high_res_tick_clock.Pointer()->IsHighResolution();
}
+
+// static
+TimeTicks TimeTicks::KernelTimestampNow() { return TimeTicks(0); }
+
+
+// static
+bool TimeTicks::KernelTimestampAvailable() { return false; }
+
#else // V8_OS_WIN
TimeTicks TimeTicks::Now() {
@@ -563,6 +572,82 @@ bool TimeTicks::IsHighResolutionClockWorking() {
return true;
}
+
+#if V8_OS_LINUX && !V8_LIBRT_NOT_AVAILABLE
+
+class KernelTimestampClock {
+ public:
+ KernelTimestampClock() : clock_fd_(-1), clock_id_(kClockInvalid) {
+ clock_fd_ = open(kTraceClockDevice, O_RDONLY);
+ if (clock_fd_ == -1) {
+ return;
+ }
+ clock_id_ = get_clockid(clock_fd_);
+ }
+
+ virtual ~KernelTimestampClock() {
+ if (clock_fd_ != -1) {
+ close(clock_fd_);
+ }
+ }
+
+ int64_t Now() {
+ if (clock_id_ == kClockInvalid) {
+ return 0;
+ }
+
+ struct timespec ts;
+
+ clock_gettime(clock_id_, &ts);
+ return ((int64_t)ts.tv_sec * kNsecPerSec) + ts.tv_nsec;
+ }
+
+ bool Available() { return clock_id_ != kClockInvalid; }
+
+ private:
+ static const clockid_t kClockInvalid = -1;
+ static const char kTraceClockDevice[];
+ static const uint64_t kNsecPerSec = 1000000000;
+
+ int clock_fd_;
+ clockid_t clock_id_;
+
+ static int get_clockid(int fd) { return ((~(clockid_t)(fd) << 3) | 3); }
+};
+
+
+// Timestamp module name
+const char KernelTimestampClock::kTraceClockDevice[] = "/dev/trace_clock";
+
+#else
+
+class KernelTimestampClock {
+ public:
+ KernelTimestampClock() {}
+
+ int64_t Now() { return 0; }
+ bool Available() { return false; }
+};
+
+#endif // V8_OS_LINUX && !V8_LIBRT_NOT_AVAILABLE
+
+static LazyStaticInstance<KernelTimestampClock,
+ DefaultConstructTrait<KernelTimestampClock>,
+ ThreadSafeInitOnceTrait>::type kernel_tick_clock =
+ LAZY_STATIC_INSTANCE_INITIALIZER;
+
+
+// static
+TimeTicks TimeTicks::KernelTimestampNow() {
+ return TimeTicks(kernel_tick_clock.Pointer()->Now());
+}
+
+
+// static
+bool TimeTicks::KernelTimestampAvailable() {
+ return kernel_tick_clock.Pointer()->Available();
+}
+
#endif // V8_OS_WIN
} } // namespace v8::base
« no previous file with comments | « src/base/platform/time.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698