| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 array = GetSortedArray(&length); | 151 array = GetSortedArray(&length); |
| 152 ASSERT(array != NULL); | 152 ASSERT(array != NULL); |
| 153 | 153 |
| 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 stream->OpenObject(); | 161 JSONObject jsobj(stream); |
| 162 stream->PrintProperty("type", "ObjectHistogram"); | 162 jsobj.AddProperty("type", "ObjectHistogram"); |
| 163 stream->OpenArray("properties"); | 163 { // TODO(johnmccutchan): Why is this empty array needed here? |
| 164 stream->PrintValue("size"); | 164 JSONArray jsarr(jsobj, "properties"); |
| 165 stream->PrintValue("count"); | 165 jsarr.AddValue("size"); |
| 166 stream->CloseArray(); | 166 jsarr.AddValue("count"); |
| 167 stream->OpenArray("members"); | 167 } |
| 168 for (intptr_t pos = 0; pos < length; pos++) { | 168 { |
| 169 Element* e = array[pos]; | 169 JSONArray jsarr(jsobj, "members"); |
| 170 if (e->count_ > 0) { | 170 for (intptr_t pos = 0; pos < length; pos++) { |
| 171 cls = isolate_->class_table()->At(e->class_id_); | 171 Element* e = array[pos]; |
| 172 str = cls.Name(); | 172 if (e->count_ > 0) { |
| 173 lib = cls.library(); | 173 cls = isolate_->class_table()->At(e->class_id_); |
| 174 stream->OpenObject(); | 174 str = cls.Name(); |
| 175 stream->PrintProperty("type", "ObjectHistogramEntry"); | 175 lib = cls.library(); |
| 176 // It should not be possible to overflow here because the total | 176 JSONObject jsobj(jsarr); |
| 177 // size of the heap is bounded and we are dividing the value | 177 jsobj.AddProperty("type", "ObjectHistogramEntry"); |
| 178 // by the number of major gcs that have occurred. | 178 // It should not be possible to overflow here because the total |
| 179 size_sum += (e->size_ / major_gc_count_); | 179 // size of the heap is bounded and we are dividing the value |
| 180 count_sum += (e->count_ / major_gc_count_); | 180 // by the number of major gcs that have occurred. |
| 181 stream->PrintProperty("size", e->size_ / major_gc_count_); | 181 size_sum += (e->size_ / major_gc_count_); |
| 182 stream->PrintProperty("count", e->count_ / major_gc_count_); | 182 count_sum += (e->count_ / major_gc_count_); |
| 183 stream->PrintProperty("name", str.ToCString()); | 183 jsobj.AddProperty("size", e->size_ / major_gc_count_); |
| 184 if (lib.IsNull()) { | 184 jsobj.AddProperty("count", e->count_ / major_gc_count_); |
| 185 stream->PrintProperty("category", ""); | 185 jsobj.AddProperty("class", cls, true); |
| 186 } else { | 186 jsobj.AddProperty("lib", lib, true); |
| 187 str = lib.url(); | 187 // TODO(johnmccutchan): Update the UI to use the class and lib object |
| 188 stream->PrintProperty("category", str.ToCString()); | 188 // properties above instead of name and category strings. |
| 189 jsobj.AddProperty("name", str.ToCString()); |
| 190 if (lib.IsNull()) { |
| 191 jsobj.AddProperty("category", ""); |
| 192 } else { |
| 193 str = lib.url(); |
| 194 jsobj.AddProperty("category", str.ToCString()); |
| 195 } |
| 189 } | 196 } |
| 190 stream->CloseObject(); | |
| 191 } | 197 } |
| 192 } | 198 } |
| 193 stream->CloseArray(); | 199 JSONObject sums(jsobj, "sums"); |
| 194 stream->OpenObject("sums"); | 200 sums.AddProperty("size", size_sum); |
| 195 stream->PrintProperty("size", size_sum); | 201 sums.AddProperty("count", count_sum); |
| 196 stream->PrintProperty("count", count_sum); | |
| 197 stream->CloseObject(); | |
| 198 stream->CloseObject(); | |
| 199 | 202 |
| 200 // Deallocate the array for sorting. | 203 // Deallocate the array for sorting. |
| 201 free(array); | 204 free(array); |
| 202 } | 205 } |
| 203 | 206 |
| 204 | 207 |
| 205 } // namespace dart | 208 } // namespace dart |
| OLD | NEW |