Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index cff1f2819d34e85f5dbb8a2a6533170a449116f1..2b73cc65473719d0db599f00264e7c30e0b7eda1 100644 |
--- a/runtime/vm/service.cc |
+++ b/runtime/vm/service.cc |
@@ -14,6 +14,7 @@ |
#include "vm/object_id_ring.h" |
#include "vm/object_store.h" |
#include "vm/port.h" |
+#include "vm/profiler.h" |
namespace dart { |
@@ -251,7 +252,7 @@ static void HandleEcho(Isolate* isolate, JSONStream* js) { |
} |
-static bool GetIntegerId(const char* s, intptr_t* id) { |
+static bool GetIntegerId(const char* s, intptr_t* id, int base = 10) { |
if ((s == NULL) || (*s == '\0')) { |
// Empty string. |
return false; |
@@ -262,7 +263,28 @@ static bool GetIntegerId(const char* s, intptr_t* id) { |
} |
intptr_t r = 0; |
char* end_ptr = NULL; |
- r = strtol(s, &end_ptr, 10); |
+ r = strtol(s, &end_ptr, base); |
+ if (end_ptr == s) { |
+ // String was not advanced at all, cannot be valid. |
+ return false; |
+ } |
+ *id = r; |
+ return true; |
+} |
+ |
+ |
+static bool GetUnsignedIntegerId(const char* s, uintptr_t* id, int base = 10) { |
+ if ((s == NULL) || (*s == '\0')) { |
+ // Empty string. |
+ return false; |
+ } |
+ if (id == NULL) { |
+ // No id pointer. |
+ return false; |
+ } |
+ uintptr_t r = 0; |
+ char* end_ptr = NULL; |
+ r = strtoul(s, &end_ptr, base); |
if (end_ptr == s) { |
// String was not advanced at all, cannot be valid. |
return false; |
@@ -521,9 +543,31 @@ static void HandleCpu(Isolate* isolate, JSONStream* js) { |
} |
+static void HandleCode(Isolate* isolate, JSONStream* js) { |
+ REQUIRE_COLLECTION_ID("code"); |
+ uintptr_t pc; |
+ if (!GetUnsignedIntegerId(js->GetArgument(1), &pc, 16)) { |
+ PrintError(js, "Must specify code address: code/c0deadd0."); |
+ return; |
+ } |
+ Code& code = Code::Handle(Code::LookupCode(pc)); |
+ if (code.IsNull()) { |
+ PrintError(js, "Could not find code at %" Px "", pc); |
+ return; |
+ } |
+ code.PrintToJSONStream(js, false); |
+} |
+ |
+ |
+static void HandleProfile(Isolate* isolate, JSONStream* js) { |
+ Profiler::PrintToJSONStream(isolate, js); |
+} |
+ |
+ |
static ServiceMessageHandlerEntry __message_handlers[] = { |
{ "_echo", HandleEcho }, |
{ "classes", HandleClasses }, |
+ { "code", HandleCode }, |
{ "cpu", HandleCpu }, |
{ "debug", HandleDebug }, |
{ "libraries", HandleLibraries }, |
@@ -531,6 +575,7 @@ static ServiceMessageHandlerEntry __message_handlers[] = { |
{ "name", HandleName }, |
{ "objecthistogram", HandleObjectHistogram}, |
{ "objects", HandleObjects }, |
+ { "profile", HandleProfile }, |
Ivan Posva
2013/12/30 23:06:09
We will want to separate profile from profile tick
|
{ "scripts", HandleScripts }, |
{ "stacktrace", HandleStackTrace }, |
}; |