| 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/common.gypi sets OS_CHROMEOS without any other OS_* |
| 325 // at the moment and surfacing it in the right place requires mucking | 325 // macros for untrusted NaCl build so we need to check |
| 326 // with glibc et al. | 326 // __native_client__ explicitly. |
| 327 #define CLOCK_SYSTEM_TRACE 11 | 327 // TODO(hamaji): Do not specify OS_CHROMEOS for untrusted NaCl build |
| 328 | 328 // and remove !defined(__native_client__). |
| 329 #if defined(OS_CHROMEOS) && !defined(__native_client__) |
| 329 // static | 330 // static |
| 330 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 331 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 331 uint64_t absolute_micro; | 332 uint64_t absolute_micro; |
| 332 | 333 |
| 333 struct timespec ts; | 334 struct timespec ts; |
| 334 if (clock_gettime(CLOCK_SYSTEM_TRACE, &ts) != 0) { | 335 if (clock_gettime(kClockSystemTrace, &ts) != 0) { |
| 335 // NB: fall-back for a chrome os build running on linux | 336 // NB: fall-back for a chrome os build running on linux |
| 336 return HighResNow(); | 337 return HighResNow(); |
| 337 } | 338 } |
| 338 | 339 |
| 339 absolute_micro = | 340 absolute_micro = |
| 340 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 341 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 341 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 342 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 342 | 343 |
| 343 return TimeTicks(absolute_micro); | 344 return TimeTicks(absolute_micro); |
| 344 } | 345 } |
| 345 | 346 |
| 346 #else // !defined(OS_CHROMEOS) | 347 #else // !(defined(OS_CHROMEOS) && !defined(__native_client__)) |
| 347 | 348 |
| 348 // static | 349 // static |
| 349 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 350 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 350 return HighResNow(); | 351 return HighResNow(); |
| 351 } | 352 } |
| 352 | 353 |
| 353 #endif // defined(OS_CHROMEOS) | 354 #endif // defined(OS_CHROMEOS) && !defined(__native_client__) |
| 354 | 355 |
| 355 #endif // !OS_MACOSX | 356 #endif // !OS_MACOSX |
| 356 | 357 |
| 357 // static | 358 // static |
| 358 Time Time::FromTimeVal(struct timeval t) { | 359 Time Time::FromTimeVal(struct timeval t) { |
| 359 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 360 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
| 360 DCHECK_GE(t.tv_usec, 0); | 361 DCHECK_GE(t.tv_usec, 0); |
| 361 if (t.tv_usec == 0 && t.tv_sec == 0) | 362 if (t.tv_usec == 0 && t.tv_sec == 0) |
| 362 return Time(); | 363 return Time(); |
| 363 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 364 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; | 382 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 382 return result; | 383 return result; |
| 383 } | 384 } |
| 384 int64 us = us_ - kTimeTToMicrosecondsOffset; | 385 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 385 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 386 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 386 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 387 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 387 return result; | 388 return result; |
| 388 } | 389 } |
| 389 | 390 |
| 390 } // namespace base | 391 } // namespace base |
| OLD | NEW |