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

Unified Diff: runtime/vm/debugger.cc

Issue 12221022: Initial prototype of vmstats support, based on Dart VM Stats draft design doc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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
Index: runtime/vm/debugger.cc
===================================================================
--- runtime/vm/debugger.cc (revision 18152)
+++ runtime/vm/debugger.cc (working copy)
@@ -4,14 +4,18 @@
#include "vm/debugger.h"
+#include <string>
+
#include "include/dart_api.h"
#include "vm/code_generator.h"
#include "vm/code_patcher.h"
#include "vm/compiler.h"
+#include "vm/dart_api_impl.h"
#include "vm/dart_entry.h"
#include "vm/flags.h"
#include "vm/globals.h"
+#include "vm/isolate.h"
#include "vm/longjump.h"
#include "vm/object.h"
#include "vm/object_store.h"
@@ -1734,4 +1738,56 @@
code_breakpoints_ = bpt;
}
+
+// Global static pointer used to ensure a single instance of the class.
+VmStatusService* VmStatusService::instance_ = NULL;
+
+
+void VmStatusService::InitOnce() {
+ VmStatusService::instance_ = new VmStatusService();
+
+ // Register built-in status plug-ins. RegisterPlugin is not used because
+ // this isn't called within an isolate, and because parameter checking
+ // isn't necessary.
+ VmStatusService::instance_->service_map_["isolate"] = &Isolate::GetStatus;
+
+ // TODO(tball): dynamically load any additional plug-ins.
+}
+
+
+Dart_Handle VmStatusService::RegisterPlugin(
+ const char* status_type, Dart_VmStatusCallback callback) {
siva 2013/02/11 19:14:55 Do you expect multiple threads to register plugins
+ if (status_type == NULL) {
+ return Api::NewError("status_type not specified");
+ }
+ if (callback == NULL) {
+ return Api::NewError("callback not specified");
+ }
+ VmStatusService::instance_->service_map_[status_type] = callback;
+ return Api::True(Isolate::Current());
+}
+
+
+char* VmStatusService::Dart_GetVmStatus(const char* request) {
+ // Extract service type from beginning of string.
+ char* start = const_cast<char*>(request);
+ if (*start == '/') {
+ start++;
+ }
+ size_t n = 0;
+ while (*(start + n) != '\0' && *(start + n) != '/') {
+ n++;
+ }
+ ASSERT(n != 0);
+ char* status_type = strndup(start, n);
+ ServiceMap* map = &VmStatusService::instance_->service_map_;
+ ServiceMap::iterator itr = map->find(status_type);
+ if (itr == map->end()) {
+ return strdup(""); // No status available for this status type.
+ }
+ Dart_VmStatusCallback callback = itr->second;
+ free(status_type);
+ return (callback)(request);
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698