Chromium Code Reviews| Index: runtime/vm/heap_histogram.h |
| =================================================================== |
| --- runtime/vm/heap_histogram.h (revision 0) |
| +++ runtime/vm/heap_histogram.h (revision 0) |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2013, 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. |
| + |
| +#ifndef VM_HEAP_HISTOGRAM_H_ |
| +#define VM_HEAP_HISTOGRAM_H_ |
| + |
| +#include "platform/assert.h" |
| +#include "vm/flags.h" |
| +#include "vm/raw_object.h" |
| +#include "vm/globals.h" |
| + |
| +namespace dart { |
| + |
| +DECLARE_FLAG(bool, print_object_histogram); |
| + |
| +// ObjectHistogram is used to compute an average object histogram over |
| +// the lifetime of an isolate and then print the histogram when the isolate |
| +// is shut down. Information is gathered at the backedge of each major GC event. |
|
ahe
2013/06/12 11:24:01
backedge -> back-edge or back edge.
bakster
2013/06/12 11:34:21
Done.
|
| +// When an object histogram is collected for an isolate, an extra major GC is |
| +// performed just prior to shutdown. |
| +class ObjectHistogram { |
| + public: |
| + explicit ObjectHistogram(Isolate* isolate); |
| + ~ObjectHistogram(); |
| + |
| + // Called when a new class is registered in the isoalte. |
|
ahe
2013/06/12 11:24:01
isoalte -> isolate.
bakster
2013/06/12 11:34:21
Done.
|
| + void RegisterClass(const Class& cls); |
| + |
| + // Collect sample for the histogram. Called at backedge of major GC. |
|
ahe
2013/06/12 11:24:01
backedge -> back-edge or back edge.
bakster
2013/06/12 11:34:21
Done.
|
| + void Collect(); |
| + |
| + // Print the histogram on stdout. |
| + void Print(); |
| + |
| + private: |
| + // Add obj to histogram |
| + void Add(RawObject* obj); |
| + |
| + // For each class an Element keeps track of the accounting. |
| + struct Element { |
| + void Add(int s) { |
| + count++; |
| + size += s; |
| + } |
| + int class_id; |
| + int count; |
| + int size; |
| + }; |
| + |
| + // Compare function for sorting result. |
| + static int compare(const Element** a, const Element** b); |
| + |
| + int major_gc_count_; |
| + int table_length_; |
| + Element* table_; |
| + Isolate* isolate_; |
| + |
| + friend class ObjectHistogramVisitor; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ObjectHistogram); |
| +}; |
| + |
| +} // namespace dart |
| + |
| +#endif // VM_HEAP_HISTOGRAM_H_ |