Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: runtime/vm/heap_histogram.cc

Issue 23875015: - Base JSON stream printing on stack objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/heap_histogram.cc
===================================================================
--- runtime/vm/heap_histogram.cc (revision 27302)
+++ runtime/vm/heap_histogram.cc (working copy)
@@ -158,44 +158,47 @@
intptr_t size_sum = 0;
intptr_t count_sum = 0;
- stream->OpenObject();
- stream->PrintProperty("type", "ObjectHistogram");
- stream->OpenArray("properties");
- stream->PrintValue("size");
- stream->PrintValue("count");
- stream->CloseArray();
- stream->OpenArray("members");
- for (intptr_t pos = 0; pos < length; pos++) {
- Element* e = array[pos];
- if (e->count_ > 0) {
- cls = isolate_->class_table()->At(e->class_id_);
- str = cls.Name();
- lib = cls.library();
- stream->OpenObject();
- stream->PrintProperty("type", "ObjectHistogramEntry");
- // It should not be possible to overflow here because the total
- // size of the heap is bounded and we are dividing the value
- // by the number of major gcs that have occurred.
- size_sum += (e->size_ / major_gc_count_);
- count_sum += (e->count_ / major_gc_count_);
- stream->PrintProperty("size", e->size_ / major_gc_count_);
- stream->PrintProperty("count", e->count_ / major_gc_count_);
- stream->PrintProperty("name", str.ToCString());
- if (lib.IsNull()) {
- stream->PrintProperty("category", "");
- } else {
- str = lib.url();
- stream->PrintProperty("category", str.ToCString());
+ JSONObject jsobj(stream);
+ jsobj.AddProperty("type", "ObjectHistogram");
+ { // TODO(johnmccutchan): Why is this empty array needed here?
+ JSONArray jsarr(jsobj, "properties");
+ jsarr.AddValue("size");
+ jsarr.AddValue("count");
Cutch 2013/09/09 18:35:39 Because of how web_ui <template> tags are executed
Ivan Posva 2013/09/10 17:21:31 Thanks for the explanation. Will this change with
Cutch 2013/09/10 17:49:03 Not sure yet. Polymer looks like it's going to req
+ }
+ {
+ JSONArray jsarr(jsobj, "members");
+ for (intptr_t pos = 0; pos < length; pos++) {
+ Element* e = array[pos];
+ if (e->count_ > 0) {
+ cls = isolate_->class_table()->At(e->class_id_);
+ str = cls.Name();
+ lib = cls.library();
+ JSONObject jsobj(jsarr);
+ jsobj.AddProperty("type", "ObjectHistogramEntry");
+ // It should not be possible to overflow here because the total
+ // size of the heap is bounded and we are dividing the value
+ // by the number of major gcs that have occurred.
+ size_sum += (e->size_ / major_gc_count_);
+ count_sum += (e->count_ / major_gc_count_);
+ jsobj.AddProperty("size", e->size_ / major_gc_count_);
+ jsobj.AddProperty("count", e->count_ / major_gc_count_);
+ jsobj.AddProperty("name", str.ToCString());
+ if (lib.IsNull()) {
+ jsobj.AddProperty("category", "");
+ } else {
+ // TODO(johnmccutchan): Shouldn't the code below just do:
+ // jsobj.AddProperty("category", lib);
Cutch 2013/09/09 18:35:39 Yes, and the class above too (instead of printing
Ivan Posva 2013/09/10 17:21:31 Done. But left the old code in so that the UI does
+ // This would allow us to put a proper reference to the library into
+ // the UI.
+ str = lib.url();
+ jsobj.AddProperty("category", str.ToCString());
+ }
}
- stream->CloseObject();
}
}
- stream->CloseArray();
- stream->OpenObject("sums");
- stream->PrintProperty("size", size_sum);
- stream->PrintProperty("count", count_sum);
- stream->CloseObject();
- stream->CloseObject();
+ JSONObject jsobj1(jsobj, "sums");
siva 2013/09/09 22:45:26 I would name this as aggregate_jsobj and some othe
Ivan Posva 2013/09/10 17:21:31 Done.
+ jsobj1.AddProperty("size", size_sum);
+ jsobj1.AddProperty("count", count_sum);
// Deallocate the array for sorting.
free(array);

Powered by Google App Engine
This is Rietveld 408576698