Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/profiler/simulator-helper.cc

Issue 2105943002: Expose TickSample and its APIs in v8-profiler.h (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PROFILER_TICK_SAMPLE_H_ 5 #include "src/profiler/simulator-helper.h"
6 #define V8_PROFILER_TICK_SAMPLE_H_
7 6
8 #include "include/v8.h" 7 #include "src/simulator.h"
9
10 #include "src/base/platform/time.h"
11 #include "src/frames.h"
12 #include "src/globals.h"
13 8
14 namespace v8 { 9 namespace v8 {
15 namespace internal { 10 namespace internal {
16 11
17 class Isolate;
18
19 // ----------------------------------------------------------------------------
20 // Sampler
21 //
22 // A sampler periodically samples the state of the VM and optionally
23 // (if used for profiling) the program counter and stack pointer for
24 // the thread that created it.
25
26 // TickSample captures the information collected for each sample.
27 struct TickSample {
28 // Internal profiling (with --prof + tools/$OS-tick-processor) wants to
29 // include the runtime function we're calling. Externally exposed tick
30 // samples don't care.
31 enum RecordCEntryFrame { kIncludeCEntryFrame, kSkipCEntryFrame };
32
33 TickSample()
34 : state(OTHER),
35 pc(NULL),
36 external_callback_entry(NULL),
37 frames_count(0),
38 has_external_callback(false),
39 update_stats(true) {}
40 void Init(Isolate* isolate, const v8::RegisterState& state,
41 RecordCEntryFrame record_c_entry_frame, bool update_stats);
42 static bool GetStackSample(Isolate* isolate, const v8::RegisterState& state,
43 RecordCEntryFrame record_c_entry_frame,
44 void** frames, size_t frames_limit,
45 v8::SampleInfo* sample_info);
46 StateTag state; // The state of the VM.
47 Address pc; // Instruction pointer.
48 union {
49 Address tos; // Top stack value (*sp).
50 Address external_callback_entry;
51 };
52 static const unsigned kMaxFramesCountLog2 = 8;
53 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
54 Address stack[kMaxFramesCount]; // Call stack.
55 base::TimeTicks timestamp;
56 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames.
57 bool has_external_callback : 1;
58 bool update_stats : 1; // Whether the sample should update aggregated stats.
59 };
60
61
62 #if defined(USE_SIMULATOR) 12 #if defined(USE_SIMULATOR)
63 class SimulatorHelper { 13 bool SimulatorHelper::FillRegisters(Isolate* isolate,
64 public: 14 v8::RegisterState* state) {
65 // Returns true if register values were successfully retrieved 15 Simulator* simulator = isolate->thread_local_top()->simulator_;
66 // from the simulator, otherwise returns false. 16 // Check if there is active simulator.
67 static bool FillRegisters(Isolate* isolate, v8::RegisterState* state); 17 if (simulator == NULL) return false;
68 }; 18 #if V8_TARGET_ARCH_ARM
19 if (!simulator->has_bad_pc()) {
20 state->pc = reinterpret_cast<Address>(simulator->get_pc());
21 }
22 state->sp = reinterpret_cast<Address>(simulator->get_register(Simulator::sp));
23 state->fp =
24 reinterpret_cast<Address>(simulator->get_register(Simulator::r11));
25 #elif V8_TARGET_ARCH_ARM64
26 state->pc = reinterpret_cast<Address>(simulator->pc());
27 state->sp = reinterpret_cast<Address>(simulator->sp());
28 state->fp = reinterpret_cast<Address>(simulator->fp());
29 #elif V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64
30 if (!simulator->has_bad_pc()) {
31 state->pc = reinterpret_cast<Address>(simulator->get_pc());
32 }
33 state->sp = reinterpret_cast<Address>(simulator->get_register(Simulator::sp));
34 state->fp = reinterpret_cast<Address>(simulator->get_register(Simulator::fp));
35 #elif V8_TARGET_ARCH_PPC
36 if (!simulator->has_bad_pc()) {
37 state->pc = reinterpret_cast<Address>(simulator->get_pc());
38 }
39 state->sp = reinterpret_cast<Address>(simulator->get_register(Simulator::sp));
40 state->fp = reinterpret_cast<Address>(simulator->get_register(Simulator::fp));
41 #elif V8_TARGET_ARCH_S390
42 if (!simulator->has_bad_pc()) {
43 state->pc = reinterpret_cast<Address>(simulator->get_pc());
44 }
45 state->sp = reinterpret_cast<Address>(simulator->get_register(Simulator::sp));
46 state->fp = reinterpret_cast<Address>(simulator->get_register(Simulator::fp));
47 #endif
48 if (state->sp == 0 || state->fp == 0) {
49 // It possible that the simulator is interrupted while it is updating
50 // the sp or fp register. ARM64 simulator does this in two steps:
51 // first setting it to zero and then setting it to the new value.
52 // Bailout if sp/fp doesn't contain the new value.
53 //
54 // FIXME: The above doesn't really solve the issue.
55 // If a 64-bit target is executed on a 32-bit host even the final
56 // write is non-atomic, so it might obtain a half of the result.
57 // Moreover as long as the register set code uses memcpy (as of now),
58 // it is not guaranteed to be atomic even when both host and target
59 // are of same bitness.
60 return false;
61 }
62 return true;
63 }
69 #endif // USE_SIMULATOR 64 #endif // USE_SIMULATOR
70 65
71 } // namespace internal 66 } // namespace internal
72 } // namespace v8 67 } // namespace v8
73
74 #endif // V8_PROFILER_TICK_SAMPLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698