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

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

Issue 1303033005: Add --print-metrics vm flag for printing metrics to console (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « runtime/vm/metrics.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13
13 namespace dart { 14 namespace dart {
14 15
16 DEFINE_FLAG(bool, print_metrics, false,
17 "Print metrics when isolates (and the VM) are shutdown.");
18
15 Metric* Metric::vm_list_head_ = NULL; 19 Metric* Metric::vm_list_head_ = NULL;
16 20
17 Metric::Metric() 21 Metric::Metric()
18 : isolate_(NULL), 22 : isolate_(NULL),
19 name_(NULL), 23 name_(NULL),
20 description_(NULL), 24 description_(NULL),
21 unit_(kCounter), 25 unit_(kCounter),
22 value_(0), 26 value_(0),
23 next_(NULL) { 27 next_(NULL) {
24 } 28 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 obj.AddFixedServiceId("vm/metrics/%s", name_); 89 obj.AddFixedServiceId("vm/metrics/%s", name_);
86 } else { 90 } else {
87 obj.AddFixedServiceId("metrics/native/%s", name_); 91 obj.AddFixedServiceId("metrics/native/%s", name_);
88 } 92 }
89 // TODO(johnmccutchan): Overflow? 93 // TODO(johnmccutchan): Overflow?
90 double value_as_double = static_cast<double>(Value()); 94 double value_as_double = static_cast<double>(Value());
91 obj.AddProperty("value", value_as_double); 95 obj.AddProperty("value", value_as_double);
92 } 96 }
93 97
94 98
99 char* Metric::ValueToString(int64_t value, Unit unit) {
100 Thread* thread = Thread::Current();
101 ASSERT(thread != NULL);
102 Zone* zone = thread->zone();
103 ASSERT(zone != NULL);
104 switch (unit) {
105 case kCounter:
106 return zone->PrintToString("%" Pd64 "", value);
107 case kByte: {
108 const char* scaled_suffix = "b";
109 double scaled_value = static_cast<double>(value);
110 if (value > KB) {
111 scaled_suffix = "kb";
112 scaled_value /= KB;
113 } else if (value > MB) {
114 scaled_suffix = "mb";
115 scaled_value /= MB;
116 } else if (value > GB) {
117 scaled_suffix = "gb";
118 scaled_value /= GB;
119 }
120 return zone->PrintToString("%.3f %s (%" Pd64 ")",
121 scaled_value,
122 scaled_suffix,
123 value);
124 }
125 default:
126 UNREACHABLE();
127 return NULL;
128 }
129 }
130
131
132 char* Metric::ToString() {
133 Thread* thread = Thread::Current();
134 ASSERT(thread != NULL);
135 Zone* zone = thread->zone();
136 ASSERT(zone != NULL);
137 return zone->PrintToString("%s %s", name(), ValueToString(value(), unit()));
138 }
139
140
95 bool Metric::NameExists(Metric* head, const char* name) { 141 bool Metric::NameExists(Metric* head, const char* name) {
96 ASSERT(name != NULL); 142 ASSERT(name != NULL);
97 while (head != NULL) { 143 while (head != NULL) {
98 const char* metric_name = head->name(); 144 const char* metric_name = head->name();
99 ASSERT(metric_name != NULL); 145 ASSERT(metric_name != NULL);
100 if (strcmp(metric_name, name) == 0) { 146 if (strcmp(metric_name, name) == 0) {
101 return true; 147 return true;
102 } 148 }
103 head = head->next(); 149 head = head->next();
104 } 150 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 #undef VM_METRIC_VARIABLE 286 #undef VM_METRIC_VARIABLE
241 287
242 288
243 void Metric::InitOnce() { 289 void Metric::InitOnce() {
244 #define VM_METRIC_INIT(type, variable, name, unit) \ 290 #define VM_METRIC_INIT(type, variable, name, unit) \
245 vm_metric_##variable##_.Init(name, NULL, Metric::unit); 291 vm_metric_##variable##_.Init(name, NULL, Metric::unit);
246 VM_METRIC_LIST(VM_METRIC_INIT); 292 VM_METRIC_LIST(VM_METRIC_INIT);
247 #undef VM_METRIC_INIT 293 #undef VM_METRIC_INIT
248 } 294 }
249 295
296 void Metric::Cleanup() {
297 if (FLAG_print_metrics) {
298 // Create a zone to allocate temporary strings in.
299 StackZone sz(Thread::Current());
300 OS::Print("Printing metrics for VM\n");
301 Metric* current = Metric::vm_head();
302 while (current != NULL) {
303 OS::Print("%s\n", current->ToString());
304 current = current->next();
305 }
306 OS::Print("\n");
307 }
308 }
309
250 } // namespace dart 310 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/metrics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698