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 struct Element { | |
Ivan Posva
2013/06/12 15:18:09
class Element : public ValueObject {
bakster
2013/06/12 15:42:42
Done.
| |
42 void Add(int s) { | |
Ivan Posva
2013/06/12 15:18:09
intptr_t size
bakster
2013/06/12 15:42:42
Done.
| |
43 count++; | |
44 size += s; | |
45 } | |
46 int class_id; | |
47 int count; | |
Ivan Posva
2013/06/12 15:18:09
intptr_t for class_id_, count_ and size_.
bakster
2013/06/12 15:42:42
Done.
| |
48 int size; | |
49 }; | |
50 | |
51 // Compare function for sorting result. | |
52 static int compare(const Element** a, const Element** b); | |
53 | |
54 int major_gc_count_; | |
55 int table_length_; | |
Ivan Posva
2013/06/12 15:18:09
intptr_t for these int fields.
bakster
2013/06/12 15:42:42
Done.
| |
56 Element* table_; | |
57 Isolate* isolate_; | |
58 | |
59 friend class ObjectHistogramVisitor; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(ObjectHistogram); | |
62 }; | |
63 | |
64 } // namespace dart | |
65 | |
66 #endif // VM_HEAP_HISTOGRAM_H_ | |
67 | |
OLD | NEW |