| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 EXPECT_GE(counter1, 0); | 55 EXPECT_GE(counter1, 0); |
| 56 EXPECT_GE(counter2, 0); | 56 EXPECT_GE(counter2, 0); |
| 57 int64_t process_duration_nanos = | 57 int64_t process_duration_nanos = |
| 58 GetProcessCpuTimeNanos() - process_start_time_nanos; | 58 GetProcessCpuTimeNanos() - process_start_time_nanos; |
| 59 int64_t thread_duration_nanos = | 59 int64_t thread_duration_nanos = |
| 60 GetThreadCpuTimeNanos() - thread_start_time_nanos; | 60 GetThreadCpuTimeNanos() - thread_start_time_nanos; |
| 61 // This thread did almost nothing. | 61 // This thread did almost nothing. |
| 62 // Therefore GetThreadCpuTime is not a wall clock. | 62 // Therefore GetThreadCpuTime is not a wall clock. |
| 63 EXPECT_LE(thread_duration_nanos, | 63 EXPECT_LE(thread_duration_nanos, |
| 64 kAllowedErrorMillisecs * kNumNanosecsPerMillisec); | 64 kAllowedErrorMillisecs * kNumNanosecsPerMillisec); |
| 65 // Total process time is twice working threads' CPU time. | 65 // Total process time is at least twice working threads' CPU time. |
| 66 // Therefore process and thread times are correctly related. | 66 // Therefore process and thread times are correctly related. |
| 67 EXPECT_NEAR( | 67 EXPECT_GE( |
| 68 process_duration_nanos, | 68 process_duration_nanos, |
| 69 kWorkingThreads * kProcessingTimeMillisecs * kNumNanosecsPerMillisec, | 69 kWorkingThreads * (kProcessingTimeMillisecs - kAllowedErrorMillisecs) |
| 70 kWorkingThreads * kAllowedErrorMillisecs * kNumNanosecsPerMillisec); | 70 * kNumNanosecsPerMillisec); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(CpuTimeTest, Sleeping) { | 73 TEST(CpuTimeTest, Sleeping) { |
| 74 int64_t process_start_time_nanos = GetProcessCpuTimeNanos(); | 74 int64_t process_start_time_nanos = GetProcessCpuTimeNanos(); |
| 75 webrtc::SleepMs(kProcessingTimeMillisecs); | 75 webrtc::SleepMs(kProcessingTimeMillisecs); |
| 76 int64_t process_duration_nanos = | 76 int64_t process_duration_nanos = |
| 77 GetProcessCpuTimeNanos() - process_start_time_nanos; | 77 GetProcessCpuTimeNanos() - process_start_time_nanos; |
| 78 // Sleeping should not introduce any additional CPU time. | 78 // Sleeping should not introduce any additional CPU time. |
| 79 // Therefore GetProcessCpuTime is not a wall clock. | 79 // Therefore GetProcessCpuTime is not a wall clock. |
| 80 EXPECT_LE(process_duration_nanos, | 80 EXPECT_LE(process_duration_nanos, |
| 81 kWorkingThreads * kAllowedErrorMillisecs * kNumNanosecsPerMillisec); | 81 kWorkingThreads * kAllowedErrorMillisecs * kNumNanosecsPerMillisec); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace rtc | 84 } // namespace rtc |
| OLD | NEW |