Files
sdk/runtime/vm/counters.cc
T
koda@google.com 5886e8ec95 Light-weight stats counters for temporary experiments/debugging.
A single statement is enough to add a counter:
  ...
  Isolate::Current()->counters()->Increment("allocated", size_in_bytes);
  ...

I've been using these myself for a while now, but figured others might
find them useful too. They are not intended for production use, just temporary local experiments/investigation.

R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org//336683003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@37367 260f80e4-7a28-3924-810f-c04153c831b5
2014-06-16 17:13:20 +00:00

41 lines
1.0 KiB
C++

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/counters.h"
#include <string.h>
#include <map> // TODO(koda): Remove STL dependencies.
#include "platform/globals.h"
#include "vm/os.h"
namespace dart {
struct CStrLess {
bool operator()(const char* a, const char* b) const {
return strcmp(a, b) < 0;
}
};
Counters::~Counters() {
if (collision_) {
OS::PrintErr("Counters table collision; increase Counters::kSize.");
return;
}
typedef std::map<const char*, int64_t, CStrLess> TotalsMap;
TotalsMap totals;
for (int i = 0; i < kSize; ++i) {
const Counter& counter = counters_[i];
if (counter.name != NULL) {
totals[counter.name] += counter.value;
}
}
for (TotalsMap::iterator it = totals.begin(); it != totals.end(); ++it) {
OS::PrintErr("%s: %" Pd64 "\n", it->first, it->second);
}
}
} // namespace dart