1d229c5f9a5a43ba0245737ce498de4e5bad2d8f
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / tracing / analysis / cpu_slice_view.js
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 base.require('base.utils');
8 base.require('tracing.analysis.slice_view');
9 base.require('tracing.analysis.util');
10 base.require('tracing.analysis.analysis_link');
11 base.requireTemplate('tracing.analysis.cpu_slice_view');
12
13 base.exportTo('tracing.analysis', function() {
14   var tsRound = tracing.analysis.tsRound;
15
16   /**
17    * @constructor
18    */
19   var CpuSliceView = ui.define('cpu-slice-view', tracing.analysis.SliceView);
20
21   CpuSliceView.prototype = {
22     __proto__: tracing.analysis.SliceView.prototype,
23
24     decorate: function() {
25       tracing.analysis.SliceView.prototype.decorate.call(this);
26       this.classList.add('cpu-slice-view');
27     },
28
29     updateContents: function() {
30       this.textContent = '';
31       this.appendChild(base.instantiateTemplate('#cpu-slice-view-template'));
32
33       var cpuSlice = this.slice;
34       var thread = cpuSlice.threadThatWasRunning;
35
36       if (thread) {
37         this.querySelector('#process-name').textContent =
38             thread.parent.userFriendlyName;
39         this.querySelector('#thread-name').textContent =
40             thread.userFriendlyName;
41       } else {
42         this.querySelector('#process-name').parentElement.style.display =
43             'none';
44         this.querySelector('#thread-name').textContent = cpuSlice.title;
45       }
46       this.querySelector('#start').textContent = tsRound(cpuSlice.start) + 'ms';
47       this.querySelector('#duration').textContent =
48           tsRound(cpuSlice.duration) + 'ms';
49       var runningThreadEl = this.querySelector('#running-thread');
50       var timeSlice = cpuSlice.getAssociatedTimeslice();
51       if (!timeSlice) {
52         runningThreadEl.parentElement.style.display = 'none';
53       } else {
54         var threadLink = new tracing.analysis.AnalysisLink();
55         threadLink.textContent = 'Click to select';
56         threadLink.selectionGenerator = function() {
57           var selection = new tracing.Selection();
58           selection.push(timeSlice);
59           return selection;
60         }.bind(this);
61         runningThreadEl.appendChild(threadLink);
62       }
63     }
64   };
65
66   tracing.analysis.SliceView.register(
67       'tracing.analysis.CpuSlice', CpuSliceView);
68
69   return {
70     CpuSliceView: CpuSliceView
71   };
72 });