OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/heap_histogram.h" | 5 #include "vm/heap_histogram.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/json_stream.h" | 10 #include "vm/json_stream.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Finally print the sorted array. | 154 // Finally print the sorted array. |
155 Class& cls = Class::Handle(); | 155 Class& cls = Class::Handle(); |
156 String& str = String::Handle(); | 156 String& str = String::Handle(); |
157 Library& lib = Library::Handle(); | 157 Library& lib = Library::Handle(); |
158 | 158 |
159 intptr_t size_sum = 0; | 159 intptr_t size_sum = 0; |
160 intptr_t count_sum = 0; | 160 intptr_t count_sum = 0; |
161 JSONObject jsobj(stream); | 161 JSONObject jsobj(stream); |
162 jsobj.AddProperty("type", "ObjectHistogram"); | 162 jsobj.AddProperty("type", "ObjectHistogram"); |
163 { // TODO(johnmccutchan): Why is this empty array needed here? | 163 { // TODO(johnmccutchan): Why is this empty array needed here? |
164 JSONArray jsarr(jsobj, "properties"); | 164 JSONArray jsarr(&jsobj, "properties"); |
165 jsarr.AddValue("size"); | 165 jsarr.AddValue("size"); |
166 jsarr.AddValue("count"); | 166 jsarr.AddValue("count"); |
167 } | 167 } |
168 { | 168 { |
169 JSONArray jsarr(jsobj, "members"); | 169 JSONArray jsarr(&jsobj, "members"); |
170 for (intptr_t pos = 0; pos < length; pos++) { | 170 for (intptr_t pos = 0; pos < length; pos++) { |
171 Element* e = array[pos]; | 171 Element* e = array[pos]; |
172 if (e->count_ > 0) { | 172 if (e->count_ > 0) { |
173 cls = isolate_->class_table()->At(e->class_id_); | 173 cls = isolate_->class_table()->At(e->class_id_); |
174 str = cls.Name(); | 174 str = cls.Name(); |
175 lib = cls.library(); | 175 lib = cls.library(); |
176 JSONObject jsobj(jsarr); | 176 JSONObject jsobj(&jsarr); |
177 jsobj.AddProperty("type", "ObjectHistogramEntry"); | 177 jsobj.AddProperty("type", "ObjectHistogramEntry"); |
178 // It should not be possible to overflow here because the total | 178 // It should not be possible to overflow here because the total |
179 // size of the heap is bounded and we are dividing the value | 179 // size of the heap is bounded and we are dividing the value |
180 // by the number of major gcs that have occurred. | 180 // by the number of major gcs that have occurred. |
181 size_sum += (e->size_ / major_gc_count_); | 181 size_sum += (e->size_ / major_gc_count_); |
182 count_sum += (e->count_ / major_gc_count_); | 182 count_sum += (e->count_ / major_gc_count_); |
183 jsobj.AddProperty("size", e->size_ / major_gc_count_); | 183 jsobj.AddProperty("size", e->size_ / major_gc_count_); |
184 jsobj.AddProperty("count", e->count_ / major_gc_count_); | 184 jsobj.AddProperty("count", e->count_ / major_gc_count_); |
185 jsobj.AddProperty("class", cls, true); | 185 jsobj.AddProperty("class", cls, true); |
186 jsobj.AddProperty("lib", lib, true); | 186 jsobj.AddProperty("lib", lib, true); |
187 // TODO(johnmccutchan): Update the UI to use the class and lib object | 187 // TODO(johnmccutchan): Update the UI to use the class and lib object |
188 // properties above instead of name and category strings. | 188 // properties above instead of name and category strings. |
189 jsobj.AddProperty("name", str.ToCString()); | 189 jsobj.AddProperty("name", str.ToCString()); |
190 if (lib.IsNull()) { | 190 if (lib.IsNull()) { |
191 jsobj.AddProperty("category", ""); | 191 jsobj.AddProperty("category", ""); |
192 } else { | 192 } else { |
193 str = lib.url(); | 193 str = lib.url(); |
194 jsobj.AddProperty("category", str.ToCString()); | 194 jsobj.AddProperty("category", str.ToCString()); |
195 } | 195 } |
196 } | 196 } |
197 } | 197 } |
198 } | 198 } |
199 JSONObject sums(jsobj, "sums"); | 199 JSONObject sums(&jsobj, "sums"); |
200 sums.AddProperty("size", size_sum); | 200 sums.AddProperty("size", size_sum); |
201 sums.AddProperty("count", count_sum); | 201 sums.AddProperty("count", count_sum); |
202 | 202 |
203 // Deallocate the array for sorting. | 203 // Deallocate the array for sorting. |
204 free(array); | 204 free(array); |
205 } | 205 } |
206 | 206 |
207 | 207 |
208 } // namespace dart | 208 } // namespace dart |
OLD | NEW |