Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / side_panel / sampling_summary_test.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/side_panel/sampling_summary.html">
9 <link rel="import" href="/tracing/test_utils.html">
10 <link rel="import" href="/tracing/trace_model.html">
11
12 <script>
13 'use strict';
14
15 tvcm.unittest.testSuite(function() {
16   var StackFrame = tracing.trace_model.StackFrame;
17   var Sample = tracing.trace_model.Sample;
18
19   var newSliceNamed = tracing.test_utils.newSliceNamed;
20
21   function createSelection() {
22     var selection = new tracing.Selection();
23     var model = new tracing.TraceModel();
24     var thread = model.getOrCreateProcess(1).getOrCreateThread(2);
25     thread.name = 'The Thread';
26
27     var fA = new StackFrame(undefined, 1, 'Chrome', 'a', 7);
28     var fAB = new StackFrame(fA, 2, 'Chrome', 'b', 7);
29     var fABC = new StackFrame(fAB, 3, 'Chrome', 'c', 7);
30     var fAD = new StackFrame(fA, 4, 'GPU Driver', 'd', 7);
31
32     selection.push(new Sample(undefined, thread, 'cycles',
33                               10, fABC, 10));
34     selection.push(new Sample(undefined, thread, 'cycles',
35                               20, fAB, 10));
36     selection.push(new Sample(undefined, thread, 'cycles',
37                               25, fAB, 10));
38     selection.push(new Sample(undefined, thread, 'cycles',
39                               30, fAB, 10));
40     selection.push(new Sample(undefined, thread, 'cycles',
41                               35, fAD, 10));
42     selection.push(new Sample(undefined, thread, 'cycles',
43                               35, fAD, 5));
44     selection.push(new Sample(undefined, thread, 'cycles',
45                               40, fAD, 5));
46     selection.push(new Sample(undefined, thread, 'page_misses',
47                               35, fAD, 7));
48     selection.push(new Sample(undefined, thread, 'page_misses',
49                               40, fAD, 9));
50     return selection;
51   }
52
53   test('createSunburstDataBasic', function() {
54     var s = createSelection();
55
56     var expect = {
57       name: '<All Threads>',
58       category: 'root',
59       children: [
60         {
61           name: 'Thread 2: The Thread',
62           category: 'Thread',
63           children: [
64             {
65               category: 'Chrome',
66               name: 'Chrome',
67               children: [
68                 {
69                   category: 'Chrome',
70                   name: 'a',
71                   children: [
72                     {
73                       category: 'Chrome',
74                       name: 'b',
75                       children: [
76                         {
77                           category: 'Chrome',
78                           name: 'c',
79                           leaf_node_id: 3,
80                           size: 10
81                         },
82                         {
83                           name: '<self>',
84                           category: 'Chrome',
85                           size: 30,
86                           leaf_node_id: 2
87                         }
88                       ]
89                     },
90                     {
91                       category: 'GPU Driver',
92                       name: 'd',
93                       leaf_node_id: 4,
94                       size: 20
95                     }
96                   ]
97                 }
98               ]
99             }
100           ]
101         }
102       ]
103     };
104
105     var sunburstData = tracing.createSunburstData(s, 'cycles');
106     assertEquals(JSON.stringify(expect), JSON.stringify(sunburstData));
107   });
108
109   test('processOnlySamples', function() {
110     var selection = new tracing.Selection();
111     var model = new tracing.TraceModel();
112     var thread = model.getOrCreateProcess(1).getOrCreateThread(2);
113     thread.name = 'The Thread';
114
115     var fA = new StackFrame(undefined, 1, 'Chrome', 'a', 7);
116     var fAB = new StackFrame(fA, 2, 'Chrome', 'b', 7);
117     var fABC = new StackFrame(fAB, 3, 'Chrome', 'c', 7);
118     var fAD = new StackFrame(fA, 4, 'GPU Driver', 'd', 7);
119
120     selection.push(new Sample(undefined, thread, 'cycles',
121                               10, fABC, 10));
122     selection.push(new Sample(undefined, thread, 'cycles',
123                               20, fAB, 10));
124     selection.push(new Sample(undefined, thread, 'page_misses',
125                               40, fAD, 9));
126     var expect = {
127       name: '<All Threads>',
128       category: 'root',
129       children: [
130         {
131           name: 'Thread 2: The Thread',
132           category: 'Thread',
133           children: [
134             {
135               category: 'Chrome',
136               name: 'Chrome',
137               children: [
138                 {
139                   category: 'Chrome',
140                   name: 'a',
141                   children: [
142                     {
143                       category: 'GPU Driver',
144                       name: 'd',
145                       leaf_node_id: 4,
146                       size: 9
147                     }
148                   ]
149                 }
150               ]
151             }
152           ]
153         }
154       ]
155     };
156
157     // Along with the samples, push some slices too.
158     // The panel should completely ignore these.
159     selection.push(newSliceNamed('a', 1, 2));
160     selection.push(newSliceNamed('f', 9, 7));
161
162     var sunburstData = tracing.createSunburstData(selection, 'page_misses');
163     assertEquals(JSON.stringify(expect), JSON.stringify(sunburstData));
164   });
165
166   test('createSunburstDataSampleType', function() {
167     var s = createSelection();
168
169     var expect = {
170       name: '<All Threads>',
171       category: 'root',
172       children: [
173         {
174           name: 'Thread 2: The Thread',
175           category: 'Thread',
176           children: [
177             {
178               category: 'Chrome',
179               name: 'Chrome',
180               children: [
181                 {
182                   category: 'Chrome',
183                   name: 'a',
184                   children: [
185                     {
186                       category: 'GPU Driver',
187                       name: 'd',
188                       leaf_node_id: 4,
189                       size: 16
190                     }
191                   ]
192                 }
193               ]
194             }
195           ]
196         }
197       ]
198     };
199
200     var sunburstData = tracing.createSunburstData(s, 'page_misses');
201     assertEquals(JSON.stringify(expect), JSON.stringify(sunburstData));
202   });
203
204   test('instantiate', function() {
205     var s = createSelection();
206
207     var panel = new tracing.SamplingSummaryPanel();
208     this.addHTMLOutput(panel);
209     panel.style.border = '1px solid black';
210     panel.selection = s;
211   });
212 });
213 </script>