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

Unified Diff: runtime/vm/message.cc

Issue 1122503003: Display isolate message queue in Observatory debugger (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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/message.cc
diff --git a/runtime/vm/message.cc b/runtime/vm/message.cc
index ea9b9861425510f59e1b38ca9e79ab209aad79b7..90335d101203ed6262c6349097728a6832ccaa31 100644
--- a/runtime/vm/message.cc
+++ b/runtime/vm/message.cc
@@ -4,6 +4,9 @@
#include "vm/message.h"
+#include "vm/dart_entry.h"
+#include "vm/json_stream.h"
+#include "vm/object.h"
#include "vm/port.h"
namespace dart {
@@ -18,6 +21,26 @@ bool Message::RedirectToDeliveryFailurePort() {
}
+intptr_t Message::Id() const {
+ // Messages are allocated on the C heap. Use the raw address as the id.
+ return reinterpret_cast<intptr_t>(this);
+}
+
+const char* Message::PriorityAsString(Priority priority) {
+ switch (priority) {
+ case kNormalPriority:
+ return "Normal";
+ break;
+ case kOOBPriority:
+ return "OOB";
+ break;
+ default:
+ UNIMPLEMENTED();
+ return NULL;
+ }
+}
+
+
MessageQueue::MessageQueue() {
head_ = NULL;
tail_ = NULL;
@@ -106,4 +129,98 @@ void MessageQueue::Clear() {
}
+MessageQueue::Iterator::Iterator(const MessageQueue* queue)
+ : current_(NULL),
+ queue_(queue) {
+ Reset(queue);
+}
+
+
+MessageQueue::Iterator::~Iterator() {
+}
+
+void MessageQueue::Iterator::Reset(const MessageQueue* queue) {
+ queue_ = queue;
+ if (queue_ == NULL) {
+ current_ = NULL;
+ return;
+ }
+ current_ = queue_->head_;
+}
+
+// returns false when iterator has reached end of message queue.
+bool MessageQueue::Iterator::HasNext() {
+ return current() != NULL;
+}
+
+// Moves forward and then returns current().
+Message* MessageQueue::Iterator::Next() {
+ if (!HasNext()) {
+ return current();
turnidge 2015/05/04 17:47:13 Your Next() and HasNext() are a bit different than
Cutch 2015/05/04 19:56:51 Done.
+ }
+ current_ = current_->next_;
+ return current();
+}
+
+
+intptr_t MessageQueue::Length() const {
+ MessageQueue::Iterator it(this);
+ intptr_t length = 0;
+ for (; it.HasNext(); it.Next()) {
+ length++;
+ }
+ return length;
+}
+
+
+Message* MessageQueue::FindMessageById(intptr_t id) {
+ MessageQueue::Iterator it(this);
+ for (; it.HasNext(); it.Next()) {
+ Message* message = it.current();
+ ASSERT(message != NULL);
+ if (message->Id() == id) {
+ return message;
+ }
+ }
+ return NULL;
+}
+
+
+void MessageQueue::PrintJSON(JSONStream* stream) {
+ Isolate* isolate = Isolate::Current();
+ JSONArray messages(stream);
+
+ MessageQueue::Iterator it(this);
+ intptr_t depth = 0;
+
+ Object& msg_handler = Object::Handle(isolate);
+ for (; it.HasNext(); it.Next()) {
+ Message* current = it.current();
+ JSONObject message(&messages);
+ message.AddProperty("type", "IsolateMessage");
turnidge 2015/05/04 17:47:13 IsolateMessage? I don't like the "Isolate". Mayb
Cutch 2015/05/04 19:56:51 Done.
+ message.AddPropertyF("name", "Isolate Message (%" Px ")", current->Id());
+ message.AddPropertyF("messageObjectId", "messages/0x%" Px "",
+ current->Id());
+ message.AddProperty("size", current->len());
+ message.AddProperty("depth", depth++);
+ message.AddProperty("destinationPort",
turnidge 2015/05/04 17:47:13 Make this _destinationPort.
Cutch 2015/05/04 19:56:51 Done.
+ static_cast<intptr_t>(current->dest_port()));
+ message.AddProperty("priority",
+ Message::PriorityAsString(current->priority()));
+ msg_handler = DartLibraryCalls::LookupHandler(current->dest_port());
turnidge 2015/05/04 17:47:13 Add a TODO to move this map into the VM so we can
Cutch 2015/05/04 19:56:51 Done.
+ if (msg_handler.IsInstance() && Instance::Cast(msg_handler).IsClosure()) {
+ // Grab function from closure.
+ msg_handler = Closure::function(Instance::Cast(msg_handler));
+ }
+ if (!msg_handler.IsFunction()) {
+ // No handler function.
+ continue;
+ }
+ const Function& function = Function::Cast(msg_handler);
+ const Script& script = Script::Handle(isolate, function.script());
+ message.AddProperty("handlerFunction", function);
+ message.AddProperty("handlerScript", script);
turnidge 2015/05/04 17:47:13 Consider dropping handlerScript. Up to you.
Cutch 2015/05/04 19:56:51 Done.
+ }
+}
+
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698