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

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

Issue 194623006: Improve the instance-view page in observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: gen js / fix stuff Created 6 years, 9 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.cc ('k') | runtime/vm/service_test.cc » ('j') | 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 8
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/coverage.h" 10 #include "vm/coverage.h"
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 static void PrintPseudoNull(JSONStream* js, 888 static void PrintPseudoNull(JSONStream* js,
889 const char* id, 889 const char* id,
890 const char* preview) { 890 const char* preview) {
891 JSONObject jsobj(js); 891 JSONObject jsobj(js);
892 jsobj.AddProperty("type", "Null"); 892 jsobj.AddProperty("type", "Null");
893 jsobj.AddProperty("id", id); 893 jsobj.AddProperty("id", id);
894 jsobj.AddProperty("preview", preview); 894 jsobj.AddProperty("preview", preview);
895 } 895 }
896 896
897 897
898 static bool HandleObjects(Isolate* isolate, JSONStream* js) { 898 static RawObject* LookupObjectId(Isolate* isolate,
899 REQUIRE_COLLECTION_ID("objects"); 899 const char* arg,
900 ASSERT(js->num_arguments() >= 2); 900 bool* error) {
901 const char* arg = js->GetArgument(1); 901 *error = false;
902 902 if (strncmp(arg, "int-", 4) == 0) {
903 // TODO(turnidge): Handle <optimized out> the same way as other 903 arg += 4;
904 // special nulls.
905 if (strcmp(arg, "null") == 0) {
906 Object::null_object().PrintToJSONStream(js, false);
907 return true;
908
909 } else if (strcmp(arg, "not-initialized") == 0) {
910 Object::sentinel().PrintToJSONStream(js, false);
911 return true;
912
913 } else if (strcmp(arg, "being-initialized") == 0) {
914 Object::transition_sentinel().PrintToJSONStream(js, false);
915 return true;
916
917 } else if (strcmp(arg, "optimized-out") == 0) {
918 Symbols::OptimizedOut().PrintToJSONStream(js, false);
919 return true;
920
921 } else if (strcmp(arg, "collected") == 0) {
922 PrintPseudoNull(js, "objects/collected", "<collected>");
923 return true;
924
925 } else if (strcmp(arg, "expired") == 0) {
926 PrintPseudoNull(js, "objects/expired", "<expired>");
927 return true;
928
929 } else if (strcmp(arg, "int") == 0) {
930 if (js->num_arguments() < 3) {
931 PrintError(js, "expected 3 arguments but found %" Pd "\n",
932 js->num_arguments());
933 return true;
934 }
935 int64_t value = 0; 904 int64_t value = 0;
936 if (!OS::StringToInt64(js->GetArgument(2), &value) || 905 if (!OS::StringToInt64(arg, &value) ||
937 !Smi::IsValid64(value)) { 906 !Smi::IsValid64(value)) {
938 PrintError(js, "integer value too large\n", 907 *error = true;
939 js->num_arguments()); 908 return Object::null();
940 return true;
941 } 909 }
942 const Integer& obj = 910 const Integer& obj =
943 Integer::Handle(isolate, Smi::New(static_cast<intptr_t>(value))); 911 Integer::Handle(isolate, Smi::New(static_cast<intptr_t>(value)));
944 obj.PrintToJSONStream(js, false); 912 return obj.raw();
945 return true;
946 913
947 } else if (strcmp(arg, "bool") == 0) { 914 } else if (strcmp(arg, "bool-true") == 0) {
948 if (js->num_arguments() < 3) { 915 return Bool::True().raw();
949 PrintError(js, "expected 3 arguments but found %" Pd "\n", 916
950 js->num_arguments()); 917 } else if (strcmp(arg, "bool-false") == 0) {
951 return true; 918 return Bool::False().raw();
952 }
953 const char* value_str = js->GetArgument(2);
954 bool value = false;
955 if (strcmp(value_str, "false") == 0) {
956 value = false;
957 } else if (strcmp(value_str, "true") == 0) {
958 value = true;
959 } else {
960 PrintError(js, "expected 'true' or 'false' but found %s\n", value_str);
961 return true;
962 }
963 Bool::Get(value).PrintToJSONStream(js, false);
964 return true;
965 } 919 }
966 920
967 ObjectIdRing* ring = isolate->object_id_ring(); 921 ObjectIdRing* ring = isolate->object_id_ring();
968 ASSERT(ring != NULL); 922 ASSERT(ring != NULL);
969 intptr_t id = -1; 923 intptr_t id = -1;
970 if (!GetIntegerId(arg, &id)) { 924 if (!GetIntegerId(arg, &id)) {
971 Object::null_object().PrintToJSONStream(js, false); 925 *error = true;
926 return Instance::null();
927 }
928 return ring->GetObjectForId(id);
929 }
930
931
932 static bool HandleObjects(Isolate* isolate, JSONStream* js) {
933 REQUIRE_COLLECTION_ID("objects");
934 if (js->num_arguments() < 2) {
935 PrintError(js, "expected at least 2 arguments but found %" Pd "\n",
936 js->num_arguments());
972 return true; 937 return true;
973 } 938 }
974 Object& obj = Object::Handle(ring->GetObjectForId(id)); 939 const char* arg = js->GetArgument(1);
975 if (obj.IsNull()) { 940
976 // The object has been collected by the gc. 941 // Handle special objects first.
977 PrintPseudoNull(js, "objects/collected", "<collected>"); 942 if (strcmp(arg, "null") == 0) {
943 if (js->num_arguments() > 2) {
944 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
945 js->num_arguments());
946 } else {
947 Instance::null_instance().PrintToJSONStream(js, false);
948 }
978 return true; 949 return true;
979 } else if (obj.raw() == Object::sentinel().raw()) { 950
980 // The object id has expired. 951 } else if (strcmp(arg, "not-initialized") == 0) {
981 PrintPseudoNull(js, "objects/expired", "<expired>"); 952 if (js->num_arguments() > 2) {
953 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
954 js->num_arguments());
955 } else {
956 Object::sentinel().PrintToJSONStream(js, false);
957 }
958 return true;
959
960 } else if (strcmp(arg, "being-initialized") == 0) {
961 if (js->num_arguments() > 2) {
962 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
963 js->num_arguments());
964 } else {
965 Object::transition_sentinel().PrintToJSONStream(js, false);
966 }
967 return true;
968
969 } else if (strcmp(arg, "optimized-out") == 0) {
970 if (js->num_arguments() > 2) {
971 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
972 js->num_arguments());
973 } else {
974 Symbols::OptimizedOut().PrintToJSONStream(js, false);
975 }
976 return true;
977
978 } else if (strcmp(arg, "collected") == 0) {
979 if (js->num_arguments() > 2) {
980 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
981 js->num_arguments());
982 } else {
983 PrintPseudoNull(js, "objects/collected", "<collected>");
984 }
985 return true;
986
987 } else if (strcmp(arg, "expired") == 0) {
988 if (js->num_arguments() > 2) {
989 PrintError(js, "expected at most 2 arguments but found %" Pd "\n",
990 js->num_arguments());
991 } else {
992 PrintPseudoNull(js, "objects/expired", "<expired>");
993 }
982 return true; 994 return true;
983 } 995 }
984 obj.PrintToJSONStream(js, false); 996
997 // Lookup the object.
998 Object& obj = Object::Handle(isolate);
999 bool error = false;
1000 obj = LookupObjectId(isolate, arg, &error);
1001 if (error) {
1002 PrintError(js, "unrecognized object id '%s'", arg);
1003 return true;
1004 }
1005
1006 // Now what should we do with the object?
1007 if (js->num_arguments() == 2) {
1008 // Print.
1009 if (obj.IsNull()) {
1010 // The object has been collected by the gc.
1011 PrintPseudoNull(js, "objects/collected", "<collected>");
1012 return true;
1013 } else if (obj.raw() == Object::sentinel().raw()) {
1014 // The object id has expired.
1015 PrintPseudoNull(js, "objects/expired", "<expired>");
1016 return true;
1017 }
1018 obj.PrintToJSONStream(js, false);
1019 return true;
1020 }
1021 ASSERT(js->num_arguments() > 2);
1022
1023 const char* action = js->GetArgument(2);
1024 if (strcmp(action, "eval") == 0) {
1025 if (js->num_arguments() > 3) {
1026 PrintError(js, "expected at most 3 arguments but found %" Pd "\n",
1027 js->num_arguments());
1028 return true;
1029 }
1030 if (obj.IsNull()) {
1031 PrintErrorWithKind(js, "EvalCollected",
1032 "attempt to evaluate against collected object\n",
1033 js->num_arguments());
1034 return true;
1035 }
1036 if (obj.raw() == Object::sentinel().raw()) {
1037 PrintErrorWithKind(js, "EvalExpired",
1038 "attempt to evaluate against expired object\n",
1039 js->num_arguments());
1040 return true;
1041 }
1042 const char* expr = js->LookupOption("expr");
1043 if (expr == NULL) {
1044 PrintError(js, "eval expects an 'expr' option\n",
1045 js->num_arguments());
1046 return true;
1047 }
1048 const String& expr_str = String::Handle(isolate, String::New(expr));
1049 ASSERT(obj.IsInstance());
1050 const Instance& instance = Instance::Cast(obj);
1051 const Object& result = Object::Handle(instance.Evaluate(expr_str));
1052 result.PrintToJSONStream(js, true);
1053 return true;
1054 }
1055
1056 PrintError(js, "unrecognized action '%s'\n", action);
985 return true; 1057 return true;
986 } 1058 }
987 1059
988 1060
989
990 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) { 1061 static bool HandleScriptsEnumerate(Isolate* isolate, JSONStream* js) {
991 JSONObject jsobj(js); 1062 JSONObject jsobj(js);
992 jsobj.AddProperty("type", "ScriptList"); 1063 jsobj.AddProperty("type", "ScriptList");
993 JSONArray members(&jsobj, "members"); 1064 JSONArray members(&jsobj, "members");
994 const GrowableObjectArray& libs = 1065 const GrowableObjectArray& libs =
995 GrowableObjectArray::Handle(isolate->object_store()->libraries()); 1066 GrowableObjectArray::Handle(isolate->object_store()->libraries());
996 int num_libs = libs.Length(); 1067 int num_libs = libs.Length();
997 Library &lib = Library::Handle(); 1068 Library &lib = Library::Handle();
998 Script& script = Script::Handle(); 1069 Script& script = Script::Handle();
999 for (intptr_t i = 0; i < num_libs; i++) { 1070 for (intptr_t i = 0; i < num_libs; i++) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 static bool HandleCpu(Isolate* isolate, JSONStream* js) { 1173 static bool HandleCpu(Isolate* isolate, JSONStream* js) {
1103 JSONObject jsobj(js); 1174 JSONObject jsobj(js);
1104 jsobj.AddProperty("type", "CPU"); 1175 jsobj.AddProperty("type", "CPU");
1105 jsobj.AddProperty("targetCPU", CPU::Id()); 1176 jsobj.AddProperty("targetCPU", CPU::Id());
1106 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); 1177 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware());
1107 return true; 1178 return true;
1108 } 1179 }
1109 1180
1110 1181
1111 static bool HandleNullCode(uintptr_t pc, JSONStream* js) { 1182 static bool HandleNullCode(uintptr_t pc, JSONStream* js) {
1183 // TODO(turnidge): Consider adding/using Object::null_code() for
1184 // consistent "type".
1112 Object::null_object().PrintToJSONStream(js, false); 1185 Object::null_object().PrintToJSONStream(js, false);
1113 return true; 1186 return true;
1114 } 1187 }
1115 1188
1116 1189
1117 static bool HandleCode(Isolate* isolate, JSONStream* js) { 1190 static bool HandleCode(Isolate* isolate, JSONStream* js) {
1118 REQUIRE_COLLECTION_ID("code"); 1191 REQUIRE_COLLECTION_ID("code");
1119 uintptr_t pc; 1192 uintptr_t pc;
1120 if (js->num_arguments() > 3) { 1193 if (js->num_arguments() > 3) {
1121 PrintError(js, "Command too long"); 1194 PrintError(js, "Command too long");
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 while (current != NULL) { 1498 while (current != NULL) {
1426 if (strcmp(name, current->name()) == 0) { 1499 if (strcmp(name, current->name()) == 0) {
1427 return current; 1500 return current;
1428 } 1501 }
1429 current = current->next(); 1502 current = current->next();
1430 } 1503 }
1431 return NULL; 1504 return NULL;
1432 } 1505 }
1433 1506
1434 } // namespace dart 1507 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698