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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 */ | 789 */ |
790 addHeapSnapshotChunk: function(uid, chunk) | 790 addHeapSnapshotChunk: function(uid, chunk) |
791 { | 791 { |
792 this._genericCaller("addHeapSnapshotChunk"); | 792 this._genericCaller("addHeapSnapshotChunk"); |
793 }, | 793 }, |
794 | 794 |
795 /** | 795 /** |
796 * @override | 796 * @override |
797 * @param {number} done | 797 * @param {number} done |
798 * @param {number} total | 798 * @param {number} total |
| 799 * @param {boolean=} finished |
799 */ | 800 */ |
800 reportHeapSnapshotProgress: function(done, total) | 801 reportHeapSnapshotProgress: function(done, total, finished) |
801 { | 802 { |
802 this._genericCaller("reportHeapSnapshotProgress"); | 803 this._genericCaller("reportHeapSnapshotProgress"); |
803 }, | 804 }, |
804 | 805 |
805 /** | 806 /** |
806 * @override | 807 * @override |
807 */ | 808 */ |
808 resetProfiles: function() | 809 resetProfiles: function() |
809 { | 810 { |
810 this._genericCaller("resetProfiles"); | 811 this._genericCaller("resetProfiles"); |
811 } | 812 } |
812 } | 813 } |
813 | 814 |
814 WebInspector.HeapProfilerDispatcher._dispatcher = new WebInspector.HeapProfilerD
ispatcher(); | 815 WebInspector.HeapProfilerDispatcher._dispatcher = new WebInspector.HeapProfilerD
ispatcher(); |
815 | 816 |
816 /** | 817 /** |
817 * @constructor | 818 * @constructor |
818 * @extends {WebInspector.ProfileType} | 819 * @extends {WebInspector.ProfileType} |
819 * @implements {HeapProfilerAgent.Dispatcher} | 820 * @implements {HeapProfilerAgent.Dispatcher} |
| 821 * @param {string=} id |
| 822 * @param {string=} title |
820 */ | 823 */ |
821 WebInspector.HeapSnapshotProfileType = function() | 824 WebInspector.HeapSnapshotProfileType = function(id, title) |
822 { | 825 { |
823 WebInspector.ProfileType.call(this, WebInspector.HeapSnapshotProfileType.Typ
eId, WebInspector.UIString("Take Heap Snapshot")); | 826 WebInspector.ProfileType.call(this, id || WebInspector.HeapSnapshotProfileTy
pe.TypeId, title || WebInspector.UIString("Take Heap Snapshot")); |
824 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); | 827 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); |
| 828 |
| 829 this._nextSnapshotId = 1; |
825 } | 830 } |
826 | 831 |
827 WebInspector.HeapSnapshotProfileType.TypeId = "HEAP"; | 832 WebInspector.HeapSnapshotProfileType.TypeId = "HEAP"; |
828 WebInspector.HeapSnapshotProfileType.SnapshotReceived = "SnapshotReceived"; | 833 WebInspector.HeapSnapshotProfileType.SnapshotReceived = "SnapshotReceived"; |
829 | 834 |
830 WebInspector.HeapSnapshotProfileType.prototype = { | 835 WebInspector.HeapSnapshotProfileType.prototype = { |
831 /** | 836 /** |
832 * @override | 837 * @override |
833 * @return {string} | 838 * @return {string} |
834 */ | 839 */ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 */ | 901 */ |
897 createProfileLoadedFromFile: function(title) | 902 createProfileLoadedFromFile: function(title) |
898 { | 903 { |
899 return new WebInspector.HeapProfileHeader(this, title); | 904 return new WebInspector.HeapProfileHeader(this, title); |
900 }, | 905 }, |
901 | 906 |
902 _takeHeapSnapshot: function(callback) | 907 _takeHeapSnapshot: function(callback) |
903 { | 908 { |
904 if (this.profileBeingRecorded()) | 909 if (this.profileBeingRecorded()) |
905 return; | 910 return; |
906 this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this, We
bInspector.UIString("Snapshotting\u2026")); | 911 var id = this._nextSnapshotId++; |
| 912 this._profileBeingRecorded = new WebInspector.HeapProfileHeader(this, We
bInspector.UIString("Snapshotting\u2026"), id); |
907 this.addProfile(this._profileBeingRecorded); | 913 this.addProfile(this._profileBeingRecorded); |
908 HeapProfilerAgent.takeHeapSnapshot(true, callback); | 914 /** |
| 915 * @param {?string} error |
| 916 * @this {WebInspector.HeapSnapshotProfileType} |
| 917 */ |
| 918 function didTakeHeapSnapshot(error) |
| 919 { |
| 920 var profile = this._profileBeingRecorded; |
| 921 profile.title = WebInspector.UIString("Snapshot %d", profile.uid); |
| 922 profile._finishLoad(); |
| 923 this._profileBeingRecorded = null; |
| 924 WebInspector.panels.profiles.showProfile(profile); |
| 925 profile.existingView()._refreshView(); |
| 926 callback(); |
| 927 } |
| 928 HeapProfilerAgent.takeHeapSnapshot(true, didTakeHeapSnapshot.bind(this))
; |
909 }, | 929 }, |
910 | 930 |
911 /** | 931 /** |
912 * @param {!HeapProfilerAgent.ProfileHeader} profileHeader | 932 * @param {!HeapProfilerAgent.ProfileHeader} profileHeader |
913 */ | 933 */ |
914 addProfileHeader: function(profileHeader) | 934 addProfileHeader: function(profileHeader) |
915 { | 935 { |
916 var profile = this.profileBeingRecorded(); | 936 var profile = this.profileBeingRecorded(); |
917 if (!profile) | 937 if (!profile) |
918 return; | 938 return; |
(...skipping 11 matching lines...) Expand all Loading... |
930 profile.existingView()._refreshView(); | 950 profile.existingView()._refreshView(); |
931 }, | 951 }, |
932 | 952 |
933 /** | 953 /** |
934 * @override | 954 * @override |
935 * @param {number} uid | 955 * @param {number} uid |
936 * @param {string} chunk | 956 * @param {string} chunk |
937 */ | 957 */ |
938 addHeapSnapshotChunk: function(uid, chunk) | 958 addHeapSnapshotChunk: function(uid, chunk) |
939 { | 959 { |
940 var profile = this.getProfile(uid); | 960 if (!this.profileBeingRecorded()) |
941 if (profile) | 961 return; |
942 profile.transferChunk(chunk); | 962 this.profileBeingRecorded().transferChunk(chunk); |
943 }, | 963 }, |
944 | 964 |
945 /** | 965 /** |
946 * @override | 966 * @override |
947 * @param {number} done | 967 * @param {number} done |
948 * @param {number} total | 968 * @param {number} total |
| 969 * @param {boolean=} finished |
949 */ | 970 */ |
950 reportHeapSnapshotProgress: function(done, total) | 971 reportHeapSnapshotProgress: function(done, total, finished) |
951 { | 972 { |
952 var profile = this.profileBeingRecorded(); | 973 var profile = this.profileBeingRecorded(); |
953 if (!profile) | 974 if (!profile) |
954 return; | 975 return; |
955 profile.sidebarElement.subtitle = WebInspector.UIString("%.0f%", (done /
total) * 100); | 976 profile.sidebarElement.subtitle = WebInspector.UIString("%.0f%", (done /
total) * 100); |
956 profile.sidebarElement.wait = true; | 977 profile.sidebarElement.wait = true; |
| 978 if (finished) |
| 979 profile._prepareToLoad(); |
957 }, | 980 }, |
958 | 981 |
959 /** | 982 /** |
960 * @override | 983 * @override |
961 */ | 984 */ |
962 resetProfiles: function() | 985 resetProfiles: function() |
963 { | 986 { |
964 this._reset(); | 987 this._reset(); |
965 }, | 988 }, |
966 | 989 |
(...skipping 18 matching lines...) Expand all Loading... |
985 __proto__: WebInspector.ProfileType.prototype | 1008 __proto__: WebInspector.ProfileType.prototype |
986 } | 1009 } |
987 | 1010 |
988 | 1011 |
989 /** | 1012 /** |
990 * @constructor | 1013 * @constructor |
991 * @extends {WebInspector.HeapSnapshotProfileType} | 1014 * @extends {WebInspector.HeapSnapshotProfileType} |
992 */ | 1015 */ |
993 WebInspector.TrackingHeapSnapshotProfileType = function() | 1016 WebInspector.TrackingHeapSnapshotProfileType = function() |
994 { | 1017 { |
995 WebInspector.ProfileType.call(this, WebInspector.TrackingHeapSnapshotProfile
Type.TypeId, WebInspector.UIString("Record Heap Allocations")); | 1018 WebInspector.HeapSnapshotProfileType.call(this, WebInspector.TrackingHeapSna
pshotProfileType.TypeId, WebInspector.UIString("Record Heap Allocations")); |
996 WebInspector.HeapProfilerDispatcher._dispatcher.register(this); | |
997 } | 1019 } |
998 | 1020 |
999 WebInspector.TrackingHeapSnapshotProfileType.TypeId = "HEAP-RECORD"; | 1021 WebInspector.TrackingHeapSnapshotProfileType.TypeId = "HEAP-RECORD"; |
1000 | 1022 |
1001 WebInspector.TrackingHeapSnapshotProfileType.HeapStatsUpdate = "HeapStatsUpdate"
; | 1023 WebInspector.TrackingHeapSnapshotProfileType.HeapStatsUpdate = "HeapStatsUpdate"
; |
1002 WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted = "TrackingStarted"
; | 1024 WebInspector.TrackingHeapSnapshotProfileType.TrackingStarted = "TrackingStarted"
; |
1003 WebInspector.TrackingHeapSnapshotProfileType.TrackingStopped = "TrackingStopped"
; | 1025 WebInspector.TrackingHeapSnapshotProfileType.TrackingStopped = "TrackingStopped"
; |
1004 | 1026 |
1005 WebInspector.TrackingHeapSnapshotProfileType.prototype = { | 1027 WebInspector.TrackingHeapSnapshotProfileType.prototype = { |
1006 | 1028 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 }; | 1119 }; |
1098 this._profileBeingRecorded._profileSamples = this._profileSamples; | 1120 this._profileBeingRecorded._profileSamples = this._profileSamples; |
1099 this._recording = true; | 1121 this._recording = true; |
1100 this.addProfile(this._profileBeingRecorded); | 1122 this.addProfile(this._profileBeingRecorded); |
1101 HeapProfilerAgent.startTrackingHeapObjects(); | 1123 HeapProfilerAgent.startTrackingHeapObjects(); |
1102 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy
pe.TrackingStarted); | 1124 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy
pe.TrackingStarted); |
1103 }, | 1125 }, |
1104 | 1126 |
1105 _stopRecordingProfile: function() | 1127 _stopRecordingProfile: function() |
1106 { | 1128 { |
1107 HeapProfilerAgent.stopTrackingHeapObjects(true); | 1129 |
| 1130 var profile = this._profileBeingRecorded; |
| 1131 var title = WebInspector.UIString("Snapshotting\u2026"); |
| 1132 profile.title = title; |
| 1133 profile.sidebarElement.mainTitle = title; |
| 1134 /** |
| 1135 * @param {?string} error |
| 1136 * @this {WebInspector.HeapSnapshotProfileType} |
| 1137 */ |
| 1138 function didTakeHeapSnapshot(error) |
| 1139 { |
| 1140 profile.uid = this._nextSnapshotId++; |
| 1141 var title = WebInspector.UIString("Snapshot %d", profile.uid); |
| 1142 profile.title = title; |
| 1143 profile.sidebarElement.mainTitle = title; |
| 1144 profile._finishLoad(); |
| 1145 this._profileSamples = null; |
| 1146 this._profileBeingRecorded = null; |
| 1147 WebInspector.panels.profiles.showProfile(profile); |
| 1148 profile.existingView()._refreshView(); |
| 1149 } |
| 1150 |
| 1151 HeapProfilerAgent.stopTrackingHeapObjects(true, didTakeHeapSnapshot.bind
(this)); |
1108 this._recording = false; | 1152 this._recording = false; |
1109 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy
pe.TrackingStopped); | 1153 this.dispatchEventToListeners(WebInspector.TrackingHeapSnapshotProfileTy
pe.TrackingStopped); |
1110 }, | 1154 }, |
1111 | 1155 |
1112 _toggleRecording: function() | 1156 _toggleRecording: function() |
1113 { | 1157 { |
1114 if (this._recording) | 1158 if (this._recording) |
1115 this._stopRecordingProfile(); | 1159 this._stopRecordingProfile(); |
1116 else | 1160 else |
1117 this._startRecordingProfile(); | 1161 this._startRecordingProfile(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 * @param {function(!WebInspector.HeapSnapshotProxy):void} callback | 1250 * @param {function(!WebInspector.HeapSnapshotProxy):void} callback |
1207 */ | 1251 */ |
1208 load: function(callback) | 1252 load: function(callback) |
1209 { | 1253 { |
1210 if (this.uid === -1) | 1254 if (this.uid === -1) |
1211 return; | 1255 return; |
1212 if (this._snapshotProxy) { | 1256 if (this._snapshotProxy) { |
1213 callback(this._snapshotProxy); | 1257 callback(this._snapshotProxy); |
1214 return; | 1258 return; |
1215 } | 1259 } |
1216 | |
1217 this._numberOfChunks = 0; | |
1218 if (!this._receiver) { | |
1219 this._setupWorker(); | |
1220 this._transferHandler = new WebInspector.BackendSnapshotLoader(this)
; | |
1221 this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026"
); | |
1222 this.sidebarElement.wait = true; | |
1223 this._transferSnapshot(); | |
1224 } | |
1225 console.assert(this._receiver); | |
1226 this._loadCallbacks.push(callback); | 1260 this._loadCallbacks.push(callback); |
1227 }, | 1261 }, |
1228 | 1262 |
1229 _transferSnapshot: function() | 1263 _prepareToLoad: function() |
1230 { | 1264 { |
1231 /** | 1265 console.assert(!this._receiver, "Already loading"); |
1232 * @this {WebInspector.HeapProfileHeader} | 1266 this._numberOfChunks = 0; |
1233 */ | 1267 this._setupWorker(); |
1234 function finishTransfer() | 1268 this._transferHandler = new WebInspector.BackendSnapshotLoader(this); |
1235 { | 1269 this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026"); |
1236 if (this._transferHandler) { | 1270 this.sidebarElement.wait = true; |
1237 this._transferHandler.finishTransfer(); | 1271 }, |
1238 this._totalNumberOfChunks = this._transferHandler._totalNumberOf
Chunks; | 1272 |
1239 } | 1273 _finishLoad: function() |
1240 if (this._bufferedWriter) { | 1274 { |
1241 this._bufferedWriter.close(this._didWriteToTempFile.bind(this)); | 1275 if (this._transferHandler) { |
1242 this._bufferedWriter = null; | 1276 this._transferHandler.finishTransfer(); |
1243 } | 1277 this._totalNumberOfChunks = this._transferHandler._totalNumberOfChun
ks; |
1244 } | 1278 } |
1245 HeapProfilerAgent.getHeapSnapshot(this.uid, finishTransfer.bind(this)); | 1279 if (this._bufferedWriter) { |
| 1280 this._bufferedWriter.close(this._didWriteToTempFile.bind(this)); |
| 1281 this._bufferedWriter = null; |
| 1282 } |
1246 }, | 1283 }, |
1247 | 1284 |
1248 _didWriteToTempFile: function(tempFile) | 1285 _didWriteToTempFile: function(tempFile) |
1249 { | 1286 { |
1250 this._tempFile = tempFile; | 1287 this._tempFile = tempFile; |
1251 if (!tempFile) | 1288 if (!tempFile) |
1252 this._failedToCreateTempFile = true; | 1289 this._failedToCreateTempFile = true; |
1253 if (this._onTempFileReady) { | 1290 if (this._onTempFileReady) { |
1254 this._onTempFileReady(); | 1291 this._onTempFileReady(); |
1255 this._onTempFileReady = null; | 1292 this._onTempFileReady = null; |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 }, | 1964 }, |
1928 | 1965 |
1929 /** | 1966 /** |
1930 * @return {number} | 1967 * @return {number} |
1931 */ | 1968 */ |
1932 boundarySpan: function() | 1969 boundarySpan: function() |
1933 { | 1970 { |
1934 return this._maximumBoundaries - this._minimumBoundaries; | 1971 return this._maximumBoundaries - this._minimumBoundaries; |
1935 } | 1972 } |
1936 } | 1973 } |
OLD | NEW |