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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 #ifndef PRODUCT | 71 #ifndef PRODUCT |
72 static const char* UnitString(intptr_t unit) { | 72 static const char* UnitString(intptr_t unit) { |
73 switch (unit) { | 73 switch (unit) { |
74 case Metric::kCounter: | 74 case Metric::kCounter: |
75 return "counter"; | 75 return "counter"; |
76 case Metric::kByte: | 76 case Metric::kByte: |
77 return "byte"; | 77 return "byte"; |
78 case Metric::kMicrosecond: | |
79 return "us"; | |
78 default: | 80 default: |
79 UNREACHABLE(); | 81 UNREACHABLE(); |
80 } | 82 } |
81 UNREACHABLE(); | 83 UNREACHABLE(); |
82 return NULL; | 84 return NULL; |
83 } | 85 } |
84 | 86 |
85 | 87 |
86 void Metric::PrintJSON(JSONStream* stream) { | 88 void Metric::PrintJSON(JSONStream* stream) { |
87 if (!FLAG_support_service) { | 89 if (!FLAG_support_service) { |
(...skipping 18 matching lines...) Expand all Loading... | |
106 | 108 |
107 char* Metric::ValueToString(int64_t value, Unit unit) { | 109 char* Metric::ValueToString(int64_t value, Unit unit) { |
108 Thread* thread = Thread::Current(); | 110 Thread* thread = Thread::Current(); |
109 ASSERT(thread != NULL); | 111 ASSERT(thread != NULL); |
110 Zone* zone = thread->zone(); | 112 Zone* zone = thread->zone(); |
111 ASSERT(zone != NULL); | 113 ASSERT(zone != NULL); |
112 switch (unit) { | 114 switch (unit) { |
113 case kCounter: | 115 case kCounter: |
114 return zone->PrintToString("%" Pd64 "", value); | 116 return zone->PrintToString("%" Pd64 "", value); |
115 case kByte: { | 117 case kByte: { |
116 const char* scaled_suffix = "b"; | 118 const char* scaled_suffix = "B"; |
117 double scaled_value = static_cast<double>(value); | 119 double scaled_value = static_cast<double>(value); |
118 if (value > KB) { | 120 if (value > GB) { |
Cutch
2016/12/16 21:49:07
nice fix.
| |
119 scaled_suffix = "kb"; | 121 scaled_suffix = "GB"; |
122 scaled_value /= GB; | |
123 } else if (value > MB) { | |
124 scaled_suffix = "MB"; | |
125 scaled_value /= MB; | |
126 } else if (value > KB) { | |
127 scaled_suffix = "kB"; | |
120 scaled_value /= KB; | 128 scaled_value /= KB; |
121 } else if (value > MB) { | |
122 scaled_suffix = "mb"; | |
123 scaled_value /= MB; | |
124 } else if (value > GB) { | |
125 scaled_suffix = "gb"; | |
126 scaled_value /= GB; | |
127 } | 129 } |
128 return zone->PrintToString("%.3f %s (%" Pd64 ")", scaled_value, | 130 return zone->PrintToString("%.3f %s (%" Pd64 " B)", scaled_value, |
131 scaled_suffix, value); | |
132 } | |
133 case kMicrosecond: { | |
134 const char* scaled_suffix = "us"; | |
135 double scaled_value = static_cast<double>(value); | |
136 if (value > kMicrosecondsPerSecond) { | |
137 scaled_suffix = "s"; | |
138 scaled_value /= kMicrosecondsPerSecond; | |
139 } else if (value > kMicrosecondsPerMillisecond) { | |
140 scaled_suffix = "ms"; | |
141 scaled_value /= kMicrosecondsPerMillisecond; | |
142 } | |
143 return zone->PrintToString("%.3f %s (%" Pd64 " us)", scaled_value, | |
129 scaled_suffix, value); | 144 scaled_suffix, value); |
130 } | 145 } |
131 default: | 146 default: |
132 UNREACHABLE(); | 147 UNREACHABLE(); |
133 return NULL; | 148 return NULL; |
134 } | 149 } |
135 } | 150 } |
136 | 151 |
137 | 152 |
138 char* Metric::ToString() { | 153 char* Metric::ToString() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 | 313 |
299 | 314 |
300 void Metric::InitOnce() { | 315 void Metric::InitOnce() { |
301 #define VM_METRIC_INIT(type, variable, name, unit) \ | 316 #define VM_METRIC_INIT(type, variable, name, unit) \ |
302 vm_metric_##variable##_.Init(name, NULL, Metric::unit); | 317 vm_metric_##variable##_.Init(name, NULL, Metric::unit); |
303 VM_METRIC_LIST(VM_METRIC_INIT); | 318 VM_METRIC_LIST(VM_METRIC_INIT); |
304 #undef VM_METRIC_INIT | 319 #undef VM_METRIC_INIT |
305 } | 320 } |
306 | 321 |
307 void Metric::Cleanup() { | 322 void Metric::Cleanup() { |
308 if (FLAG_print_metrics) { | 323 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { |
309 // Create a zone to allocate temporary strings in. | 324 // Create a zone to allocate temporary strings in. |
310 StackZone sz(Thread::Current()); | 325 StackZone sz(Thread::Current()); |
311 OS::PrintErr("Printing metrics for VM\n"); | 326 OS::PrintErr("Printing metrics for VM\n"); |
312 Metric* current = Metric::vm_head(); | 327 Metric* current = Metric::vm_head(); |
313 while (current != NULL) { | 328 while (current != NULL) { |
314 OS::PrintErr("%s\n", current->ToString()); | 329 OS::PrintErr("%s\n", current->ToString()); |
315 current = current->next(); | 330 current = current->next(); |
316 } | 331 } |
317 OS::PrintErr("\n"); | 332 OS::PrintErr("\n"); |
318 } | 333 } |
(...skipping 17 matching lines...) Expand all Loading... | |
336 } | 351 } |
337 | 352 |
338 | 353 |
339 void MinMetric::SetValue(int64_t new_value) { | 354 void MinMetric::SetValue(int64_t new_value) { |
340 if (new_value < value()) { | 355 if (new_value < value()) { |
341 set_value(new_value); | 356 set_value(new_value); |
342 } | 357 } |
343 } | 358 } |
344 | 359 |
345 } // namespace dart | 360 } // namespace dart |
OLD | NEW |