From 71a2f538c07fa3ec941fd1410b7625d36ed21f95 Mon Sep 17 00:00:00 2001 From: "ulan@chromium.org" Date: Mon, 28 Nov 2011 12:12:00 +0000 Subject: [PATCH] Dump counters sorted by name on d8 exit. BUG= TEST= Review URL: http://codereview.chromium.org/8720005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10075 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8.cc | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/d8.cc b/src/d8.cc index 64ada2c..9eccc7e 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -794,22 +794,47 @@ void Shell::Exit(int exit_code) { #ifndef V8_SHARED +struct CounterAndKey { + Counter* counter; + const char* key; +}; + + +int CompareKeys(const void* a, const void* b) { + return strcmp(static_cast(a)->key, + static_cast(b)->key); +} + + void Shell::OnExit() { if (console != NULL) console->Close(); if (i::FLAG_dump_counters) { - printf("+----------------------------------------+-------------+\n"); - printf("| Name | Value |\n"); - printf("+----------------------------------------+-------------+\n"); + int number_of_counters = 0; for (CounterMap::Iterator i(counter_map_); i.More(); i.Next()) { - Counter* counter = i.CurrentValue(); + number_of_counters++; + } + CounterAndKey* counters = new CounterAndKey[number_of_counters]; + int j = 0; + for (CounterMap::Iterator i(counter_map_); i.More(); i.Next(), j++) { + counters[j].counter = i.CurrentValue(); + counters[j].key = i.CurrentKey(); + } + qsort(counters, number_of_counters, sizeof(counters[0]), CompareKeys); + printf("+--------------------------------------------+-------------+\n"); + printf("| Name | Value |\n"); + printf("+--------------------------------------------+-------------+\n"); + for (j = 0; j < number_of_counters; j++) { + Counter* counter = counters[j].counter; + const char* key = counters[j].key; if (counter->is_histogram()) { - printf("| c:%-36s | %11i |\n", i.CurrentKey(), counter->count()); - printf("| t:%-36s | %11i |\n", i.CurrentKey(), counter->sample_total()); + printf("| c:%-40s | %11i |\n", key, counter->count()); + printf("| t:%-40s | %11i |\n", key, counter->sample_total()); } else { - printf("| %-38s | %11i |\n", i.CurrentKey(), counter->count()); + printf("| %-42s | %11i |\n", key, counter->count()); } } - printf("+----------------------------------------+-------------+\n"); + printf("+--------------------------------------------+-------------+\n"); + delete [] counters; } if (counters_file_ != NULL) delete counters_file_; -- 2.7.4