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

Side by Side Diff: runtime/bin/vmstats_impl.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 namespace dart {
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 Start(int port, const char* root_dir);
25 static void Stop();
26
27 // Add and remove functions for the isolate_table, called by main.cc.
28 static void AddIsolate(IsolateData* isolate_data, Dart_Isolate isolate);
29 static void RemoveIsolate(IsolateData* isolate_data);
30
31 private:
32 VmStats() {}
33
34 // Initial server thread function.
35 static void WebServer(uword server_socket);
36
37 // Status text generators.
38 char* IsolatesStatus();
39
40 typedef std::map<IsolateData*, Dart_Isolate> IsolateTable;
41
42 std::string root_directory_;
43 IsolateTable isolate_table_;
44
45 static VmStats* instance_;
46 static Mutex instance_lock_;
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
93 VmStatusPlugin* registered_plugin_list_;
94
95 DISALLOW_COPY_AND_ASSIGN(VmStatusService);
96 };
97
98 } // namespace dart
99
100 #endif // BIN_VMSTATS_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698