OLD | NEW |
| (Empty) |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_COMPILER_ZONE_STATS_H_ | |
6 #define V8_COMPILER_ZONE_STATS_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <vector> | |
11 | |
12 #include "src/zone/zone.h" | |
13 | |
14 namespace v8 { | |
15 namespace internal { | |
16 namespace compiler { | |
17 | |
18 class ZoneStats final { | |
19 public: | |
20 class Scope final { | |
21 public: | |
22 explicit Scope(ZoneStats* zone_stats) | |
23 : zone_stats_(zone_stats), zone_(nullptr) {} | |
24 ~Scope() { Destroy(); } | |
25 | |
26 Zone* zone() { | |
27 if (zone_ == nullptr) zone_ = zone_stats_->NewEmptyZone(); | |
28 return zone_; | |
29 } | |
30 void Destroy() { | |
31 if (zone_ != nullptr) zone_stats_->ReturnZone(zone_); | |
32 zone_ = nullptr; | |
33 } | |
34 | |
35 private: | |
36 ZoneStats* const zone_stats_; | |
37 Zone* zone_; | |
38 DISALLOW_COPY_AND_ASSIGN(Scope); | |
39 }; | |
40 | |
41 class StatsScope final { | |
42 public: | |
43 explicit StatsScope(ZoneStats* zone_stats); | |
44 ~StatsScope(); | |
45 | |
46 size_t GetMaxAllocatedBytes(); | |
47 size_t GetCurrentAllocatedBytes(); | |
48 size_t GetTotalAllocatedBytes(); | |
49 | |
50 private: | |
51 friend class ZoneStats; | |
52 void ZoneReturned(Zone* zone); | |
53 | |
54 typedef std::map<Zone*, size_t> InitialValues; | |
55 | |
56 ZoneStats* const zone_stats_; | |
57 InitialValues initial_values_; | |
58 size_t total_allocated_bytes_at_start_; | |
59 size_t max_allocated_bytes_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(StatsScope); | |
62 }; | |
63 | |
64 explicit ZoneStats(AccountingAllocator* allocator); | |
65 ~ZoneStats(); | |
66 | |
67 size_t GetMaxAllocatedBytes(); | |
68 size_t GetTotalAllocatedBytes(); | |
69 size_t GetCurrentAllocatedBytes(); | |
70 | |
71 private: | |
72 Zone* NewEmptyZone(); | |
73 void ReturnZone(Zone* zone); | |
74 | |
75 static const size_t kMaxUnusedSize = 3; | |
76 typedef std::vector<Zone*> Zones; | |
77 typedef std::vector<StatsScope*> Stats; | |
78 | |
79 Zones zones_; | |
80 Stats stats_; | |
81 size_t max_allocated_bytes_; | |
82 size_t total_deleted_bytes_; | |
83 AccountingAllocator* allocator_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(ZoneStats); | |
86 }; | |
87 | |
88 } // namespace compiler | |
89 } // namespace internal | |
90 } // namespace v8 | |
91 | |
92 #endif // V8_COMPILER_ZONE_STATS_H_ | |
OLD | NEW |