| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 TimeTicks TimeTicks::ThreadNow() { | 313 TimeTicks TimeTicks::ThreadNow() { |
| 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 // NaCl IRT does not support the Chrome OS specific clock |
| 324 // Force definition of the system trace clock; it is a chromeos-only api | 324 // ID. build_nexe.py sets OS_CHROMEOS without any other OS_* macros so |
| 325 // at the moment and surfacing it in the right place requires mucking | 325 // we need to check __native_client__ explicitly. |
| 326 // with glibc et al. | 326 #if defined(OS_CHROMEOS) && !defined(__native_client__) |
| 327 #define CLOCK_SYSTEM_TRACE 11 | |
| 328 | |
| 329 // static | 327 // static |
| 330 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 328 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 331 uint64_t absolute_micro; | 329 uint64_t absolute_micro; |
| 332 | 330 |
| 333 struct timespec ts; | 331 struct timespec ts; |
| 334 if (clock_gettime(CLOCK_SYSTEM_TRACE, &ts) != 0) { | 332 if (clock_gettime(kClockSystemTrace, &ts) != 0) { |
| 335 // NB: fall-back for a chrome os build running on linux | 333 // NB: fall-back for a chrome os build running on linux |
| 336 return HighResNow(); | 334 return HighResNow(); |
| 337 } | 335 } |
| 338 | 336 |
| 339 absolute_micro = | 337 absolute_micro = |
| 340 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 338 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 341 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 339 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 342 | 340 |
| 343 return TimeTicks(absolute_micro); | 341 return TimeTicks(absolute_micro); |
| 344 } | 342 } |
| 345 | 343 |
| 346 #else // !defined(OS_CHROMEOS) | 344 #else // !(defined(OS_CHROMEOS) && !defined(__native_client__)) |
| 347 | 345 |
| 348 // static | 346 // static |
| 349 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 347 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 350 return HighResNow(); | 348 return HighResNow(); |
| 351 } | 349 } |
| 352 | 350 |
| 353 #endif // defined(OS_CHROMEOS) | 351 #endif // defined(OS_CHROMEOS) && !defined(__native_client__) |
| 354 | 352 |
| 355 #endif // !OS_MACOSX | 353 #endif // !OS_MACOSX |
| 356 | 354 |
| 357 // static | 355 // static |
| 358 Time Time::FromTimeVal(struct timeval t) { | 356 Time Time::FromTimeVal(struct timeval t) { |
| 359 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 357 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
| 360 DCHECK_GE(t.tv_usec, 0); | 358 DCHECK_GE(t.tv_usec, 0); |
| 361 if (t.tv_usec == 0 && t.tv_sec == 0) | 359 if (t.tv_usec == 0 && t.tv_sec == 0) |
| 362 return Time(); | 360 return Time(); |
| 363 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 361 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 381 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 379 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 382 return result; | 380 return result; |
| 383 } | 381 } |
| 384 int64 us = us_ - kTimeTToMicrosecondsOffset; | 382 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 385 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 383 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 386 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 384 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 387 return result; | 385 return result; |
| 388 } | 386 } |
| 389 | 387 |
| 390 } // namespace base | 388 } // namespace base |
| OLD | NEW |