Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Unified Diff: tracing/tracing/extras/chrome/cpu_time_test.html

Issue 2798213002: Add function to get total cpu time in thread (Closed)
Patch Set: Change bounds to range Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tracing/tracing/extras/chrome/cpu_time.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « tracing/tracing/extras/chrome/cpu_time.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698