Upstream version 5.34.104.0
[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 tvcm.require('tvcm.utils');
8 tvcm.require('tracing.analysis.slice_view');
9 tvcm.require('tracing.analysis.util');
10 tvcm.require('tracing.analysis.analysis_link');
11 tvcm.requireTemplate('tracing.analysis.cpu_slice_view');
12
13 tvcm.exportTo('tracing.analysis', function() {
14   var tsRound = tracing.analysis.tsRound;
15
16   /**
17    * @constructor
18    */
19   var CpuSliceView = tvcm.ui.define('cpu-slice-view',
20                                     tracing.analysis.SliceView);
21
22   CpuSliceView.prototype = {
23     __proto__: tracing.analysis.SliceView.prototype,
24
25     decorate: function() {
26       tracing.analysis.SliceView.prototype.decorate.call(this);
27       this.classList.add('cpu-slice-view');
28     },
29
30     updateContents: function() {
31       this.textContent = '';
32       this.appendChild(tvcm.instantiateTemplate('#cpu-slice-view-template'));
33
34       var cpuSlice = this.slice;
35       var thread = cpuSlice.threadThatWasRunning;
36
37       if (thread) {
38         this.querySelector('#process-name').textContent =
39             thread.parent.userFriendlyName;
40         this.querySelector('#thread-name').textContent =
41             thread.userFriendlyName;
42       } else {
43         this.querySelector('#process-name').parentElement.style.display =
44             'none';
45         this.querySelector('#thread-name').textContent = cpuSlice.title;
46       }
47       this.querySelector('#start').textContent = tsRound(cpuSlice.start) + 'ms';
48       this.querySelector('#duration').textContent =
49           tsRound(cpuSlice.duration) + 'ms';
50       var runningThreadEl = this.querySelector('#running-thread');
51       var timeSlice = cpuSlice.getAssociatedTimeslice();
52       if (!timeSlice) {
53         runningThreadEl.parentElement.style.display = 'none';
54       } else {
55         var threadLink = new tracing.analysis.AnalysisLink();
56         threadLink.textContent = 'Click to select';
57         threadLink.selectionGenerator = function() {
58           var selection = new tracing.Selection();
59           selection.push(timeSlice);
60           return selection;
61         }.bind(this);
62         runningThreadEl.appendChild(threadLink);
63       }
64     }
65   };
66
67   tracing.analysis.SliceView.register(
68       'tracing.analysis.CpuSlice', CpuSliceView);
69
70   return {
71     CpuSliceView: CpuSliceView
72   };
73 });