Chromium Code Reviews| 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) { |
| 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() { |
| 139 Thread* thread = Thread::Current(); | 154 Thread* thread = Thread::Current(); |
| 140 ASSERT(thread != NULL); | 155 ASSERT(thread != NULL); |
| 141 Zone* zone = thread->zone(); | 156 Zone* zone = thread->zone(); |
| 142 ASSERT(zone != NULL); | 157 ASSERT(zone != NULL); |
| 143 return zone->PrintToString("%s %s", name(), ValueToString(value(), unit())); | 158 return zone->PrintToString("%s %s", name(), ValueToString(Value(), unit())); |
|
rmacnak
2017/01/31 23:49:19
Forcing compute here.
Cutch
2017/01/31 23:50:56
Acknowledged.
| |
| 144 } | 159 } |
| 145 | 160 |
| 146 | 161 |
| 147 bool Metric::NameExists(Metric* head, const char* name) { | 162 bool Metric::NameExists(Metric* head, const char* name) { |
| 148 ASSERT(name != NULL); | 163 ASSERT(name != NULL); |
| 149 while (head != NULL) { | 164 while (head != NULL) { |
| 150 const char* metric_name = head->name(); | 165 const char* metric_name = head->name(); |
| 151 ASSERT(metric_name != NULL); | 166 ASSERT(metric_name != NULL); |
| 152 if (strcmp(metric_name, name) == 0) { | 167 if (strcmp(metric_name, name) == 0) { |
| 153 return true; | 168 return true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 int64_t MetricHeapUsed::Value() const { | 299 int64_t MetricHeapUsed::Value() const { |
| 285 ASSERT(isolate() == Isolate::Current()); | 300 ASSERT(isolate() == Isolate::Current()); |
| 286 return isolate()->heap()->UsedInWords(Heap::kNew) * kWordSize + | 301 return isolate()->heap()->UsedInWords(Heap::kNew) * kWordSize + |
| 287 isolate()->heap()->UsedInWords(Heap::kOld) * kWordSize; | 302 isolate()->heap()->UsedInWords(Heap::kOld) * kWordSize; |
| 288 } | 303 } |
| 289 | 304 |
| 290 int64_t MetricIsolateCount::Value() const { | 305 int64_t MetricIsolateCount::Value() const { |
| 291 return Isolate::IsolateListLength(); | 306 return Isolate::IsolateListLength(); |
| 292 } | 307 } |
| 293 | 308 |
| 309 | |
| 310 int64_t MetricPeakRSS::Value() const { | |
| 311 return OS::MaxRSS(); | |
| 312 } | |
| 313 | |
| 294 #define VM_METRIC_VARIABLE(type, variable, name, unit) \ | 314 #define VM_METRIC_VARIABLE(type, variable, name, unit) \ |
| 295 static type vm_metric_##variable##_; | 315 static type vm_metric_##variable##_; |
| 296 VM_METRIC_LIST(VM_METRIC_VARIABLE); | 316 VM_METRIC_LIST(VM_METRIC_VARIABLE); |
| 297 #undef VM_METRIC_VARIABLE | 317 #undef VM_METRIC_VARIABLE |
| 298 | 318 |
| 299 | 319 |
| 300 void Metric::InitOnce() { | 320 void Metric::InitOnce() { |
| 301 #define VM_METRIC_INIT(type, variable, name, unit) \ | 321 #define VM_METRIC_INIT(type, variable, name, unit) \ |
| 302 vm_metric_##variable##_.Init(name, NULL, Metric::unit); | 322 vm_metric_##variable##_.Init(name, NULL, Metric::unit); |
| 303 VM_METRIC_LIST(VM_METRIC_INIT); | 323 VM_METRIC_LIST(VM_METRIC_INIT); |
| 304 #undef VM_METRIC_INIT | 324 #undef VM_METRIC_INIT |
| 305 } | 325 } |
| 306 | 326 |
| 307 void Metric::Cleanup() { | 327 void Metric::Cleanup() { |
| 308 if (FLAG_print_metrics) { | 328 if (FLAG_print_metrics || FLAG_print_benchmarking_metrics) { |
| 309 // Create a zone to allocate temporary strings in. | 329 // Create a zone to allocate temporary strings in. |
| 310 StackZone sz(Thread::Current()); | 330 StackZone sz(Thread::Current()); |
| 311 OS::PrintErr("Printing metrics for VM\n"); | 331 OS::PrintErr("Printing metrics for VM\n"); |
| 312 Metric* current = Metric::vm_head(); | 332 Metric* current = Metric::vm_head(); |
| 313 while (current != NULL) { | 333 while (current != NULL) { |
| 314 OS::PrintErr("%s\n", current->ToString()); | 334 OS::PrintErr("%s\n", current->ToString()); |
| 315 current = current->next(); | 335 current = current->next(); |
| 316 } | 336 } |
| 317 OS::PrintErr("\n"); | 337 OS::PrintErr("\n"); |
| 318 } | 338 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 336 } | 356 } |
| 337 | 357 |
| 338 | 358 |
| 339 void MinMetric::SetValue(int64_t new_value) { | 359 void MinMetric::SetValue(int64_t new_value) { |
| 340 if (new_value < value()) { | 360 if (new_value < value()) { |
| 341 set_value(new_value); | 361 set_value(new_value); |
| 342 } | 362 } |
| 343 } | 363 } |
| 344 | 364 |
| 345 } // namespace dart | 365 } // namespace dart |
| OLD | NEW |