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/ui/extras/about_tracing/inspector_connection.h
tml"> | 8 <link rel="import" href="/tracing/ui/extras/about_tracing/inspector_connection.h
tml"> |
9 <link rel="import" | 9 <link rel="import" |
10 href="/tracing/ui/extras/about_tracing/tracing_controller_client.html"> | 10 href="/tracing/ui/extras/about_tracing/tracing_controller_client.html"> |
11 | 11 |
12 <script> | 12 <script> |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 tr.exportTo('tr.ui.e.about_tracing', function() { | 15 tr.exportTo('tr.ui.e.about_tracing', function() { |
16 function createResolvedPromise(data) { | 16 function createResolvedPromise(data) { |
17 var promise = new Promise(function(resolve, reject) { | 17 var promise = new Promise(function(resolve, reject) { |
18 if (data) | 18 if (data) { |
19 resolve(data); | 19 resolve(data); |
20 else | 20 } else { |
21 resolve(); | 21 resolve(); |
| 22 } |
22 }); | 23 }); |
23 return promise; | 24 return promise; |
24 } | 25 } |
25 | 26 |
26 function appendTraceChunksTo(chunks, messageString) { | 27 function appendTraceChunksTo(chunks, messageString) { |
27 if (typeof messageString !== 'string') | 28 if (typeof messageString !== 'string') { |
28 throw new Error('Invalid data'); | 29 throw new Error('Invalid data'); |
| 30 } |
29 var re = /"params":\s*\{\s*"value":\s*\[([^]+)\]\s*\}\s*\}/; | 31 var re = /"params":\s*\{\s*"value":\s*\[([^]+)\]\s*\}\s*\}/; |
30 var m = re.exec(messageString); | 32 var m = re.exec(messageString); |
31 if (!m) | 33 if (!m) { |
32 throw new Error('Malformed response'); | 34 throw new Error('Malformed response'); |
| 35 } |
33 | 36 |
34 if (chunks.length > 1) | 37 if (chunks.length > 1) { |
35 chunks.push(','); | 38 chunks.push(','); |
| 39 } |
36 chunks.push(m[1]); | 40 chunks.push(m[1]); |
37 } | 41 } |
38 | 42 |
39 /** | 43 /** |
40 * Controls tracing using the inspector's FrontendAgentHost APIs. | 44 * Controls tracing using the inspector's FrontendAgentHost APIs. |
41 * | 45 * |
42 * @constructor | 46 * @constructor |
43 */ | 47 */ |
44 function InspectorTracingControllerClient() { | 48 function InspectorTracingControllerClient() { |
45 this.recording_ = false; | 49 this.recording_ = false; |
(...skipping 30 matching lines...) Expand all Loading... |
76 getCategories: function() { | 80 getCategories: function() { |
77 var res = this.conn_.req('Tracing.getCategories', {}); | 81 var res = this.conn_.req('Tracing.getCategories', {}); |
78 return res.then(function(result) { | 82 return res.then(function(result) { |
79 return result.categories; | 83 return result.categories; |
80 }, function(err) { | 84 }, function(err) { |
81 return []; | 85 return []; |
82 }); | 86 }); |
83 }, | 87 }, |
84 | 88 |
85 beginRecording: function(recordingOptions) { | 89 beginRecording: function(recordingOptions) { |
86 if (this.recording_) | 90 if (this.recording_) { |
87 throw new Error('Already recording'); | 91 throw new Error('Already recording'); |
| 92 } |
88 this.recording_ = 'starting'; | 93 this.recording_ = 'starting'; |
89 var res = this.conn_.req( | 94 var res = this.conn_.req( |
90 'Tracing.start', | 95 'Tracing.start', |
91 { | 96 { |
92 categories: recordingOptions.categoryFilter, | 97 categories: recordingOptions.categoryFilter, |
93 options: | 98 options: |
94 [recordingOptions.tracingRecordMode, | 99 [recordingOptions.tracingRecordMode, |
95 (recordingOptions.useSampling ? 'enable-sampling' : '') | 100 (recordingOptions.useSampling ? 'enable-sampling' : '') |
96 ].join(','), | 101 ].join(','), |
97 bufferUsageReportingInterval: 1000 | 102 bufferUsageReportingInterval: 1000 |
(...skipping 21 matching lines...) Expand all Loading... |
119 resolve(this.bufferUsage_); | 124 resolve(this.bufferUsage_); |
120 }, 100); | 125 }, 100); |
121 }); | 126 }); |
122 }, | 127 }, |
123 | 128 |
124 onDataCollected_: function(messageString) { | 129 onDataCollected_: function(messageString) { |
125 appendTraceChunksTo(this.currentTraceTextChunks_, messageString); | 130 appendTraceChunksTo(this.currentTraceTextChunks_, messageString); |
126 }, | 131 }, |
127 | 132 |
128 endRecording: function() { | 133 endRecording: function() { |
129 if (this.recording_ === false) | 134 if (this.recording_ === false) { |
130 return createResolvedPromise(); | 135 return createResolvedPromise(); |
| 136 } |
131 | 137 |
132 if (this.recording_ !== true) | 138 if (this.recording_ !== true) { |
133 throw new Error('Cannot end'); | 139 throw new Error('Cannot end'); |
| 140 } |
134 | 141 |
135 this.currentTraceTextChunks_ = ['[']; | 142 this.currentTraceTextChunks_ = ['[']; |
136 this.conn_.setNotificationListener( | 143 this.conn_.setNotificationListener( |
137 'Tracing.dataCollected', this.onDataCollected_.bind(this)); | 144 'Tracing.dataCollected', this.onDataCollected_.bind(this)); |
138 | 145 |
139 var clearListeners = function() { | 146 var clearListeners = function() { |
140 this.conn_.setNotificationListener( | 147 this.conn_.setNotificationListener( |
141 'Tracing.bufferUsage', undefined); | 148 'Tracing.bufferUsage', undefined); |
142 this.conn_.setNotificationListener( | 149 this.conn_.setNotificationListener( |
143 'Tracing.tracingComplete', undefined); | 150 'Tracing.tracingComplete', undefined); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return 'trace.json'; | 184 return 'trace.json'; |
178 } | 185 } |
179 }; | 186 }; |
180 | 187 |
181 return { | 188 return { |
182 InspectorTracingControllerClient, | 189 InspectorTracingControllerClient, |
183 appendTraceChunksTo, | 190 appendTraceChunksTo, |
184 }; | 191 }; |
185 }); | 192 }); |
186 </script> | 193 </script> |
OLD | NEW |