| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #ifndef VM_COUNTERS_H_ |
| 6 #define VM_COUNTERS_H_ |
| 7 |
| 8 #include "platform/assert.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 struct Counter { |
| 13 Counter() : name(NULL), value(0) {} |
| 14 const char* name; |
| 15 int64_t value; |
| 16 }; |
| 17 |
| 18 |
| 19 // Light-weight stats counters for temporary experiments/debugging. |
| 20 // A single statement is enough to add a counter: |
| 21 // ... |
| 22 // Isolate::Current()->counters()->Increment("allocated", size_in_bytes); |
| 23 // ... |
| 24 class Counters { |
| 25 public: |
| 26 Counters() : collision_(false) {} |
| 27 |
| 28 // Adds 'delta' to the named counter. 'name' must be a literal string. |
| 29 void Increment(const char* name, int64_t delta) { |
| 30 Counter& counter = |
| 31 counters_[reinterpret_cast<uword>(name) & (kSize - 1)]; |
| 32 if (counter.name != name && counter.name != NULL) { |
| 33 collision_ = true; |
| 34 } |
| 35 counter.name = name; |
| 36 counter.value += delta; |
| 37 } |
| 38 |
| 39 // Prints all counters to stderr. |
| 40 ~Counters(); |
| 41 |
| 42 private: |
| 43 enum { kSize = 1024 }; |
| 44 COMPILE_ASSERT((0 == (kSize & (kSize - 1)))); // kSize is a power of 2. |
| 45 Counter counters_[kSize]; |
| 46 bool collision_; |
| 47 }; |
| 48 |
| 49 } // namespace dart |
| 50 |
| 51 #endif // VM_COUNTERS_H_ |
| OLD | NEW |