OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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_HEAP_HISTOGRAM_H_ |
| 6 #define VM_HEAP_HISTOGRAM_H_ |
| 7 |
| 8 #include "platform/assert.h" |
| 9 #include "vm/flags.h" |
| 10 #include "vm/globals.h" |
| 11 #include "vm/raw_object.h" |
| 12 |
| 13 namespace dart { |
| 14 |
| 15 DECLARE_FLAG(bool, print_object_histogram); |
| 16 |
| 17 // ObjectHistogram is used to compute an average object histogram over |
| 18 // the lifetime of an isolate and then print the histogram when the isolate |
| 19 // is shut down. Information is gathered at the back-edge of each major GC |
| 20 // event. When an object histogram is collected for an isolate, an extra major |
| 21 // GC is performed just prior to shutdown. |
| 22 class ObjectHistogram { |
| 23 public: |
| 24 explicit ObjectHistogram(Isolate* isolate); |
| 25 ~ObjectHistogram(); |
| 26 |
| 27 // Called when a new class is registered in the isolate. |
| 28 void RegisterClass(const Class& cls); |
| 29 |
| 30 // Collect sample for the histogram. Called at back-edge of major GC. |
| 31 void Collect(); |
| 32 |
| 33 // Print the histogram on stdout. |
| 34 void Print(); |
| 35 |
| 36 private: |
| 37 // Add obj to histogram |
| 38 void Add(RawObject* obj); |
| 39 |
| 40 // For each class an Element keeps track of the accounting. |
| 41 class Element : public ValueObject { |
| 42 public: |
| 43 void Add(int size) { |
| 44 count_++; |
| 45 size_ += size; |
| 46 } |
| 47 intptr_t class_id_; |
| 48 intptr_t count_; |
| 49 intptr_t size_; |
| 50 }; |
| 51 |
| 52 // Compare function for sorting result. |
| 53 static int compare(const Element** a, const Element** b); |
| 54 |
| 55 intptr_t major_gc_count_; |
| 56 intptr_t table_length_; |
| 57 Element* table_; |
| 58 Isolate* isolate_; |
| 59 |
| 60 friend class ObjectHistogramVisitor; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ObjectHistogram); |
| 63 }; |
| 64 |
| 65 } // namespace dart |
| 66 |
| 67 #endif // VM_HEAP_HISTOGRAM_H_ |
| 68 |
OLD | NEW |