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