NativeHeapSnapshot.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright (C) 2013 Google 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 are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * @constructor
  32. * @extends {WebInspector.HeapSnapshot}
  33. */
  34. WebInspector.NativeHeapSnapshot = function(profile)
  35. {
  36. WebInspector.HeapSnapshot.call(this, profile);
  37. this._nodeObjectType = this._metaNode.type_strings["object"];
  38. this._edgeWeakType = this._metaNode.type_strings["weak"];
  39. this._edgeElementType = this._metaNode.type_strings["property"];
  40. }
  41. WebInspector.NativeHeapSnapshot.prototype = {
  42. createNode: function(nodeIndex)
  43. {
  44. return new WebInspector.NativeHeapSnapshotNode(this, nodeIndex);
  45. },
  46. createEdge: function(edges, edgeIndex)
  47. {
  48. return new WebInspector.NativeHeapSnapshotEdge(this, edges, edgeIndex);
  49. },
  50. createRetainingEdge: function(retainedNodeIndex, retainerIndex)
  51. {
  52. return new WebInspector.NativeHeapSnapshotRetainerEdge(this, retainedNodeIndex, retainerIndex);
  53. },
  54. _markInvisibleEdges: function()
  55. {
  56. },
  57. _calculateFlags: function()
  58. {
  59. },
  60. userObjectsMapAndFlag: function()
  61. {
  62. return null;
  63. },
  64. images: function()
  65. {
  66. var aggregatesByClassName = this.aggregates(false, "allObjects");
  67. var result = [];
  68. var cachedImages = aggregatesByClassName["WebCore::CachedImage"];
  69. function getImageName(node)
  70. {
  71. return node.name();
  72. }
  73. this._addNodes(cachedImages, getImageName, result);
  74. var canvases = aggregatesByClassName["WebCore::HTMLCanvasElement"];
  75. function getCanvasName(node)
  76. {
  77. return "HTMLCanvasElement";
  78. }
  79. this._addNodes(canvases, getCanvasName, result);
  80. return result;
  81. },
  82. _addNodes: function(classData, nameResolver, result)
  83. {
  84. if (!classData)
  85. return;
  86. var node = this.rootNode();
  87. for (var i = 0; i < classData.idxs.length; i++) {
  88. node.nodeIndex = classData.idxs[i];
  89. result.push({
  90. name: nameResolver(node),
  91. size: node.retainedSize(),
  92. });
  93. }
  94. },
  95. __proto__: WebInspector.HeapSnapshot.prototype
  96. };
  97. /**
  98. * @constructor
  99. * @extends {WebInspector.HeapSnapshotNode}
  100. * @param {WebInspector.NativeHeapSnapshot} snapshot
  101. * @param {number=} nodeIndex
  102. */
  103. WebInspector.NativeHeapSnapshotNode = function(snapshot, nodeIndex)
  104. {
  105. WebInspector.HeapSnapshotNode.call(this, snapshot, nodeIndex)
  106. }
  107. WebInspector.NativeHeapSnapshotNode.prototype = {
  108. className: function()
  109. {
  110. return this._snapshot._strings[this.classIndex()];
  111. },
  112. classIndex: function()
  113. {
  114. return this._snapshot._nodes[this.nodeIndex + this._snapshot._nodeTypeOffset];
  115. },
  116. id: function()
  117. {
  118. return this._snapshot._nodes[this.nodeIndex + this._snapshot._nodeIdOffset];
  119. },
  120. name: function()
  121. {
  122. return this._snapshot._strings[this._snapshot._nodes[this.nodeIndex + this._snapshot._nodeNameOffset]];;
  123. },
  124. serialize: function()
  125. {
  126. return {
  127. id: this.id(),
  128. name: this.className(),
  129. displayName: this.name(),
  130. distance: this.distance(),
  131. nodeIndex: this.nodeIndex,
  132. retainedSize: this.retainedSize(),
  133. selfSize: this.selfSize(),
  134. type: this._snapshot._nodeObjectType
  135. };
  136. },
  137. isHidden: function()
  138. {
  139. return false;
  140. },
  141. isSynthetic: function()
  142. {
  143. return false;
  144. },
  145. __proto__: WebInspector.HeapSnapshotNode.prototype
  146. };
  147. /**
  148. * @constructor
  149. * @extends {WebInspector.HeapSnapshotEdge}
  150. * @param {WebInspector.NativeHeapSnapshot} snapshot
  151. * @param {Array.<number>} edges
  152. * @param {number=} edgeIndex
  153. */
  154. WebInspector.NativeHeapSnapshotEdge = function(snapshot, edges, edgeIndex)
  155. {
  156. WebInspector.HeapSnapshotEdge.call(this, snapshot, edges, edgeIndex);
  157. }
  158. WebInspector.NativeHeapSnapshotEdge.prototype = {
  159. clone: function()
  160. {
  161. return new WebInspector.NativeHeapSnapshotEdge(this._snapshot, this._edges, this.edgeIndex);
  162. },
  163. hasStringName: function()
  164. {
  165. return true;
  166. },
  167. isHidden: function()
  168. {
  169. return false;
  170. },
  171. isWeak: function()
  172. {
  173. return false;
  174. },
  175. isInternal: function()
  176. {
  177. return false;
  178. },
  179. isInvisible: function()
  180. {
  181. return false;
  182. },
  183. isShortcut: function()
  184. {
  185. return false;
  186. },
  187. name: function()
  188. {
  189. return this._snapshot._strings[this._nameOrIndex()];
  190. },
  191. toString: function()
  192. {
  193. return "NativeHeapSnapshotEdge: " + this.name();
  194. },
  195. _nameOrIndex: function()
  196. {
  197. return this._edges.item(this.edgeIndex + this._snapshot._edgeNameOffset);
  198. },
  199. __proto__: WebInspector.HeapSnapshotEdge.prototype
  200. };
  201. /**
  202. * @constructor
  203. * @extends {WebInspector.HeapSnapshotRetainerEdge}
  204. * @param {WebInspector.NativeHeapSnapshot} snapshot
  205. */
  206. WebInspector.NativeHeapSnapshotRetainerEdge = function(snapshot, retainedNodeIndex, retainerIndex)
  207. {
  208. WebInspector.HeapSnapshotRetainerEdge.call(this, snapshot, retainedNodeIndex, retainerIndex);
  209. }
  210. WebInspector.NativeHeapSnapshotRetainerEdge.prototype = {
  211. clone: function()
  212. {
  213. return new WebInspector.NativeHeapSnapshotRetainerEdge(this._snapshot, this._retainedNodeIndex, this.retainerIndex());
  214. },
  215. isHidden: function()
  216. {
  217. return this._edge().isHidden();
  218. },
  219. isInternal: function()
  220. {
  221. return this._edge().isInternal();
  222. },
  223. isInvisible: function()
  224. {
  225. return this._edge().isInvisible();
  226. },
  227. isShortcut: function()
  228. {
  229. return this._edge().isShortcut();
  230. },
  231. isWeak: function()
  232. {
  233. return this._edge().isWeak();
  234. },
  235. __proto__: WebInspector.HeapSnapshotRetainerEdge.prototype
  236. }