| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
| 5 found in the LICENSE file. | 5 found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 | 7 |
| 8 <link rel="import" href="/tracing/base/range.html"> | 8 <link rel="import" href="/tracing/base/math/range.html"> |
| 9 <link rel="import" href="/tracing/model/counter.html"> | 9 <link rel="import" href="/tracing/model/counter.html"> |
| 10 <link rel="import" href="/tracing/model/cpu_slice.html"> | 10 <link rel="import" href="/tracing/model/cpu_slice.html"> |
| 11 <link rel="import" href="/tracing/model/process_base.html"> | 11 <link rel="import" href="/tracing/model/process_base.html"> |
| 12 <link rel="import" href="/tracing/model/thread_time_slice.html"> | 12 <link rel="import" href="/tracing/model/thread_time_slice.html"> |
| 13 | 13 |
| 14 <script> | 14 <script> |
| 15 'use strict'; | 15 'use strict'; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @fileoverview Provides the Cpu class. | 18 * @fileoverview Provides the Cpu class. |
| 19 */ | 19 */ |
| 20 tr.exportTo('tr.model', function() { | 20 tr.exportTo('tr.model', function() { |
| 21 var ColorScheme = tr.b.ColorScheme; | 21 var ColorScheme = tr.b.ColorScheme; |
| 22 var Counter = tr.model.Counter; | 22 var Counter = tr.model.Counter; |
| 23 var CpuSlice = tr.model.CpuSlice; | 23 var CpuSlice = tr.model.CpuSlice; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The Cpu represents a Cpu from the kernel's point of view. | 26 * The Cpu represents a Cpu from the kernel's point of view. |
| 27 * @constructor | 27 * @constructor |
| 28 */ | 28 */ |
| 29 function Cpu(kernel, number) { | 29 function Cpu(kernel, number) { |
| 30 if (kernel === undefined || number === undefined) | 30 if (kernel === undefined || number === undefined) |
| 31 throw new Error('Missing arguments'); | 31 throw new Error('Missing arguments'); |
| 32 this.kernel = kernel; | 32 this.kernel = kernel; |
| 33 this.cpuNumber = number; | 33 this.cpuNumber = number; |
| 34 this.slices = []; | 34 this.slices = []; |
| 35 this.counters = {}; | 35 this.counters = {}; |
| 36 this.bounds_ = new tr.b.Range(); | 36 this.bounds_ = new tr.b.math.Range(); |
| 37 this.samples_ = undefined; // Set during createSubSlices | 37 this.samples_ = undefined; // Set during createSubSlices |
| 38 | 38 |
| 39 // Start timestamp of the last active thread. | 39 // Start timestamp of the last active thread. |
| 40 this.lastActiveTimestamp_ = undefined; | 40 this.lastActiveTimestamp_ = undefined; |
| 41 | 41 |
| 42 // Identifier of the last active thread. On Linux, it's a pid while on | 42 // Identifier of the last active thread. On Linux, it's a pid while on |
| 43 // Windows it's a thread id. | 43 // Windows it's a thread id. |
| 44 this.lastActiveThread_ = undefined; | 44 this.lastActiveThread_ = undefined; |
| 45 | 45 |
| 46 // Name and arguments of the last active thread. | 46 // Name and arguments of the last active thread. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 for (var id in this.counters) | 143 for (var id in this.counters) |
| 144 categoriesDict[this.counters[id].category] = true; | 144 categoriesDict[this.counters[id].category] = true; |
| 145 for (var i = 0; i < this.samples_.length; i++) | 145 for (var i = 0; i < this.samples_.length; i++) |
| 146 categoriesDict[this.samples_[i].category] = true; | 146 categoriesDict[this.samples_[i].category] = true; |
| 147 }, | 147 }, |
| 148 | 148 |
| 149 /* | 149 /* |
| 150 * Returns the index of the slice in the CPU's slices, or undefined. | 150 * Returns the index of the slice in the CPU's slices, or undefined. |
| 151 */ | 151 */ |
| 152 indexOf: function(cpuSlice) { | 152 indexOf: function(cpuSlice) { |
| 153 var i = tr.b.findLowIndexInSortedArray( | 153 var i = tr.b.math.findLowIndexInSortedArray( |
| 154 this.slices, | 154 this.slices, |
| 155 function(slice) { return slice.start; }, | 155 function(slice) { return slice.start; }, |
| 156 cpuSlice.start); | 156 cpuSlice.start); |
| 157 if (this.slices[i] !== cpuSlice) | 157 if (this.slices[i] !== cpuSlice) |
| 158 return undefined; | 158 return undefined; |
| 159 return i; | 159 return i; |
| 160 }, | 160 }, |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * Closes the thread running on the CPU. |endTimestamp| is the timestamp | 163 * Closes the thread running on the CPU. |endTimestamp| is the timestamp |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 var stats = {}; | 219 var stats = {}; |
| 220 | 220 |
| 221 function addStatsForFreq(freqSample, index) { | 221 function addStatsForFreq(freqSample, index) { |
| 222 // Counters don't have an explicit end or duration; | 222 // Counters don't have an explicit end or duration; |
| 223 // calculate the end by looking at the starting point | 223 // calculate the end by looking at the starting point |
| 224 // of the next value in the series, or if that doesn't | 224 // of the next value in the series, or if that doesn't |
| 225 // exist, assume this frequency is held until the end. | 225 // exist, assume this frequency is held until the end. |
| 226 var freqEnd = (index < freqSample.series_.length - 1) ? | 226 var freqEnd = (index < freqSample.series_.length - 1) ? |
| 227 freqSample.series_.samples_[index + 1].timestamp : range.max; | 227 freqSample.series_.samples_[index + 1].timestamp : range.max; |
| 228 | 228 |
| 229 var freqRange = tr.b.Range.fromExplicitRange(freqSample.timestamp, | 229 var freqRange = tr.b.math.Range.fromExplicitRange(freqSample.timestamp, |
| 230 freqEnd); | 230 freqEnd); |
| 231 var intersection = freqRange.findIntersection(range); | 231 var intersection = freqRange.findIntersection(range); |
| 232 if (!(freqSample.value in stats)) | 232 if (!(freqSample.value in stats)) |
| 233 stats[freqSample.value] = 0; | 233 stats[freqSample.value] = 0; |
| 234 stats[freqSample.value] += intersection.duration; | 234 stats[freqSample.value] += intersection.duration; |
| 235 } | 235 } |
| 236 | 236 |
| 237 var freqCounter = this.getCounter('', 'Clock Frequency'); | 237 var freqCounter = this.getCounter('', 'Clock Frequency'); |
| 238 if (freqCounter !== undefined) { | 238 if (freqCounter !== undefined) { |
| 239 var freqSeries = freqCounter.getSeries(0); | 239 var freqSeries = freqCounter.getSeries(0); |
| 240 if (!freqSeries) | 240 if (!freqSeries) |
| 241 return; | 241 return; |
| 242 | 242 |
| 243 tr.b.iterateOverIntersectingIntervals(freqSeries.samples_, | 243 tr.b.math.iterateOverIntersectingIntervals(freqSeries.samples_, |
| 244 function(x) { return x.timestamp; }, | 244 function(x) { return x.timestamp; }, |
| 245 function(x, index) { | 245 function(x, index) { |
| 246 if (index < freqSeries.length - 1) { | 246 if (index < freqSeries.length - 1) { |
| 247 return freqSeries.samples_[index + 1].timestamp; | 247 return freqSeries.samples_[index + 1].timestamp; |
| 248 } | 248 } |
| 249 return range.max; | 249 return range.max; |
| 250 }, | 250 }, |
| 251 range.min, | 251 range.min, |
| 252 range.max, | 252 range.max, |
| 253 addStatsForFreq); | 253 addStatsForFreq); |
| 254 } | 254 } |
| 255 | 255 |
| 256 return stats; | 256 return stats; |
| 257 } | 257 } |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 /** | 260 /** |
| 261 * Comparison between processes that orders by cpuNumber. | 261 * Comparison between processes that orders by cpuNumber. |
| 262 */ | 262 */ |
| 263 Cpu.compare = function(x, y) { | 263 Cpu.compare = function(x, y) { |
| 264 return x.cpuNumber - y.cpuNumber; | 264 return x.cpuNumber - y.cpuNumber; |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 | 267 |
| 268 return { | 268 return { |
| 269 Cpu, | 269 Cpu, |
| 270 }; | 270 }; |
| 271 }); | 271 }); |
| 272 </script> | 272 </script> |
| OLD | NEW |