| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 ThreadTicks ThreadTicks::Now() { | 322 ThreadTicks ThreadTicks::Now() { |
| 323 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ | 323 #if (defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ |
| 324 defined(OS_ANDROID) | 324 defined(OS_ANDROID) |
| 325 return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); | 325 return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); |
| 326 #else | 326 #else |
| 327 NOTREACHED(); | 327 NOTREACHED(); |
| 328 return ThreadTicks(); | 328 return ThreadTicks(); |
| 329 #endif | 329 #endif |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Use the Chrome OS specific system-wide clock. | |
| 333 #if defined(OS_CHROMEOS) | |
| 334 // static | |
| 335 TraceTicks TraceTicks::Now() { | |
| 336 struct timespec ts; | |
| 337 if (clock_gettime(kClockSystemTrace, &ts) != 0) { | |
| 338 // NB: fall-back for a chrome os build running on linux | |
| 339 return TraceTicks(ClockNow(CLOCK_MONOTONIC)); | |
| 340 } | |
| 341 return TraceTicks(ConvertTimespecToMicros(ts)); | |
| 342 } | |
| 343 | |
| 344 #else // !defined(OS_CHROMEOS) | |
| 345 | |
| 346 // static | 332 // static |
| 347 TraceTicks TraceTicks::Now() { | 333 TraceTicks TraceTicks::Now() { |
| 348 return TraceTicks(ClockNow(CLOCK_MONOTONIC)); | 334 return TraceTicks(ClockNow(CLOCK_MONOTONIC)); |
| 349 } | 335 } |
| 350 | 336 |
| 351 #endif // defined(OS_CHROMEOS) | |
| 352 | |
| 353 #endif // !OS_MACOSX | 337 #endif // !OS_MACOSX |
| 354 | 338 |
| 355 // static | 339 // static |
| 356 Time Time::FromTimeVal(struct timeval t) { | 340 Time Time::FromTimeVal(struct timeval t) { |
| 357 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 341 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
| 358 DCHECK_GE(t.tv_usec, 0); | 342 DCHECK_GE(t.tv_usec, 0); |
| 359 if (t.tv_usec == 0 && t.tv_sec == 0) | 343 if (t.tv_usec == 0 && t.tv_sec == 0) |
| 360 return Time(); | 344 return Time(); |
| 361 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 345 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && |
| 362 t.tv_sec == std::numeric_limits<time_t>::max()) | 346 t.tv_sec == std::numeric_limits<time_t>::max()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 379 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 363 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 380 return result; | 364 return result; |
| 381 } | 365 } |
| 382 int64 us = us_ - kTimeTToMicrosecondsOffset; | 366 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 383 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 367 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 384 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 368 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 385 return result; | 369 return result; |
| 386 } | 370 } |
| 387 | 371 |
| 388 } // namespace base | 372 } // namespace base |
| OLD | NEW |