Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / sdk / TracingManager.js
1 /*
2  * Copyright 2014 The Chromium Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /**
8  * @constructor
9  * @extends {WebInspector.Object}
10  * @implements {WebInspector.TargetManager.Observer}
11  */
12 WebInspector.TracingManager = function()
13 {
14     WebInspector.Object.call(this);
15     this._active = false;
16     WebInspector.targetManager.observeTargets(this);
17 }
18
19 WebInspector.TracingManager.Events = {
20     "BufferUsage": "BufferUsage",
21     "TracingStarted": "TracingStarted",
22     "EventsCollected": "EventsCollected",
23     "TracingStopped": "TracingStopped",
24     "TracingComplete": "TracingComplete"
25 }
26
27 /** @typedef {!{
28         cat: string,
29         pid: number,
30         tid: number,
31         ts: number,
32         ph: string,
33         name: string,
34         args: !Object,
35         dur: number,
36         id: number,
37         s: string
38     }}
39  */
40 WebInspector.TracingManager.EventPayload;
41
42 WebInspector.TracingManager.prototype = {
43     /**
44      * @param {!WebInspector.Target} target
45      */
46     targetAdded: function(target)
47     {
48         if (this._target)
49             return;
50         this._target = target;
51         target.registerTracingDispatcher(new WebInspector.TracingDispatcher(this));
52     },
53
54     /**
55      * @param {!WebInspector.Target} target
56      */
57     targetRemoved: function(target)
58     {
59         if (this._target !== target)
60             return;
61         delete this._target;
62     },
63
64     /**
65      * @param {number} usage
66      */
67     _bufferUsage: function(usage)
68     {
69         this.dispatchEventToListeners(WebInspector.TracingManager.Events.BufferUsage, usage);
70     },
71
72     /**
73      * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
74      */
75     _eventsCollected: function(events)
76     {
77         this.dispatchEventToListeners(WebInspector.TracingManager.Events.EventsCollected, events);
78     },
79
80     _tracingComplete: function()
81     {
82         this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingComplete);
83     },
84
85     /**
86      * @param {string} categoryFilter
87      * @param {string} options
88      * @param {function(?string)=} callback
89      */
90     start: function(categoryFilter, options, callback)
91     {
92         if (this._active)
93             return;
94         WebInspector.targetManager.suspendAllTargets();
95         var bufferUsageReportingIntervalMs = 500;
96         TracingAgent.start(categoryFilter, options, bufferUsageReportingIntervalMs, callback);
97         this._active = true;
98         this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStarted);
99     },
100
101     stop: function()
102     {
103         if (!this._active)
104             return;
105         TracingAgent.end(this._onStop.bind(this));
106         WebInspector.targetManager.resumeAllTargets();
107     },
108
109     _onStop: function()
110     {
111         if (!this._active)
112             return;
113         this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStopped);
114         this._active = false;
115     },
116
117     __proto__: WebInspector.Object.prototype
118 }
119
120 /**
121  * @constructor
122  * @implements {TracingAgent.Dispatcher}
123  * @param {!WebInspector.TracingManager} tracingManager
124  */
125 WebInspector.TracingDispatcher = function(tracingManager)
126 {
127     this._tracingManager = tracingManager;
128 }
129
130 WebInspector.TracingDispatcher.prototype = {
131     /**
132      * @param {number} usage
133      */
134     bufferUsage: function(usage)
135     {
136         this._tracingManager._bufferUsage(usage);
137     },
138
139     /**
140      * @param {!Array.<!WebInspector.TracingManager.EventPayload>} data
141      */
142     dataCollected: function(data)
143     {
144         this._tracingManager._eventsCollected(data);
145     },
146
147     tracingComplete: function()
148     {
149         this._tracingManager._tracingComplete();
150     }
151 }