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

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

Issue 292663012: Retaining path 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object_graph_test.cc ('k') | no next file » | no next file with comments »
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"
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 return true; 871 return true;
872 } 872 }
873 } 873 }
874 return false; 874 return false;
875 } else { 875 } else {
876 return !obj.IsInstance(); 876 return !obj.IsInstance();
877 } 877 }
878 } 878 }
879 879
880 880
881 // Takes an Object* only because RetainingPath temporarily clears it.
881 static bool HandleInstanceCommands(Isolate* isolate, 882 static bool HandleInstanceCommands(Isolate* isolate,
882 const Object& obj, 883 Object* obj,
883 JSONStream* js, 884 JSONStream* js,
884 intptr_t arg_pos) { 885 intptr_t arg_pos) {
885 ASSERT(js->num_arguments() > arg_pos); 886 ASSERT(js->num_arguments() > arg_pos);
886 const char* action = js->GetArgument(arg_pos); 887 const char* action = js->GetArgument(arg_pos);
887 if (strcmp(action, "eval") == 0) { 888 if (strcmp(action, "eval") == 0) {
888 if (js->num_arguments() > (arg_pos + 1)) { 889 if (js->num_arguments() > (arg_pos + 1)) {
889 PrintError(js, "expected at most %" Pd " arguments but found %" Pd "\n", 890 PrintError(js, "expected at most %" Pd " arguments but found %" Pd "\n",
890 arg_pos + 1, 891 arg_pos + 1,
891 js->num_arguments()); 892 js->num_arguments());
892 return true; 893 return true;
893 } 894 }
894 if (obj.IsNull()) { 895 if (obj->IsNull()) {
895 PrintErrorWithKind(js, "EvalCollected", 896 PrintErrorWithKind(js, "EvalCollected",
896 "attempt to evaluate against collected object\n", 897 "attempt to evaluate against collected object\n",
897 js->num_arguments()); 898 js->num_arguments());
898 return true; 899 return true;
899 } 900 }
900 if (obj.raw() == Object::sentinel().raw()) { 901 if (obj->raw() == Object::sentinel().raw()) {
901 PrintErrorWithKind(js, "EvalExpired", 902 PrintErrorWithKind(js, "EvalExpired",
902 "attempt to evaluate against expired object\n", 903 "attempt to evaluate against expired object\n",
903 js->num_arguments()); 904 js->num_arguments());
904 return true; 905 return true;
905 } 906 }
906 if (ContainsNonInstance(obj)) { 907 if (ContainsNonInstance(*obj)) {
907 PrintError(js, "attempt to evaluate against internal VM object\n"); 908 PrintError(js, "attempt to evaluate against internal VM object\n");
908 return true; 909 return true;
909 } 910 }
910 const char* expr = js->LookupOption("expr"); 911 const char* expr = js->LookupOption("expr");
911 if (expr == NULL) { 912 if (expr == NULL) {
912 PrintError(js, "eval expects an 'expr' option\n", 913 PrintError(js, "eval expects an 'expr' option\n",
913 js->num_arguments()); 914 js->num_arguments());
914 return true; 915 return true;
915 } 916 }
916 const String& expr_str = String::Handle(isolate, String::New(expr)); 917 const String& expr_str = String::Handle(isolate, String::New(expr));
917 ASSERT(obj.IsInstance()); 918 ASSERT(obj->IsInstance());
918 const Instance& instance = Instance::Cast(obj); 919 const Instance& instance = Instance::Cast(*obj);
919 const Object& result = 920 const Object& result =
920 Object::Handle(instance.Evaluate(expr_str, 921 Object::Handle(instance.Evaluate(expr_str,
921 Array::empty_array(), 922 Array::empty_array(),
922 Array::empty_array())); 923 Array::empty_array()));
923 result.PrintJSON(js, true); 924 result.PrintJSON(js, true);
924 return true; 925 return true;
925 } else if (strcmp(action, "retained") == 0) { 926 } else if (strcmp(action, "retained") == 0) {
926 ObjectGraph graph(isolate); 927 ObjectGraph graph(isolate);
927 intptr_t retained_size = graph.SizeRetainedByInstance(obj); 928 intptr_t retained_size = graph.SizeRetainedByInstance(*obj);
928 const Object& result = Object::Handle(Integer::New(retained_size)); 929 const Object& result = Object::Handle(Integer::New(retained_size));
929 result.PrintJSON(js, true); 930 result.PrintJSON(js, true);
930 return true; 931 return true;
932 } else if (strcmp(action, "retaining_path") == 0) {
933 intptr_t limit;
Cutch 2014/05/22 03:10:12 Add a service test success and failure cases.
koda 2014/05/22 17:27:47 Done.
934 if (!GetIntegerId(js->LookupOption("limit"), &limit)) {
935 PrintError(js, "retaining_path expects a 'limit' option\n",
936 js->num_arguments());
Cutch 2014/05/22 03:10:12 return true;
koda 2014/05/22 17:27:47 Done.
937 }
938 ObjectGraph graph(isolate);
939 Array& path = Array::Handle(Array::New(limit));
940 intptr_t length = graph.RetainingPath(obj, path);
941 JSONObject jsobj(js);
942 jsobj.AddProperty("type", "RetainingPath");
943 jsobj.AddProperty("id", "retaining_path");
944 jsobj.AddProperty("length", length);
945 JSONArray elements(&jsobj, "elements");
946 for (intptr_t i = 0; i < path.Length() && i < length; ++i) {
947 JSONObject jselement(&elements);
948 Object& element = Object::Handle();
949 element = path.At(i);
950 jselement.AddProperty("index", i);
951 jselement.AddProperty("value", element);
952 }
953 return true;
931 } 954 }
932 955
933 PrintError(js, "unrecognized action '%s'\n", action); 956 PrintError(js, "unrecognized action '%s'\n", action);
934 return true; 957 return true;
935 } 958 }
936 959
937 960
938 static bool HandleClassesClosures(Isolate* isolate, const Class& cls, 961 static bool HandleClassesClosures(Isolate* isolate, const Class& cls,
939 JSONStream* js) { 962 JSONStream* js) {
940 intptr_t id; 963 intptr_t id;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 Type& type = Type::Handle(); 1111 Type& type = Type::Handle();
1089 type ^= cls.CanonicalTypeFromIndex(id); 1112 type ^= cls.CanonicalTypeFromIndex(id);
1090 if (type.IsNull()) { 1113 if (type.IsNull()) {
1091 PrintError(js, "Canonical type %" Pd " not found", id); 1114 PrintError(js, "Canonical type %" Pd " not found", id);
1092 return true; 1115 return true;
1093 } 1116 }
1094 if (js->num_arguments() == 4) { 1117 if (js->num_arguments() == 4) {
1095 type.PrintJSON(js, false); 1118 type.PrintJSON(js, false);
1096 return true; 1119 return true;
1097 } 1120 }
1098 return HandleInstanceCommands(isolate, type, js, 4); 1121 return HandleInstanceCommands(isolate, &type, js, 4);
1099 } 1122 }
1100 1123
1101 1124
1102 static bool HandleClassesRetained(Isolate* isolate, const Class& cls, 1125 static bool HandleClassesRetained(Isolate* isolate, const Class& cls,
1103 JSONStream* js) { 1126 JSONStream* js) {
1104 if (js->num_arguments() != 3) { 1127 if (js->num_arguments() != 3) {
1105 PrintError(js, "Command too long"); 1128 PrintError(js, "Command too long");
1106 return true; 1129 return true;
1107 } 1130 }
1108 ObjectGraph graph(isolate); 1131 ObjectGraph graph(isolate);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 PrintPseudoNull(js, "objects/collected", "<collected>"); 1360 PrintPseudoNull(js, "objects/collected", "<collected>");
1338 return true; 1361 return true;
1339 } else if (obj.raw() == Object::sentinel().raw()) { 1362 } else if (obj.raw() == Object::sentinel().raw()) {
1340 // The object id has expired. 1363 // The object id has expired.
1341 PrintPseudoNull(js, "objects/expired", "<expired>"); 1364 PrintPseudoNull(js, "objects/expired", "<expired>");
1342 return true; 1365 return true;
1343 } 1366 }
1344 obj.PrintJSON(js, false); 1367 obj.PrintJSON(js, false);
1345 return true; 1368 return true;
1346 } 1369 }
1347 return HandleInstanceCommands(isolate, obj, js, 2); 1370 return HandleInstanceCommands(isolate, &obj, js, 2);
1348 } 1371 }
1349 1372
1350 1373
1351 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) { 1374 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) {
1352 JSONObject jsobj(js); 1375 JSONObject jsobj(js);
1353 jsobj.AddProperty("type", "ScriptList"); 1376 jsobj.AddProperty("type", "ScriptList");
1354 jsobj.AddProperty("id", "scripts"); 1377 jsobj.AddProperty("id", "scripts");
1355 JSONArray members(&jsobj, "members"); 1378 JSONArray members(&jsobj, "members");
1356 const GrowableObjectArray& libs = 1379 const GrowableObjectArray& libs =
1357 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 1380 GrowableObjectArray::Handle(isolate->object_store()->libraries());
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 while (current != NULL) { 2066 while (current != NULL) {
2044 if (strcmp(name, current->name()) == 0) { 2067 if (strcmp(name, current->name()) == 0) {
2045 return current; 2068 return current;
2046 } 2069 }
2047 current = current->next(); 2070 current = current->next();
2048 } 2071 }
2049 return NULL; 2072 return NULL;
2050 } 2073 }
2051 2074
2052 } // namespace dart 2075 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_graph_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698