• 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_LOGGING_RUNTIME_CALL_STATS_SCOPE_H_
6 #define V8_LOGGING_RUNTIME_CALL_STATS_SCOPE_H_
7 
8 #include <memory>
9 
10 #include "src/execution/isolate.h"
11 #include "src/execution/local-isolate.h"
12 #include "src/logging/counters.h"
13 #include "src/logging/runtime-call-stats.h"
14 #include "src/logging/tracing-flags.h"
15 
16 namespace v8 {
17 namespace internal {
18 
19 #ifdef V8_RUNTIME_CALL_STATS
20 
21 // Make the line number part of the scope's name to avoid -Wshadow warnings.
22 #define RCS_SCOPE(...)                                        \
23   v8::internal::RuntimeCallTimerScope CONCAT(rcs_timer_scope, \
24                                              __LINE__)(__VA_ARGS__)
25 
RuntimeCallTimerScope(Isolate * isolate,RuntimeCallCounterId counter_id)26 RuntimeCallTimerScope::RuntimeCallTimerScope(Isolate* isolate,
27                                              RuntimeCallCounterId counter_id) {
28   if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
29   stats_ = isolate->counters()->runtime_call_stats();
30   stats_->Enter(&timer_, counter_id);
31 }
32 
RuntimeCallTimerScope(LocalIsolate * isolate,RuntimeCallCounterId counter_id,RuntimeCallStats::CounterMode mode)33 RuntimeCallTimerScope::RuntimeCallTimerScope(
34     LocalIsolate* isolate, RuntimeCallCounterId counter_id,
35     RuntimeCallStats::CounterMode mode) {
36   if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
37   DCHECK_NOT_NULL(isolate->runtime_call_stats());
38   stats_ = isolate->runtime_call_stats();
39   if (mode == RuntimeCallStats::CounterMode::kThreadSpecific) {
40     counter_id = stats_->CounterIdForThread(counter_id);
41   }
42 
43   DCHECK(stats_->IsCounterAppropriateForThread(counter_id));
44   stats_->Enter(&timer_, counter_id);
45 }
46 
47 #else  // RUNTIME_CALL_STATS
48 
49 #define RCS_SCOPE(...)
50 
51 #endif  // defined(V8_RUNTIME_CALL_STATS)
52 
53 }  // namespace internal
54 }  // namespace v8
55 
56 #endif  // V8_LOGGING_RUNTIME_CALL_STATS_SCOPE_H_
57