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

Side by Side Diff: runtime/vm/service.cc

Issue 340673002: VM service: List all instances of a class. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/service_test.cc » ('j') | runtime/vm/service_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
11 #include "vm/coverage.h" 11 #include "vm/coverage.h"
12 #include "vm/cpu.h" 12 #include "vm/cpu.h"
13 #include "vm/dart_api_impl.h" 13 #include "vm/dart_api_impl.h"
14 #include "vm/dart_entry.h" 14 #include "vm/dart_entry.h"
15 #include "vm/debugger.h" 15 #include "vm/debugger.h"
16 #include "vm/isolate.h" 16 #include "vm/isolate.h"
17 #include "vm/message.h" 17 #include "vm/message.h"
18 #include "vm/message_handler.h" 18 #include "vm/message_handler.h"
19 #include "vm/native_entry.h" 19 #include "vm/native_entry.h"
20 #include "vm/native_arguments.h" 20 #include "vm/native_arguments.h"
21 #include "vm/object.h" 21 #include "vm/object.h"
22 #include "vm/object_graph.h" 22 #include "vm/object_graph.h"
23 #include "vm/object_id_ring.h" 23 #include "vm/object_id_ring.h"
24 #include "vm/object_store.h" 24 #include "vm/object_store.h"
25 #include "vm/port.h" 25 #include "vm/port.h"
26 #include "vm/profiler.h" 26 #include "vm/profiler.h"
27 #include "vm/reusable_handles.h"
27 #include "vm/stack_frame.h" 28 #include "vm/stack_frame.h"
28 #include "vm/symbols.h" 29 #include "vm/symbols.h"
29 #include "vm/version.h" 30 #include "vm/version.h"
30 31
31 32
32 namespace dart { 33 namespace dart {
33 34
34 DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests."); 35 DEFINE_FLAG(bool, trace_service, false, "Trace VM service requests.");
35 DEFINE_FLAG(bool, trace_service_pause_events, false, 36 DEFINE_FLAG(bool, trace_service_pause_events, false,
36 "Trace VM service isolate pause events."); 37 "Trace VM service isolate pause events.");
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 return true; 1131 return true;
1131 } 1132 }
1132 ObjectGraph graph(isolate); 1133 ObjectGraph graph(isolate);
1133 intptr_t retained_size = graph.SizeRetainedByClass(cls.id()); 1134 intptr_t retained_size = graph.SizeRetainedByClass(cls.id());
1134 const Object& result = Object::Handle(Integer::New(retained_size)); 1135 const Object& result = Object::Handle(Integer::New(retained_size));
1135 result.PrintJSON(js, true); 1136 result.PrintJSON(js, true);
1136 return true; 1137 return true;
1137 } 1138 }
1138 1139
1139 1140
1141 class GetInstancesVisitor : public ObjectVisitor {
1142 public:
1143 GetInstancesVisitor(Isolate* isolate, const Class& cls, const Array& storage)
1144 : ObjectVisitor(isolate), cls_(cls), storage_(storage), count_(0) {}
1145
1146 virtual void VisitObject(RawObject* raw_obj) {
1147 if (raw_obj->IsFreeListElement()) {
1148 return;
1149 }
1150 REUSABLE_OBJECT_HANDLESCOPE(isolate());
1151 Object& obj = isolate()->ObjectHandle();
1152 obj = raw_obj;
1153 if (obj.GetClassId() == cls_.id()) {
1154 if (!storage_.IsNull() && count_ < storage_.Length()) {
1155 storage_.SetAt(count_, obj);
1156 }
1157 ++count_;
1158 }
1159 }
1160
1161 intptr_t count() const { return count_; }
1162
1163 private:
1164 const Class& cls_;
1165 const Array& storage_;
1166 intptr_t count_;
1167 };
1168
1169
1170 static bool HandleClassesInstances(Isolate* isolate, const Class& cls,
1171 JSONStream* js) {
1172 if (js->num_arguments() != 3) {
1173 PrintError(js, "Command too long");
1174 return true;
1175 }
1176 intptr_t limit;
1177 if (!GetIntegerId(js->LookupOption("limit"), &limit)) {
1178 PrintError(js, "instances expects a 'limit' option\n",
1179 js->num_arguments());
1180 return true;
1181 }
1182 Array& storage = Array::Handle(Array::New(limit));
1183 GetInstancesVisitor visitor(isolate, cls, storage);
1184 isolate->heap()->IterateObjects(&visitor);
1185 intptr_t count = visitor.count();
1186 if (count < limit) {
1187 // Truncate the list using utility method for GrowableObjectArray.
1188 GrowableObjectArray& wrapper = GrowableObjectArray::Handle(
1189 GrowableObjectArray::New(storage));
1190 wrapper.SetLength(count);
1191 storage = Array::MakeArray(wrapper);
1192 }
1193 storage.PrintJSON(js, true);
1194 return true;
1195 }
1196
1197
1140 static bool HandleClasses(Isolate* isolate, JSONStream* js) { 1198 static bool HandleClasses(Isolate* isolate, JSONStream* js) {
1141 if (js->num_arguments() == 1) { 1199 if (js->num_arguments() == 1) {
1142 ClassTable* table = isolate->class_table(); 1200 ClassTable* table = isolate->class_table();
1143 JSONObject jsobj(js); 1201 JSONObject jsobj(js);
1144 table->PrintToJSONObject(&jsobj); 1202 table->PrintToJSONObject(&jsobj);
1145 return true; 1203 return true;
1146 } 1204 }
1147 ASSERT(js->num_arguments() >= 2); 1205 ASSERT(js->num_arguments() >= 2);
1148 intptr_t id; 1206 intptr_t id;
1149 if (!GetIntegerId(js->GetArgument(1), &id)) { 1207 if (!GetIntegerId(js->GetArgument(1), &id)) {
(...skipping 16 matching lines...) Expand all
1166 } else if (strcmp(second, "closures") == 0) { 1224 } else if (strcmp(second, "closures") == 0) {
1167 return HandleClassesClosures(isolate, cls, js); 1225 return HandleClassesClosures(isolate, cls, js);
1168 } else if (strcmp(second, "fields") == 0) { 1226 } else if (strcmp(second, "fields") == 0) {
1169 return HandleClassesFields(isolate, cls, js); 1227 return HandleClassesFields(isolate, cls, js);
1170 } else if (strcmp(second, "functions") == 0) { 1228 } else if (strcmp(second, "functions") == 0) {
1171 return HandleClassesFunctions(isolate, cls, js); 1229 return HandleClassesFunctions(isolate, cls, js);
1172 } else if (strcmp(second, "implicit_closures") == 0) { 1230 } else if (strcmp(second, "implicit_closures") == 0) {
1173 return HandleClassesImplicitClosures(isolate, cls, js); 1231 return HandleClassesImplicitClosures(isolate, cls, js);
1174 } else if (strcmp(second, "dispatchers") == 0) { 1232 } else if (strcmp(second, "dispatchers") == 0) {
1175 return HandleClassesDispatchers(isolate, cls, js); 1233 return HandleClassesDispatchers(isolate, cls, js);
1176 } else if (!strcmp(second, "types")) { 1234 } else if (strcmp(second, "types") == 0) {
1177 return HandleClassesTypes(isolate, cls, js); 1235 return HandleClassesTypes(isolate, cls, js);
1178 } else if (!strcmp(second, "retained")) { 1236 } else if (strcmp(second, "retained") == 0) {
1179 return HandleClassesRetained(isolate, cls, js); 1237 return HandleClassesRetained(isolate, cls, js);
1238 } else if (strcmp(second, "instances") == 0) {
1239 return HandleClassesInstances(isolate, cls, js);
1180 } else { 1240 } else {
1181 PrintError(js, "Invalid sub collection %s", second); 1241 PrintError(js, "Invalid sub collection %s", second);
1182 return true; 1242 return true;
1183 } 1243 }
1184 } 1244 }
1185 UNREACHABLE(); 1245 UNREACHABLE();
1186 return true; 1246 return true;
1187 } 1247 }
1188 1248
1189 1249
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 while (current != NULL) { 2166 while (current != NULL) {
2107 if (strcmp(name, current->name()) == 0) { 2167 if (strcmp(name, current->name()) == 0) {
2108 return current; 2168 return current;
2109 } 2169 }
2110 current = current->next(); 2170 current = current->next();
2111 } 2171 }
2112 return NULL; 2172 return NULL;
2113 } 2173 }
2114 2174
2115 } // namespace dart 2175 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/service_test.cc » ('j') | runtime/vm/service_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698