OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/time/time.h" | 5 #include "base/time/time.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #include <time.h> | 9 #include <time.h> |
10 #if defined(OS_ANDROID) && !defined(__LP64__) | 10 #if defined(OS_ANDROID) && !defined(__LP64__) |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ | 314 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ |
315 defined(OS_ANDROID) | 315 defined(OS_ANDROID) |
316 return ClockNow(CLOCK_THREAD_CPUTIME_ID); | 316 return ClockNow(CLOCK_THREAD_CPUTIME_ID); |
317 #else | 317 #else |
318 NOTREACHED(); | 318 NOTREACHED(); |
319 return TimeTicks(); | 319 return TimeTicks(); |
320 #endif | 320 #endif |
321 } | 321 } |
322 | 322 |
323 #if defined(OS_CHROMEOS) | 323 #if defined(OS_CHROMEOS) |
324 // Force definition of the system trace clock; it is a chromeos-only api | |
325 // at the moment and surfacing it in the right place requires mucking | |
326 // with glibc et al. | |
327 #define CLOCK_SYSTEM_TRACE 11 | |
328 | |
329 // static | 324 // static |
330 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 325 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
331 uint64_t absolute_micro; | 326 uint64_t absolute_micro; |
332 | 327 |
333 struct timespec ts; | 328 struct timespec ts; |
334 if (clock_gettime(CLOCK_SYSTEM_TRACE, &ts) != 0) { | 329 if (clock_gettime(kClockSystemTrace, &ts) != 0) { |
335 // NB: fall-back for a chrome os build running on linux | 330 // NB: fall-back for a chrome os build running on linux |
336 return HighResNow(); | 331 return HighResNow(); |
337 } | 332 } |
338 | 333 |
339 absolute_micro = | 334 absolute_micro = |
340 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 335 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
341 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 336 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
342 | 337 |
343 return TimeTicks(absolute_micro); | 338 return TimeTicks(absolute_micro); |
344 } | 339 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 376 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
382 return result; | 377 return result; |
383 } | 378 } |
384 int64 us = us_ - kTimeTToMicrosecondsOffset; | 379 int64 us = us_ - kTimeTToMicrosecondsOffset; |
385 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 380 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
386 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 381 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
387 return result; | 382 return result; |
388 } | 383 } |
389 | 384 |
390 } // namespace base | 385 } // namespace base |
OLD | NEW |