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

Side by Side Diff: runtime/vm/metrics.cc

Issue 464953002: Add VMMetric and some sample metrics (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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) 2014, 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 #include "vm/metrics.h"
6
7 #include "vm/isolate.h"
8 #include "vm/json_stream.h"
9 #include "vm/native_entry.h"
10 #include "vm/runtime_entry.h"
11 #include "vm/object.h"
12
13 namespace dart {
14
15 VMMetric* VMMetric::vm_list_head_ = NULL;
16
17 VMMetric::VMMetric()
18 : isolate_(NULL),
19 name_(NULL),
20 description_(NULL),
21 value_(0),
22 next_(NULL) {
23 }
24
25
26 void VMMetric::Init(Isolate* isolate,
27 const char* name,
28 const char* description) {
29 isolate_ = isolate;
30 name_ = name;
31 description_ = description;
32 RegisterWithIsolate();
33 }
34
35
36 void VMMetric::Init(const char* name, const char* description) {
37 name_ = name;
38 description_ = description;
39 RegisterWithVM();
40 }
41
42
43 VMMetric::~VMMetric() {
44 if (isolate_ == NULL) {
45 DeregisterWithVM();
46 } else {
47 DeregisterWithIsolate();
48 }
49 }
50
51
52 void VMMetric::PrintJSON(JSONStream* stream) {
53 JSONObject obj(stream);
54 obj.AddProperty("type", "Counter");
55 obj.AddProperty("name", name_);
56 obj.AddProperty("description", description_);
57 obj.AddPropertyF("id", "metrics/vm/%s", name_);
58 // TODO(johnmccutchan): Overflow?
59 double value_as_double = static_cast<double>(Value());
60 obj.AddProperty("value", value_as_double);
61 }
62
63
64 void VMMetric::RegisterWithIsolate() {
65 ASSERT(isolate_ != NULL);
66 ASSERT(next_ == NULL);
67 VMMetric* head = isolate_->metrics_list_head();
68 if (head != NULL) {
69 set_next(head);
70 }
71 isolate_->set_metrics_list_head(this);
72 }
73
74
75 void VMMetric::DeregisterWithIsolate() {
76 VMMetric* head = isolate_->metrics_list_head();
77 ASSERT(head != NULL);
78 // Handle head of list case.
79 if (head == this) {
80 isolate_->set_metrics_list_head(next());
81 set_next(NULL);
82 return;
83 }
84 VMMetric* previous = NULL;
85 while (true) {
86 previous = head;
87 ASSERT(previous != NULL);
88 head = head->next();
89 if (head == NULL) {
90 break;
91 }
92 if (head == this) {
93 // Remove this from list.
94 previous->set_next(head->next());
95 set_next(NULL);
96 return;
97 }
98 ASSERT(head != NULL);
99 }
100 UNREACHABLE();
101 }
102
103
104 void VMMetric::RegisterWithVM() {
105 ASSERT(isolate_ == NULL);
106 ASSERT(next_ == NULL);
107 VMMetric* head = vm_list_head_;
108 if (head != NULL) {
109 set_next(head);
110 }
111 vm_list_head_ = this;
112 }
113
114
115 void VMMetric::DeregisterWithVM() {
116 ASSERT(isolate_ == NULL);
117 VMMetric* head = vm_list_head_;
118 // Handle head of list case.
119 if (head == this) {
120 vm_list_head_ = next();
121 set_next(NULL);
122 return;
123 }
124 VMMetric* previous = NULL;
125 while (true) {
126 previous = head;
127 ASSERT(previous != NULL);
128 head = head->next();
129 if (head == NULL) {
130 break;
131 }
132 if (head == this) {
133 // Remove this from list.
134 previous->set_next(head->next());
135 set_next(NULL);
136 return;
137 }
138 ASSERT(head != NULL);
139 }
140 UNREACHABLE();
141 }
142
143
144 int64_t VMMetricHeapOldUsed::Value() const {
145 Isolate* isolate = Isolate::Current();
146 return isolate->heap()->UsedInWords(Heap::kOld) * kWordSize;
147 }
148
149
150 int64_t VMMetricHeapOldCapacity::Value() const {
151 Isolate* isolate = Isolate::Current();
152 return isolate->heap()->CapacityInWords(Heap::kOld) * kWordSize;
153 }
154
155
156 int64_t VMMetricHeapOldExternal::Value() const {
157 Isolate* isolate = Isolate::Current();
158 return isolate->heap()->ExternalInWords(Heap::kOld) * kWordSize;
159 }
160
161
162 int64_t VMMetricHeapNewUsed::Value() const {
163 Isolate* isolate = Isolate::Current();
164 return isolate->heap()->UsedInWords(Heap::kNew) * kWordSize;
165 }
166
167
168 int64_t VMMetricHeapNewCapacity::Value() const {
169 Isolate* isolate = Isolate::Current();
170 return isolate->heap()->CapacityInWords(Heap::kNew) * kWordSize;
171 }
172
173
174 int64_t VMMetricHeapNewExternal::Value() const {
175 Isolate* isolate = Isolate::Current();
176 return isolate->heap()->ExternalInWords(Heap::kNew) * kWordSize;
177 }
178
179
180 int64_t VMMetricIsolateCount::Value() const {
181 return Isolate::IsolateListLength();
182 }
183
184 #define VM_METRIC_VARIABLE(type, variable, name) \
185 static type vm_metric_##variable##_;
186 VM_METRIC_LIST(VM_METRIC_VARIABLE);
187 #undef VM_METRIC_VARIABLE
188
189
190 void VMMetric::InitOnce() {
191 #define VM_METRIC_INIT(type, variable, name) \
192 vm_metric_##variable##_.Init(name, NULL);
193 VM_METRIC_LIST(VM_METRIC_INIT);
194 #undef VM_METRIC_INIT
195 }
196
197 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698