| Index: runtime/vm/metrics.cc
|
| diff --git a/runtime/vm/metrics.cc b/runtime/vm/metrics.cc
|
| index 0e04e6bc1df648db2633d81013fa65279d824ea3..79038fb1f266f2588919773c14920df0d8401fc1 100644
|
| --- a/runtime/vm/metrics.cc
|
| +++ b/runtime/vm/metrics.cc
|
| @@ -9,9 +9,13 @@
|
| #include "vm/native_entry.h"
|
| #include "vm/runtime_entry.h"
|
| #include "vm/object.h"
|
| +#include "vm/log.h"
|
|
|
| namespace dart {
|
|
|
| +DEFINE_FLAG(bool, print_metrics, false,
|
| + "Print metrics when isolates (and the VM) are shutdown.");
|
| +
|
| Metric* Metric::vm_list_head_ = NULL;
|
|
|
| Metric::Metric()
|
| @@ -92,6 +96,48 @@ void Metric::PrintJSON(JSONStream* stream) {
|
| }
|
|
|
|
|
| +char* Metric::ValueToString(int64_t value, Unit unit) {
|
| + Thread* thread = Thread::Current();
|
| + ASSERT(thread != NULL);
|
| + Zone* zone = thread->zone();
|
| + ASSERT(zone != NULL);
|
| + switch (unit) {
|
| + case kCounter:
|
| + return zone->PrintToString("%" Pd64 "", value);
|
| + case kByte: {
|
| + const char* scaled_suffix = "b";
|
| + double scaled_value = static_cast<double>(value);
|
| + if (value > KB) {
|
| + scaled_suffix = "kb";
|
| + scaled_value /= KB;
|
| + } else if (value > MB) {
|
| + scaled_suffix = "mb";
|
| + scaled_value /= MB;
|
| + } else if (value > GB) {
|
| + scaled_suffix = "gb";
|
| + scaled_value /= GB;
|
| + }
|
| + return zone->PrintToString("%.3f %s (%" Pd64 ")",
|
| + scaled_value,
|
| + scaled_suffix,
|
| + value);
|
| + }
|
| + default:
|
| + UNREACHABLE();
|
| + return NULL;
|
| + }
|
| +}
|
| +
|
| +
|
| +char* Metric::ToString() {
|
| + Thread* thread = Thread::Current();
|
| + ASSERT(thread != NULL);
|
| + Zone* zone = thread->zone();
|
| + ASSERT(zone != NULL);
|
| + return zone->PrintToString("%s %s", name(), ValueToString(value(), unit()));
|
| +}
|
| +
|
| +
|
| bool Metric::NameExists(Metric* head, const char* name) {
|
| ASSERT(name != NULL);
|
| while (head != NULL) {
|
| @@ -247,4 +293,18 @@ void Metric::InitOnce() {
|
| #undef VM_METRIC_INIT
|
| }
|
|
|
| +void Metric::Cleanup() {
|
| + if (FLAG_print_metrics) {
|
| + // Create a zone to allocate temporary strings in.
|
| + StackZone sz(Thread::Current());
|
| + OS::Print("Printing metrics for VM\n");
|
| + Metric* current = Metric::vm_head();
|
| + while (current != NULL) {
|
| + OS::Print("%s\n", current->ToString());
|
| + current = current->next();
|
| + }
|
| + OS::Print("\n");
|
| + }
|
| +}
|
| +
|
| } // namespace dart
|
|
|