| 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 // NaCl IRT does not support the Chrome OS specific clock | 323 // Use the Chrome OS specific system-wide clock. |
| 324 // ID. build/common.gypi sets OS_CHROMEOS without any other OS_* | 324 #if defined(OS_CHROMEOS) |
| 325 // macros for untrusted NaCl build so we need to check | |
| 326 // __native_client__ explicitly. | |
| 327 // TODO(hamaji): Do not specify OS_CHROMEOS for untrusted NaCl build | |
| 328 // and remove !defined(__native_client__). | |
| 329 #if defined(OS_CHROMEOS) && !defined(__native_client__) | |
| 330 // static | 325 // static |
| 331 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 326 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 332 uint64_t absolute_micro; | 327 uint64_t absolute_micro; |
| 333 | 328 |
| 334 struct timespec ts; | 329 struct timespec ts; |
| 335 if (clock_gettime(kClockSystemTrace, &ts) != 0) { | 330 if (clock_gettime(kClockSystemTrace, &ts) != 0) { |
| 336 // NB: fall-back for a chrome os build running on linux | 331 // NB: fall-back for a chrome os build running on linux |
| 337 return HighResNow(); | 332 return HighResNow(); |
| 338 } | 333 } |
| 339 | 334 |
| 340 absolute_micro = | 335 absolute_micro = |
| 341 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 336 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
| 342 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 337 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
| 343 | 338 |
| 344 return TimeTicks(absolute_micro); | 339 return TimeTicks(absolute_micro); |
| 345 } | 340 } |
| 346 | 341 |
| 347 #else // !(defined(OS_CHROMEOS) && !defined(__native_client__)) | 342 #else // !defined(OS_CHROMEOS) |
| 348 | 343 |
| 349 // static | 344 // static |
| 350 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 345 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 351 return HighResNow(); | 346 return HighResNow(); |
| 352 } | 347 } |
| 353 | 348 |
| 354 #endif // defined(OS_CHROMEOS) && !defined(__native_client__) | 349 #endif // defined(OS_CHROMEOS) |
| 355 | 350 |
| 356 #endif // !OS_MACOSX | 351 #endif // !OS_MACOSX |
| 357 | 352 |
| 358 // static | 353 // static |
| 359 Time Time::FromTimeVal(struct timeval t) { | 354 Time Time::FromTimeVal(struct timeval t) { |
| 360 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 355 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
| 361 DCHECK_GE(t.tv_usec, 0); | 356 DCHECK_GE(t.tv_usec, 0); |
| 362 if (t.tv_usec == 0 && t.tv_sec == 0) | 357 if (t.tv_usec == 0 && t.tv_sec == 0) |
| 363 return Time(); | 358 return Time(); |
| 364 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 359 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 382 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 377 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 383 return result; | 378 return result; |
| 384 } | 379 } |
| 385 int64 us = us_ - kTimeTToMicrosecondsOffset; | 380 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 386 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 381 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 387 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 382 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 388 return result; | 383 return result; |
| 389 } | 384 } |
| 390 | 385 |
| 391 } // namespace base | 386 } // namespace base |
| OLD | NEW |