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

Unified Diff: runtime/vm/object_graph.cc

Issue 263803009: Retained size for instance in Observatory. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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
« no previous file with comments | « runtime/vm/object_graph.h ('k') | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object_graph.cc
===================================================================
--- runtime/vm/object_graph.cc (revision 35753)
+++ runtime/vm/object_graph.cc (working copy)
@@ -146,4 +146,64 @@
Unmarker::UnmarkAll(isolate_);
}
+
+class SizeVisitor : public ObjectGraph::Visitor {
+ public:
+ SizeVisitor() : size_(0) { }
+ intptr_t size() const { return size_; }
+ virtual bool ShouldSkip(RawObject* obj) const { return false; }
+ virtual Direction VisitObject(ObjectGraph::StackIterator* it) {
+ RawObject* obj = it->Get();
+ if (ShouldSkip(obj)) {
+ return kBacktrack;
+ }
+ size_ += obj->Size();
+ return kProceed;
+ }
+ private:
+ intptr_t size_;
+};
+
+
+class SizeExcludingObjectVisitor : public SizeVisitor {
+ public:
+ explicit SizeExcludingObjectVisitor(const Object& skip) : skip_(skip) { }
+ virtual bool ShouldSkip(RawObject* obj) const { return obj == skip_.raw(); }
+ private:
+ const Object& skip_;
+};
+
+
+class SizeExcludingClassVisitor : public SizeVisitor {
+ public:
+ explicit SizeExcludingClassVisitor(intptr_t skip) : skip_(skip) { }
+ virtual bool ShouldSkip(RawObject* obj) const {
+ return obj->GetClassId() == skip_;
+ }
+ private:
+ const intptr_t skip_;
+};
+
+
+intptr_t ObjectGraph::SizeRetainedByInstance(const Object& obj) {
+ SizeVisitor total;
+ IterateObjects(&total);
+ intptr_t size_total = total.size();
+ SizeExcludingObjectVisitor excluding_obj(obj);
+ IterateObjects(&excluding_obj);
+ intptr_t size_excluding_obj = excluding_obj.size();
+ return size_total - size_excluding_obj;
+}
+
+
+intptr_t ObjectGraph::SizeRetainedByClass(intptr_t class_id) {
+ SizeVisitor total;
+ IterateObjects(&total);
+ intptr_t size_total = total.size();
+ SizeExcludingClassVisitor excluding_class(class_id);
+ IterateObjects(&excluding_class);
+ intptr_t size_excluding_class = excluding_class.size();
+ return size_total - size_excluding_class;
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/object_graph.h ('k') | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698