• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 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_PROFILER_CPU_PROFILER_INL_H_
6 #define V8_PROFILER_CPU_PROFILER_INL_H_
7 
8 #include "src/profiler/cpu-profiler.h"
9 
10 #include <new>
11 #include "src/profiler/circular-queue-inl.h"
12 #include "src/profiler/profile-generator-inl.h"
13 
14 namespace v8 {
15 namespace internal {
16 
UpdateCodeMap(CodeMap * code_map)17 void CodeCreateEventRecord::UpdateCodeMap(CodeMap* code_map) {
18   code_map->AddCode(instruction_start, entry, instruction_size);
19 }
20 
21 
UpdateCodeMap(CodeMap * code_map)22 void CodeMoveEventRecord::UpdateCodeMap(CodeMap* code_map) {
23   code_map->MoveCode(from_instruction_start, to_instruction_start);
24 }
25 
26 
UpdateCodeMap(CodeMap * code_map)27 void CodeDisableOptEventRecord::UpdateCodeMap(CodeMap* code_map) {
28   CodeEntry* entry = code_map->FindEntry(instruction_start);
29   if (entry != nullptr) {
30     entry->set_bailout_reason(bailout_reason);
31   }
32 }
33 
34 
UpdateCodeMap(CodeMap * code_map)35 void CodeDeoptEventRecord::UpdateCodeMap(CodeMap* code_map) {
36   CodeEntry* entry = code_map->FindEntry(instruction_start);
37   if (entry != nullptr) {
38     std::vector<CpuProfileDeoptFrame> frames_vector(
39         deopt_frames, deopt_frames + deopt_frame_count);
40     entry->set_deopt_info(deopt_reason, deopt_id, std::move(frames_vector));
41   }
42   delete[] deopt_frames;
43 }
44 
45 
UpdateCodeMap(CodeMap * code_map)46 void ReportBuiltinEventRecord::UpdateCodeMap(CodeMap* code_map) {
47   CodeEntry* entry = code_map->FindEntry(instruction_start);
48   if (entry) {
49     entry->SetBuiltinId(builtin);
50     return;
51   }
52 #if V8_ENABLE_WEBASSEMBLY
53   if (builtin == Builtin::kGenericJSToWasmWrapper) {
54     // Make sure to add the generic js-to-wasm wrapper builtin, because that
55     // one is supposed to show up in profiles.
56     entry = code_map->code_entries().Create(CodeEventListener::BUILTIN_TAG,
57                                             Builtins::name(builtin));
58     code_map->AddCode(instruction_start, entry, instruction_size);
59   }
60 #endif  // V8_ENABLE_WEBASSEMBLY
61 }
62 
StartTickSample()63 TickSample* SamplingEventsProcessor::StartTickSample() {
64   void* address = ticks_buffer_.StartEnqueue();
65   if (address == nullptr) return nullptr;
66   TickSampleEventRecord* evt =
67       new (address) TickSampleEventRecord(last_code_event_id_);
68   return &evt->sample;
69 }
70 
UpdateCodeMap(CodeMap * code_map)71 void CodeDeleteEventRecord::UpdateCodeMap(CodeMap* code_map) {
72   bool removed = code_map->RemoveCode(entry);
73   CHECK(removed);
74 }
75 
FinishTickSample()76 void SamplingEventsProcessor::FinishTickSample() {
77   ticks_buffer_.FinishEnqueue();
78 }
79 
80 }  // namespace internal
81 }  // namespace v8
82 
83 #endif  // V8_PROFILER_CPU_PROFILER_INL_H_
84