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_id);
50 } else if (builtin_id == Builtins::kGenericJSToWasmWrapper) {
51 // Make sure to add the generic js-to-wasm wrapper builtin, because that
52 // one is supposed to show up in profiles.
53 entry = new CodeEntry(CodeEventListener::BUILTIN_TAG,
54 Builtins::name(builtin_id));
55 code_map->AddCode(instruction_start, entry, instruction_size);
56 }
57 }
58
StartTickSample()59 TickSample* SamplingEventsProcessor::StartTickSample() {
60 void* address = ticks_buffer_.StartEnqueue();
61 if (address == nullptr) return nullptr;
62 TickSampleEventRecord* evt =
63 new (address) TickSampleEventRecord(last_code_event_id_);
64 return &evt->sample;
65 }
66
FinishTickSample()67 void SamplingEventsProcessor::FinishTickSample() {
68 ticks_buffer_.FinishEnqueue();
69 }
70
71 } // namespace internal
72 } // namespace v8
73
74 #endif // V8_PROFILER_CPU_PROFILER_INL_H_
75