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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/metrics.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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