OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef BIN_VMSTATS_IMPL_H_ |
| 6 #define BIN_VMSTATS_IMPL_H_ |
| 7 |
| 8 #include "bin/vmstats.h" |
| 9 |
| 10 #include <map> |
| 11 #include <sstream> |
| 12 #include <string> |
| 13 |
| 14 #include "bin/isolate_data.h" |
| 15 #include "platform/thread.h" |
| 16 |
| 17 // VmStats is a HTTP singleton service that reports status information |
| 18 // of the running VM. |
| 19 |
| 20 class VmStats { |
| 21 public: |
| 22 static void Start(int port, const char* root_dir); |
| 23 static void Stop(); |
| 24 |
| 25 // Add and remove functions for the isolate_table, called by main.cc. |
| 26 static void AddIsolate(IsolateData* isolate_data, Dart_Isolate isolate); |
| 27 static void RemoveIsolate(IsolateData* isolate_data); |
| 28 |
| 29 private: |
| 30 VmStats() : running_(false), bind_address_(0) {} |
| 31 |
| 32 static void WebServer(uword bind_address); |
| 33 static void Shutdown(); |
| 34 |
| 35 // Status text generators. |
| 36 char* IsolatesStatus(); |
| 37 |
| 38 typedef std::map<IsolateData*, Dart_Isolate> IsolateTable; |
| 39 |
| 40 std::string root_directory_; |
| 41 IsolateTable isolate_table_; |
| 42 bool running_; |
| 43 int64_t bind_address_; |
| 44 |
| 45 static VmStats* instance_; |
| 46 static dart::Monitor instance_monitor_; |
| 47 |
| 48 // Disallow copy constructor. |
| 49 DISALLOW_COPY_AND_ASSIGN(VmStats); |
| 50 }; |
| 51 |
| 52 |
| 53 // Status plug-in and linked-list node. |
| 54 class VmStatusPlugin { |
| 55 public: |
| 56 explicit VmStatusPlugin(Dart_VmStatusCallback callback) |
| 57 : callback_(callback), next_(NULL) {} |
| 58 |
| 59 void Append(VmStatusPlugin* plugin) { |
| 60 VmStatusPlugin* list = this; |
| 61 while (list->next_ != NULL) { |
| 62 list = list->next_; |
| 63 } |
| 64 list->next_ = plugin; |
| 65 } |
| 66 |
| 67 Dart_VmStatusCallback callback() { return callback_; } |
| 68 VmStatusPlugin* next() { return next_; } |
| 69 |
| 70 private: |
| 71 Dart_VmStatusCallback callback_; |
| 72 VmStatusPlugin* next_; |
| 73 }; |
| 74 |
| 75 |
| 76 // Singleton service managing VM status gathering and status plug-in |
| 77 // registration. |
| 78 class VmStatusService { |
| 79 public: |
| 80 static int RegisterPlugin(Dart_VmStatusCallback callback); |
| 81 |
| 82 // Returns VM status for a specified request. The caller is responsible |
| 83 // for releasing the heap memory after use. |
| 84 static char* GetVmStatus(const char* request); |
| 85 |
| 86 static void InitOnce(); |
| 87 |
| 88 private: |
| 89 VmStatusService() : registered_plugin_list_(NULL) {} |
| 90 |
| 91 static VmStatusService* instance_; |
| 92 static dart::Mutex mutex_; |
| 93 |
| 94 VmStatusPlugin* registered_plugin_list_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(VmStatusService); |
| 97 }; |
| 98 |
| 99 #endif // BIN_VMSTATS_IMPL_H_ |
OLD | NEW |