Index: tracing/tracing/extras/chrome/cpu_time_test.html |
diff --git a/tracing/tracing/extras/chrome/cpu_time_test.html b/tracing/tracing/extras/chrome/cpu_time_test.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73220e63b8352c7de2de4566ffa44d56cf1542c7 |
--- /dev/null |
+++ b/tracing/tracing/extras/chrome/cpu_time_test.html |
@@ -0,0 +1,45 @@ |
+<!DOCTYPE html> |
+<!-- |
+Copyright 2017 The Chromium Authors. All rights reserved. |
+Use of this source code is governed by a BSD-style license that can be |
+found in the LICENSE file. |
+--> |
+ |
+<link rel="import" href="/tracing/core/test_utils.html"> |
+<link rel="import" href="/tracing/extras/chrome/cpu_time.html"> |
+ |
+<script> |
+'use strict'; |
+ |
+tr.b.unittest.testSuite(function() { |
+ test('getCpuTimeForThread', () => { |
+ const model = tr.c.TestUtils.newModel(function(model) { |
+ const thread = model.getOrCreateProcess(1).getOrCreateThread(1); |
+ const sliceSpecs = [ |
+ {wallTimeBounds: [100, 200], cpuStart: 120, cpuDuration: 50}, |
+ {wallTimeBounds: [300, 600], cpuStart: 350, cpuDuration: 150} |
+ ]; |
+ for (const sliceSpec of sliceSpecs) { |
+ thread.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({ |
+ type: tr.model.ThreadSlice, |
+ isTopLevel: true, |
+ start: sliceSpec.wallTimeBounds[0], |
+ duration: sliceSpec.wallTimeBounds[1] - sliceSpec.wallTimeBounds[0], |
+ cpuStart: sliceSpec.cpuStart, |
+ cpuDuration: sliceSpec.cpuDuration, |
+ })); |
+ } |
+ }); |
+ |
+ const thread = model.getOrCreateProcess(1).getOrCreateThread(1); |
+ const bounds = new tr.b.math.Range.fromExplicitRange(150, 400); |
+ // 1/2 of first slice + 1/3 of second slice |
+ const expectedCpuTime = 25 + 50; |
+ |
+ // Should be essentially equal, but choosing a very small epsilon 1e-7 |
+ // to allow for floating point errors. |
+ assert.closeTo(tr.e.chrome.cpuTime.getCpuTimeForThread(thread, bounds), |
+ expectedCpuTime, 1e-7); |
+ }); |
+}); |
+</script> |