Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 774 */ | 774 */ |
| 775 addHeapSnapshotChunk: function(uid, chunk) | 775 addHeapSnapshotChunk: function(uid, chunk) |
| 776 { | 776 { |
| 777 this._genericCaller("addHeapSnapshotChunk"); | 777 this._genericCaller("addHeapSnapshotChunk"); |
| 778 }, | 778 }, |
| 779 | 779 |
| 780 /** | 780 /** |
| 781 * @override | 781 * @override |
| 782 * @param {number} done | 782 * @param {number} done |
| 783 * @param {number} total | 783 * @param {number} total |
| 784 * @param {boolean=} finished | |
| 784 */ | 785 */ |
| 785 reportHeapSnapshotProgress: function(done, total) | 786 reportHeapSnapshotProgress: function(done, total, finished) |
| 786 { | 787 { |
| 787 this._genericCaller("reportHeapSnapshotProgress"); | 788 this._genericCaller("reportHeapSnapshotProgress"); |
| 788 }, | 789 }, |
| 789 | 790 |
| 790 /** | 791 /** |
| 791 * @override | 792 * @override |
| 792 */ | 793 */ |
| 793 resetProfiles: function() | 794 resetProfiles: function() |
| 794 { | 795 { |
| 795 this._genericCaller("resetProfiles"); | 796 this._genericCaller("resetProfiles"); |
| 796 } | 797 } |
| 797 } | 798 } |
| 798 | 799 |
| 799 WebInspector.HeapProfilerDispatcher._dispatcher = new WebInspector.HeapProfilerD ispatcher(); | 800 WebInspector.HeapProfilerDispatcher._dispatcher = new WebInspector.HeapProfilerD ispatcher(); |
| 800 | 801 |
| 801 /** | 802 /** |
| 802 * @constructor | 803 * @constructor |
| 803 * @extends {WebInspector.ProfileType} | 804 * @extends {WebInspector.ProfileType} |
| 804 * @implements {HeapProfilerAgent.Dispatcher} | 805 * @implements {HeapProfilerAgent.Dispatcher} |
| 806 * @param {string=} id | |
| 807 * @param {string=} title | |
| 805 */ | 808 */ |
| 806 WebInspector.HeapSnapshotProfileType = function() | 809 WebInspector.HeapSnapshotProfileType = function(id, title) |
| 807 { | 810 { |
| 808 WebInspector.ProfileType.call(this, WebInspector.HeapSnapshotProfileType.Typ eId, WebInspector.UIString("Take Heap Snapshot")); | 811 WebInspector.ProfileType.call(this, id || WebInspector.HeapSnapshotProfileTy pe.TypeId, title || WebInspector.UIString("Take Heap Snapshot")); |
| 809 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); | 812 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); |
| 813 | |
| 814 this._nextSnapshotId = 1; | |
| 810 } | 815 } |
| 811 | 816 |
| 812 WebInspector.HeapSnapshotProfileType.TypeId = "HEAP"; | 817 WebInspector.HeapSnapshotProfileType.TypeId = "HEAP"; |
| 813 WebInspector.HeapSnapshotProfileType.SnapshotReceived = "SnapshotReceived"; | 818 WebInspector.HeapSnapshotProfileType.SnapshotReceived = "SnapshotReceived"; |
| 814 | 819 |
| 815 WebInspector.HeapSnapshotProfileType.prototype = { | 820 WebInspector.HeapSnapshotProfileType.prototype = { |
| 816 /** | 821 /** |
| 817 * @override | 822 * @override |
| 818 * @return {string} | 823 * @return {string} |
| 819 */ | 824 */ |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 */ | 886 */ |
| 882 createProfileLoadedFromFile: function(title) | 887 createProfileLoadedFromFile: function(title) |
| 883 { | 888 { |
| 884 return new WebInspector.HeapProfileHeader(this, title); | 889 return new WebInspector.HeapProfileHeader(this, title); |
| 885 }, | 890 }, |
| 886 | 891 |
| 887 _takeHeapSnapshot: function(callback) | 892 _takeHeapSnapshot: function(callback) |
| 888 { | 893 { |
| 889 if (this.profileBeingRecorded()) | 894 if (this.profileBeingRecorded()) |
| 890 return; | 895 return; |
| 891 this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this, We bInspector.UIString("Snapshotting\u2026")); | 896 var id = this._nextSnapshotId++; |
| 897 this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this, We bInspector.UIString("Snapshotting\u2026"), id); | |
| 892 this.addProfile(this._profileBeingRecorded); | 898 this.addProfile(this._profileBeingRecorded); |
| 893 HeapProfilerAgent.takeHeapSnapshot(true, callback); | 899 /** |
| 900 * @param {?string} error | |
| 901 * @this {WebInspector.HeapSnapshotProfileType} | |
| 902 */ | |
| 903 function didTakeHeapSnapshot(error) | |
| 904 { | |
| 905 var profile = this._profileBeingRecorded; | |
| 906 profile.title = WebInspector.UIString("Snapshot %d", profile.uid); | |
| 907 profile._finishLoad(); | |
| 908 this._profileBeingRecorded = null; | |
| 909 callback(); | |
| 910 } | |
| 911 HeapProfilerAgent.takeHeapSnapshot(true, didTakeHeapSnapshot.bind(this)) ; | |
| 894 }, | 912 }, |
| 895 | 913 |
| 896 /** | 914 /** |
| 897 * @param {!HeapProfilerAgent.ProfileHeader} profileHeader | 915 * @param {!HeapProfilerAgent.ProfileHeader} profileHeader |
| 898 */ | 916 */ |
| 899 addProfileHeader: function(profileHeader) | 917 addProfileHeader: function(profileHeader) |
| 900 { | 918 { |
| 901 var profile = this.profileBeingRecorded(); | 919 var profile = this.profileBeingRecorded(); |
| 902 if (!profile) | 920 if (!profile) |
| 903 return; | 921 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 916 profile.existingView()._refreshView(); | 934 profile.existingView()._refreshView(); |
| 917 }, | 935 }, |
| 918 | 936 |
| 919 /** | 937 /** |
| 920 * @override | 938 * @override |
| 921 * @param {number} uid | 939 * @param {number} uid |
| 922 * @param {string} chunk | 940 * @param {string} chunk |
| 923 */ | 941 */ |
| 924 addHeapSnapshotChunk: function(uid, chunk) | 942 addHeapSnapshotChunk: function(uid, chunk) |
| 925 { | 943 { |
| 926 var profile = this.getProfile(uid); | 944 if (!this.profileBeingRecorded()) |
| 927 if (profile) | 945 return; |
| 928 profile.transferChunk(chunk); | 946 this.profileBeingRecorded().transferChunk(chunk); |
| 929 }, | 947 }, |
| 930 | 948 |
| 931 /** | 949 /** |
| 932 * @override | 950 * @override |
| 933 * @param {number} done | 951 * @param {number} done |
| 934 * @param {number} total | 952 * @param {number} total |
| 953 * @param {boolean=} finished | |
| 935 */ | 954 */ |
| 936 reportHeapSnapshotProgress: function(done, total) | 955 reportHeapSnapshotProgress: function(done, total, finished) |
| 937 { | 956 { |
| 938 var profile = this.profileBeingRecorded(); | 957 var profile = this.profileBeingRecorded(); |
| 939 if (!profile) | 958 if (!profile) |
| 940 return; | 959 return; |
| 941 profile.sidebarElement.subtitle = WebInspector.UIString("%.0f%", (done / total) * 100); | 960 profile.sidebarElement.subtitle = WebInspector.UIString("%.0f%", (done / total) * 100); |
| 942 profile.sidebarElement.wait = true; | 961 profile.sidebarElement.wait = true; |
| 962 if (finished) | |
| 963 profile._prepareToLoad(); | |
| 943 }, | 964 }, |
| 944 | 965 |
| 945 /** | 966 /** |
| 946 * @override | 967 * @override |
| 947 */ | 968 */ |
| 948 resetProfiles: function() | 969 resetProfiles: function() |
| 949 { | 970 { |
| 950 this._reset(); | 971 this._reset(); |
| 951 }, | 972 }, |
| 952 | 973 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 972 } | 993 } |
| 973 | 994 |
| 974 | 995 |
| 975 /** | 996 /** |
| 976 * @constructor | 997 * @constructor |
| 977 * @extends {WebInspector.HeapSnapshotProfileType} | 998 * @extends {WebInspector.HeapSnapshotProfileType} |
| 978 * @param {!WebInspector.ProfilesPanel} profilesPanel | 999 * @param {!WebInspector.ProfilesPanel} profilesPanel |
| 979 */ | 1000 */ |
| 980 WebInspector.TrackingHeapSnapshotProfileType = function(profilesPanel) | 1001 WebInspector.TrackingHeapSnapshotProfileType = function(profilesPanel) |
| 981 { | 1002 { |
| 982 WebInspector.ProfileType.call(this, WebInspector.TrackingHeapSnapshotProfile Type.TypeId, WebInspector.UIString("Record Heap Allocations")); | 1003 WebInspector.HeapSnapshotProfileType.call(this, WebInspector.TrackingHeapSna pshotProfileType.TypeId, WebInspector.UIString("Record Heap Allocations")); |
| 983 this._profilesPanel = profilesPanel; | 1004 this._profilesPanel = profilesPanel; |
| 984 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); | |
| 985 } | 1005 } |
| 986 | 1006 |
| 987 WebInspector.TrackingHeapSnapshotProfileType.TypeId = "HEAP-RECORD"; | 1007 WebInspector.TrackingHeapSnapshotProfileType.TypeId = "HEAP-RECORD"; |
| 988 | 1008 |
| 989 WebInspector.TrackingHeapSnapshotProfileType.HeapStatsUpdate = "HeapStatsUpdate" ; | 1009 WebInspector.TrackingHeapSnapshotProfileType.HeapStatsUpdate = "HeapStatsUpdate" ; |
| 990 WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted = "TrackingStarted" ; | 1010 WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted = "TrackingStarted" ; |
| 991 WebInspector.TrackingHeapSnapshotProfileType.TrackingStopped = "TrackingStopped" ; | 1011 WebInspector.TrackingHeapSnapshotProfileType.TrackingStopped = "TrackingStopped" ; |
| 992 | 1012 |
| 993 WebInspector.TrackingHeapSnapshotProfileType.prototype = { | 1013 WebInspector.TrackingHeapSnapshotProfileType.prototype = { |
| 994 | 1014 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1085 }; | 1105 }; |
| 1086 this._profileBeingRecorded._profileSamples = this._profileSamples; | 1106 this._profileBeingRecorded._profileSamples = this._profileSamples; |
| 1087 this._recording = true; | 1107 this._recording = true; |
| 1088 this.addProfile(this._profileBeingRecorded); | 1108 this.addProfile(this._profileBeingRecorded); |
| 1089 HeapProfilerAgent.startTrackingHeapObjects(); | 1109 HeapProfilerAgent.startTrackingHeapObjects(); |
| 1090 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy pe.TrackingStarted); | 1110 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy pe.TrackingStarted); |
| 1091 }, | 1111 }, |
| 1092 | 1112 |
| 1093 _stopRecordingProfile: function() | 1113 _stopRecordingProfile: function() |
| 1094 { | 1114 { |
| 1095 HeapProfilerAgent.stopTrackingHeapObjects(true); | 1115 |
| 1116 var profile = this._profileBeingRecorded; | |
| 1117 var title = WebInspector.UIString("Snapshotting\u2026"); | |
| 1118 profile.title = title; | |
| 1119 profile.sidebarElement.mainTitle = title; | |
| 1120 /** | |
| 1121 * @param {?string} error | |
| 1122 * @this {WebInspector.HeapSnapshotProfileType} | |
|
alph
2013/12/23 14:06:59
WebInspector.TrackingHeapSnapshotProfileType
| |
| 1123 */ | |
| 1124 function didTakeHeapSnapshot(error) | |
|
alph
2013/12/23 14:06:59
It seems to have a bunch of similar code to its fr
| |
| 1125 { | |
| 1126 profile.uid = this._nextSnapshotId++; | |
| 1127 var title = WebInspector.UIString("Snapshot %d", profile.uid); | |
| 1128 profile.title = title; | |
| 1129 profile.sidebarElement.mainTitle = title; | |
| 1130 WebInspector.log("didTakeHeapSnapshot " + this._profileBeingRecorded ); | |
|
alph
2013/12/23 14:06:59
is that intended?
| |
| 1131 profile._finishLoad(); | |
| 1132 this._profileSamples = null; | |
| 1133 this._profileBeingRecorded = null; | |
| 1134 WebInspector.panels.profiles._showProfile(profile); | |
|
alph
2013/12/23 14:06:59
Event broadcasting would look more elegant here. w
| |
| 1135 profile.existingView()._refreshView(); | |
| 1136 } | |
| 1137 | |
| 1138 HeapProfilerAgent.stopTrackingHeapObjects(true, didTakeHeapSnapshot.bind (this)); | |
| 1096 this._recording = false; | 1139 this._recording = false; |
| 1097 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy pe.TrackingStopped); | 1140 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy pe.TrackingStopped); |
| 1098 }, | 1141 }, |
| 1099 | 1142 |
| 1100 _toggleRecording: function() | 1143 _toggleRecording: function() |
| 1101 { | 1144 { |
| 1102 if (this._recording) | 1145 if (this._recording) |
| 1103 this._stopRecordingProfile(); | 1146 this._stopRecordingProfile(); |
| 1104 else | 1147 else |
| 1105 this._startRecordingProfile(); | 1148 this._startRecordingProfile(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1176 */ | 1219 */ |
| 1177 load: function(callback) | 1220 load: function(callback) |
| 1178 { | 1221 { |
| 1179 if (this.uid === -1) | 1222 if (this.uid === -1) |
| 1180 return; | 1223 return; |
| 1181 if (this._snapshotProxy) { | 1224 if (this._snapshotProxy) { |
| 1182 callback(this._snapshotProxy); | 1225 callback(this._snapshotProxy); |
| 1183 return; | 1226 return; |
| 1184 } | 1227 } |
| 1185 | 1228 |
| 1186 this._numberOfChunks = 0; | |
| 1187 if (!this._receiver) { | |
| 1188 this._setupWorker(); | |
| 1189 this._transferHandler = new WebInspector.BackendSnapshotLoader(this) ; | |
| 1190 this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026" ); | |
| 1191 this.sidebarElement.wait = true; | |
| 1192 this._transferSnapshot(); | |
| 1193 } | |
| 1194 var loaderProxy = /** @type {?WebInspector.HeapSnapshotLoaderProxy} */ ( this._receiver); | 1229 var loaderProxy = /** @type {?WebInspector.HeapSnapshotLoaderProxy} */ ( this._receiver); |
| 1195 console.assert(loaderProxy); | 1230 console.assert(loaderProxy); |
| 1196 loaderProxy.addConsumer(callback); | 1231 loaderProxy.addConsumer(callback); |
| 1197 }, | 1232 }, |
| 1198 | 1233 |
| 1234 _prepareToLoad: function() | |
| 1235 { | |
| 1236 console.assert(!this._receiver, "Already loading"); | |
| 1237 this._numberOfChunks = 0; | |
| 1238 this._setupWorker(); | |
| 1239 this._transferHandler = new WebInspector.BackendSnapshotLoader(this); | |
| 1240 this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026"); | |
| 1241 this.sidebarElement.wait = true; | |
| 1242 }, | |
| 1243 | |
| 1244 _finishLoad: function() | |
| 1245 { | |
| 1246 if (this._transferHandler) { | |
| 1247 this._transferHandler.finishTransfer(); | |
| 1248 this._totalNumberOfChunks = this._transferHandler._totalNumberOfChun ks; | |
| 1249 } | |
| 1250 }, | |
| 1251 | |
| 1199 _transferSnapshot: function() | 1252 _transferSnapshot: function() |
| 1200 { | 1253 { |
| 1201 /** | 1254 /** |
| 1202 * @this {WebInspector.HeapProfileHeader} | 1255 * @this {WebInspector.HeapProfileHeader} |
| 1203 */ | 1256 */ |
| 1204 function finishTransfer() | 1257 function finishTransfer() |
| 1205 { | 1258 { |
| 1206 if (this._transferHandler) { | 1259 if (this._transferHandler) { |
| 1207 this._transferHandler.finishTransfer(); | 1260 this._transferHandler.finishTransfer(); |
| 1208 this._totalNumberOfChunks = this._transferHandler._totalNumberOf Chunks; | 1261 this._totalNumberOfChunks = this._transferHandler._totalNumberOf Chunks; |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1845 zeroTime: function() | 1898 zeroTime: function() |
| 1846 { | 1899 { |
| 1847 return this._minimumBoundaries; | 1900 return this._minimumBoundaries; |
| 1848 }, | 1901 }, |
| 1849 | 1902 |
| 1850 boundarySpan: function() | 1903 boundarySpan: function() |
| 1851 { | 1904 { |
| 1852 return this._maximumBoundaries - this._minimumBoundaries; | 1905 return this._maximumBoundaries - this._minimumBoundaries; |
| 1853 } | 1906 } |
| 1854 } | 1907 } |
| OLD | NEW |