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 // static | |
333 TraceTicks TraceTicks::Now() { | |
334 return TraceTicks(ClockNow(CLOCK_MONOTONIC)); | |
335 } | |
336 | |
337 #endif // !OS_MACOSX | 332 #endif // !OS_MACOSX |
338 | 333 |
339 // static | 334 // static |
340 Time Time::FromTimeVal(struct timeval t) { | 335 Time Time::FromTimeVal(struct timeval t) { |
341 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); | 336 DCHECK_LT(t.tv_usec, static_cast<int>(Time::kMicrosecondsPerSecond)); |
342 DCHECK_GE(t.tv_usec, 0); | 337 DCHECK_GE(t.tv_usec, 0); |
343 if (t.tv_usec == 0 && t.tv_sec == 0) | 338 if (t.tv_usec == 0 && t.tv_sec == 0) |
344 return Time(); | 339 return Time(); |
345 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && | 340 if (t.tv_usec == static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1 && |
346 t.tv_sec == std::numeric_limits<time_t>::max()) | 341 t.tv_sec == std::numeric_limits<time_t>::max()) |
(...skipping 16 matching lines...) Expand all Loading... |
363 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 358 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
364 return result; | 359 return result; |
365 } | 360 } |
366 int64 us = us_ - kTimeTToMicrosecondsOffset; | 361 int64 us = us_ - kTimeTToMicrosecondsOffset; |
367 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 362 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
368 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 363 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
369 return result; | 364 return result; |
370 } | 365 } |
371 | 366 |
372 } // namespace base | 367 } // namespace base |
OLD | NEW |