• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2009 280 North Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26/**
27 * @constructor
28 * @extends {WebInspector.ProfileDataGridNode}
29 * @param {!ProfilerAgent.CPUProfileNode} profileNode
30 * @param {!WebInspector.TopDownProfileDataGridTree} owningTree
31 */
32WebInspector.TopDownProfileDataGridNode = function(profileNode, owningTree)
33{
34    var hasChildren = !!(profileNode.children && profileNode.children.length);
35
36    WebInspector.ProfileDataGridNode.call(this, profileNode, owningTree, hasChildren);
37
38    this._remainingChildren = profileNode.children;
39    this.buildData();
40}
41
42WebInspector.TopDownProfileDataGridNode.prototype = {
43    _sharedPopulate: function()
44    {
45        var children = this._remainingChildren;
46        var childrenLength = children.length;
47
48        for (var i = 0; i < childrenLength; ++i)
49            this.appendChild(new WebInspector.TopDownProfileDataGridNode(children[i], this.tree));
50
51        this._remainingChildren = null;
52    },
53
54    _exclude: function(aCallUID)
55    {
56        if (this._remainingChildren)
57            this.populate();
58
59        this._save();
60
61        var children = this.children;
62        var index = this.children.length;
63
64        while (index--)
65            children[index]._exclude(aCallUID);
66
67        var child = this.childrenByCallUID[aCallUID];
68
69        if (child)
70            this._merge(child, true);
71    },
72
73    __proto__: WebInspector.ProfileDataGridNode.prototype
74}
75
76/**
77 * @constructor
78 * @extends {WebInspector.ProfileDataGridTree}
79 * @param {!WebInspector.CPUProfileView} profileView
80 * @param {!ProfilerAgent.CPUProfileNode} rootProfileNode
81 */
82WebInspector.TopDownProfileDataGridTree = function(profileView, rootProfileNode)
83{
84    WebInspector.ProfileDataGridTree.call(this, profileView, rootProfileNode);
85
86    this._remainingChildren = rootProfileNode.children;
87
88    var any = /** @type {*} */(this);
89    var node = /** @type {!WebInspector.ProfileDataGridNode} */(any);
90    WebInspector.TopDownProfileDataGridNode.prototype.populate.call(node);
91}
92
93WebInspector.TopDownProfileDataGridTree.prototype = {
94    /**
95     * @param {!WebInspector.ProfileDataGridNode} profileDataGridNode
96     */
97    focus: function(profileDataGridNode)
98    {
99        if (!profileDataGridNode)
100            return;
101
102        this._save();
103        profileDataGridNode.savePosition();
104
105        this.children = [profileDataGridNode];
106        this.totalTime = profileDataGridNode.totalTime;
107    },
108
109    /**
110     * @param {!WebInspector.ProfileDataGridNode} profileDataGridNode
111     */
112    exclude: function(profileDataGridNode)
113    {
114        if (!profileDataGridNode)
115            return;
116
117        this._save();
118
119        var excludedCallUID = profileDataGridNode.callUID;
120
121        var any = /** @type {*} */(this);
122        var node = /** @type {!WebInspector.TopDownProfileDataGridNode} */(any);
123        WebInspector.TopDownProfileDataGridNode.prototype._exclude.call(node, excludedCallUID);
124
125        if (this.lastComparator)
126            this.sort(this.lastComparator, true);
127    },
128
129    restore: function()
130    {
131        if (!this._savedChildren)
132            return;
133
134        this.children[0].restorePosition();
135
136        WebInspector.ProfileDataGridTree.prototype.restore.call(this);
137    },
138
139    _merge: WebInspector.TopDownProfileDataGridNode.prototype._merge,
140
141    _sharedPopulate: WebInspector.TopDownProfileDataGridNode.prototype._sharedPopulate,
142
143    __proto__: WebInspector.ProfileDataGridTree.prototype
144}
145