| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 // Use the Chrome OS specific system-wide clock. | 332 // Use the Chrome OS specific system-wide clock. |
| 333 #if defined(OS_CHROMEOS) | 333 #if defined(OS_CHROMEOS) |
| 334 // static | 334 // static |
| 335 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 335 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 336 uint64_t absolute_micro; | 336 uint64_t absolute_micro; |
| 337 | 337 |
| 338 struct timespec ts; | 338 struct timespec ts; |
| 339 if (clock_gettime(kClockSystemTrace, &ts) != 0) { | 339 if (clock_gettime(kClockSystemTrace, &ts) != 0) { |
| 340 // NB: fall-back for a chrome os build running on linux | 340 // NB: fall-back for a chrome os build running on linux |
| 341 return HighResNow(); | 341 return Now(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 absolute_micro = | 344 absolute_micro = |
| 345 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 345 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 346 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 346 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 347 | 347 |
| 348 return TimeTicks(absolute_micro); | 348 return TimeTicks(absolute_micro); |
| 349 } | 349 } |
| 350 | 350 |
| 351 #else // !defined(OS_CHROMEOS) | 351 #else // !defined(OS_CHROMEOS) |
| 352 | 352 |
| 353 // static | 353 // static |
| 354 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 354 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 355 return HighResNow(); | 355 return Now(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 #endif // defined(OS_CHROMEOS) | 358 #endif // defined(OS_CHROMEOS) |
| 359 | 359 |
| 360 #endif // !OS_MACOSX | 360 #endif // !OS_MACOSX |
| 361 | 361 |
| 362 // static | 362 // static |
| 363 Time Time::FromTimeVal(struct timeval t) { | 363 Time Time::FromTimeVal(struct timeval t) { |
| 364 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 364 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
| 365 DCHECK_GE(t.tv_usec, 0); | 365 DCHECK_GE(t.tv_usec, 0); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 386 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 386 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 387 return result; | 387 return result; |
| 388 } | 388 } |
| 389 int64 us = us_ - kTimeTToMicrosecondsOffset; | 389 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 390 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 390 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 391 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 391 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 392 return result; | 392 return result; |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace base | 395 } // namespace base |
| OLD | NEW |