• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
6 #define V8_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
7 
8 #include "include/v8-platform.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 /**
14  * Scope that notifies embedder's observer about entering sections with high
15  * throughput of malloc/free operations.
16  */
17 class HighAllocationThroughputScope final {
18  public:
HighAllocationThroughputScope(Platform * platform)19   explicit HighAllocationThroughputScope(Platform* platform)
20       : observer_(platform->GetHighAllocationThroughputObserver()) {
21     observer_->LeaveSection();
22   }
23 
24   HighAllocationThroughputScope(const HighAllocationThroughputScope&) = delete;
25   HighAllocationThroughputScope& operator=(
26       const HighAllocationThroughputScope&) = delete;
27 
~HighAllocationThroughputScope()28   ~HighAllocationThroughputScope() { observer_->EnterSection(); }
29 
30  private:
31   HighAllocationThroughputObserver* observer_;
32 };
33 
34 }  // namespace internal
35 }  // namespace v8
36 
37 #endif  // V8_COMMON_HIGH_ALLOCATION_THROUGHPUT_SCOPE_H_
38