OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/metrics.h" | 5 #include "vm/metrics.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/json_stream.h" | 8 #include "vm/json_stream.h" |
9 #include "vm/native_entry.h" | 9 #include "vm/native_entry.h" |
10 #include "vm/runtime_entry.h" | 10 #include "vm/runtime_entry.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
12 #include "vm/log.h" | 12 #include "vm/log.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 DEFINE_FLAG(bool, print_metrics, false, | 16 DEFINE_FLAG(bool, |
| 17 print_metrics, |
| 18 false, |
17 "Print metrics when isolates (and the VM) are shutdown."); | 19 "Print metrics when isolates (and the VM) are shutdown."); |
18 | 20 |
19 Metric* Metric::vm_list_head_ = NULL; | 21 Metric* Metric::vm_list_head_ = NULL; |
20 | 22 |
21 Metric::Metric() | 23 Metric::Metric() |
22 : isolate_(NULL), | 24 : isolate_(NULL), |
23 name_(NULL), | 25 name_(NULL), |
24 description_(NULL), | 26 description_(NULL), |
25 unit_(kCounter), | 27 unit_(kCounter), |
26 value_(0), | 28 value_(0), |
27 next_(NULL) { | 29 next_(NULL) {} |
28 } | |
29 | 30 |
30 | 31 |
31 void Metric::Init(Isolate* isolate, | 32 void Metric::Init(Isolate* isolate, |
32 const char* name, | 33 const char* name, |
33 const char* description, | 34 const char* description, |
34 Unit unit) { | 35 Unit unit) { |
35 // Only called once. | 36 // Only called once. |
36 ASSERT(next_ == NULL); | 37 ASSERT(next_ == NULL); |
37 ASSERT(name != NULL); | 38 ASSERT(name != NULL); |
38 isolate_ = isolate; | 39 isolate_ = isolate; |
(...skipping 24 matching lines...) Expand all Loading... |
63 } else { | 64 } else { |
64 DeregisterWithIsolate(); | 65 DeregisterWithIsolate(); |
65 } | 66 } |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 | 70 |
70 #ifndef PRODUCT | 71 #ifndef PRODUCT |
71 static const char* UnitString(intptr_t unit) { | 72 static const char* UnitString(intptr_t unit) { |
72 switch (unit) { | 73 switch (unit) { |
73 case Metric::kCounter: return "counter"; | 74 case Metric::kCounter: |
74 case Metric::kByte: return "byte"; | 75 return "counter"; |
| 76 case Metric::kByte: |
| 77 return "byte"; |
75 default: | 78 default: |
76 UNREACHABLE(); | 79 UNREACHABLE(); |
77 } | 80 } |
78 UNREACHABLE(); | 81 UNREACHABLE(); |
79 return NULL; | 82 return NULL; |
80 } | 83 } |
81 | 84 |
82 | 85 |
83 void Metric::PrintJSON(JSONStream* stream) { | 86 void Metric::PrintJSON(JSONStream* stream) { |
84 if (!FLAG_support_service) { | 87 if (!FLAG_support_service) { |
(...skipping 30 matching lines...) Expand all Loading... |
115 if (value > KB) { | 118 if (value > KB) { |
116 scaled_suffix = "kb"; | 119 scaled_suffix = "kb"; |
117 scaled_value /= KB; | 120 scaled_value /= KB; |
118 } else if (value > MB) { | 121 } else if (value > MB) { |
119 scaled_suffix = "mb"; | 122 scaled_suffix = "mb"; |
120 scaled_value /= MB; | 123 scaled_value /= MB; |
121 } else if (value > GB) { | 124 } else if (value > GB) { |
122 scaled_suffix = "gb"; | 125 scaled_suffix = "gb"; |
123 scaled_value /= GB; | 126 scaled_value /= GB; |
124 } | 127 } |
125 return zone->PrintToString("%.3f %s (%" Pd64 ")", | 128 return zone->PrintToString("%.3f %s (%" Pd64 ")", scaled_value, |
126 scaled_value, | 129 scaled_suffix, value); |
127 scaled_suffix, | |
128 value); | |
129 } | 130 } |
130 default: | 131 default: |
131 UNREACHABLE(); | 132 UNREACHABLE(); |
132 return NULL; | 133 return NULL; |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 | 137 |
137 char* Metric::ToString() { | 138 char* Metric::ToString() { |
138 Thread* thread = Thread::Current(); | 139 Thread* thread = Thread::Current(); |
(...skipping 11 matching lines...) Expand all Loading... |
150 ASSERT(metric_name != NULL); | 151 ASSERT(metric_name != NULL); |
151 if (strcmp(metric_name, name) == 0) { | 152 if (strcmp(metric_name, name) == 0) { |
152 return true; | 153 return true; |
153 } | 154 } |
154 head = head->next(); | 155 head = head->next(); |
155 } | 156 } |
156 return false; | 157 return false; |
157 } | 158 } |
158 | 159 |
159 | 160 |
160 | |
161 void Metric::RegisterWithIsolate() { | 161 void Metric::RegisterWithIsolate() { |
162 ASSERT(isolate_ != NULL); | 162 ASSERT(isolate_ != NULL); |
163 ASSERT(next_ == NULL); | 163 ASSERT(next_ == NULL); |
164 // No duplicate names allowed. | 164 // No duplicate names allowed. |
165 ASSERT(!NameExists(isolate_->metrics_list_head(), name())); | 165 ASSERT(!NameExists(isolate_->metrics_list_head(), name())); |
166 Metric* head = isolate_->metrics_list_head(); | 166 Metric* head = isolate_->metrics_list_head(); |
167 if (head != NULL) { | 167 if (head != NULL) { |
168 set_next(head); | 168 set_next(head); |
169 } | 169 } |
170 isolate_->set_metrics_list_head(this); | 170 isolate_->set_metrics_list_head(this); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return isolate()->heap()->UsedInWords(Heap::kNew) * kWordSize + | 286 return isolate()->heap()->UsedInWords(Heap::kNew) * kWordSize + |
287 isolate()->heap()->UsedInWords(Heap::kOld) * kWordSize; | 287 isolate()->heap()->UsedInWords(Heap::kOld) * kWordSize; |
288 } | 288 } |
289 | 289 |
290 int64_t MetricIsolateCount::Value() const { | 290 int64_t MetricIsolateCount::Value() const { |
291 return Isolate::IsolateListLength(); | 291 return Isolate::IsolateListLength(); |
292 } | 292 } |
293 | 293 |
294 #define VM_METRIC_VARIABLE(type, variable, name, unit) \ | 294 #define VM_METRIC_VARIABLE(type, variable, name, unit) \ |
295 static type vm_metric_##variable##_; | 295 static type vm_metric_##variable##_; |
296 VM_METRIC_LIST(VM_METRIC_VARIABLE); | 296 VM_METRIC_LIST(VM_METRIC_VARIABLE); |
297 #undef VM_METRIC_VARIABLE | 297 #undef VM_METRIC_VARIABLE |
298 | 298 |
299 | 299 |
300 void Metric::InitOnce() { | 300 void Metric::InitOnce() { |
301 #define VM_METRIC_INIT(type, variable, name, unit) \ | 301 #define VM_METRIC_INIT(type, variable, name, unit) \ |
302 vm_metric_##variable##_.Init(name, NULL, Metric::unit); | 302 vm_metric_##variable##_.Init(name, NULL, Metric::unit); |
303 VM_METRIC_LIST(VM_METRIC_INIT); | 303 VM_METRIC_LIST(VM_METRIC_INIT); |
304 #undef VM_METRIC_INIT | 304 #undef VM_METRIC_INIT |
305 } | 305 } |
306 | 306 |
307 void Metric::Cleanup() { | 307 void Metric::Cleanup() { |
308 if (FLAG_print_metrics) { | 308 if (FLAG_print_metrics) { |
309 // Create a zone to allocate temporary strings in. | 309 // Create a zone to allocate temporary strings in. |
310 StackZone sz(Thread::Current()); | 310 StackZone sz(Thread::Current()); |
311 OS::PrintErr("Printing metrics for VM\n"); | 311 OS::PrintErr("Printing metrics for VM\n"); |
312 Metric* current = Metric::vm_head(); | 312 Metric* current = Metric::vm_head(); |
313 while (current != NULL) { | 313 while (current != NULL) { |
314 OS::PrintErr("%s\n", current->ToString()); | 314 OS::PrintErr("%s\n", current->ToString()); |
315 current = current->next(); | 315 current = current->next(); |
316 } | 316 } |
317 OS::PrintErr("\n"); | 317 OS::PrintErr("\n"); |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
321 | 321 |
322 MaxMetric::MaxMetric() | 322 MaxMetric::MaxMetric() : Metric() { |
323 : Metric() { | |
324 set_value(kMinInt64); | 323 set_value(kMinInt64); |
325 } | 324 } |
326 | 325 |
327 | 326 |
328 void MaxMetric::SetValue(int64_t new_value) { | 327 void MaxMetric::SetValue(int64_t new_value) { |
329 if (new_value > value()) { | 328 if (new_value > value()) { |
330 set_value(new_value); | 329 set_value(new_value); |
331 } | 330 } |
332 } | 331 } |
333 | 332 |
334 | 333 |
335 MinMetric::MinMetric() | 334 MinMetric::MinMetric() : Metric() { |
336 : Metric() { | |
337 set_value(kMaxInt64); | 335 set_value(kMaxInt64); |
338 } | 336 } |
339 | 337 |
340 | 338 |
341 void MinMetric::SetValue(int64_t new_value) { | 339 void MinMetric::SetValue(int64_t new_value) { |
342 if (new_value < value()) { | 340 if (new_value < value()) { |
343 set_value(new_value); | 341 set_value(new_value); |
344 } | 342 } |
345 } | 343 } |
346 | 344 |
347 } // namespace dart | 345 } // namespace dart |
OLD | NEW |