8 #include "../include/v8-profiler.h"
21 CpuProfilesCollection profiles;
23 ProfilerEventsProcessor processor(&generator);
31 static void InitializeVM() {
41 static void EnqueueTickSampleEvent(ProfilerEventsProcessor* proc,
50 sample->
stack[0] = frame2;
54 sample->
stack[1] = frame3;
64 : old_flag_prof_browser_mode_(i::FLAG_prof_browser_mode) {
65 i::FLAG_prof_browser_mode =
false;
69 i::FLAG_prof_browser_mode = old_flag_prof_browser_mode_;
73 bool old_flag_prof_browser_mode_;
81 CpuProfilesCollection profiles;
82 profiles.StartProfiling(
"", 1);
84 ProfilerEventsProcessor processor(&generator);
89 const char* aaa_str =
"aaa";
92 processor.CodeCreateEvent(i::Logger::FUNCTION_TAG,
99 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
103 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
104 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
108 processor.CodeMoveEvent(ToAddress(0x1400), ToAddress(0x1500));
109 processor.CodeCreateEvent(i::Logger::STUB_TAG, 3, ToAddress(0x1600), 0x10);
110 processor.CodeCreateEvent(i::Logger::STUB_TAG, 4, ToAddress(0x1605), 0x10);
112 EnqueueTickSampleEvent(&processor, ToAddress(0x1000));
118 CodeEntry* entry1 = generator.code_map()->FindEntry(ToAddress(0x1000));
121 CodeEntry* entry2 = generator.code_map()->FindEntry(ToAddress(0x1200));
124 CodeEntry* entry3 = generator.code_map()->FindEntry(ToAddress(0x1300));
127 CHECK_EQ(
NULL, generator.code_map()->FindEntry(ToAddress(0x1400)));
128 CodeEntry* entry4 = generator.code_map()->FindEntry(ToAddress(0x1500));
131 CHECK_EQ(
NULL, generator.code_map()->FindEntry(ToAddress(0x1600)));
136 static int CompareProfileNodes(
const T*
p1,
const T*
p2) {
137 return strcmp((*p1)->entry()->name(), (*p2)->entry()->name());
141 TestSetup test_setup;
142 CpuProfilesCollection profiles;
143 profiles.StartProfiling(
"", 1);
145 ProfilerEventsProcessor processor(&generator);
148 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
152 processor.CodeCreateEvent(i::Logger::STUB_TAG, 5, ToAddress(0x1300), 0x10);
153 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
157 EnqueueTickSampleEvent(&processor, ToAddress(0x1210));
158 EnqueueTickSampleEvent(&processor, ToAddress(0x1305), ToAddress(0x1220));
159 EnqueueTickSampleEvent(&processor,
166 CpuProfile* profile =
167 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken,
"", 1);
172 profile->top_down()->root()->children();
173 CHECK_EQ(1, top_down_root_children->length());
174 CHECK_EQ(
"bbb", top_down_root_children->
last()->entry()->name());
176 top_down_root_children->
last()->children();
177 CHECK_EQ(1, top_down_bbb_children->length());
178 CHECK_EQ(
"5", top_down_bbb_children->last()->entry()->name());
180 top_down_bbb_children->
last()->children();
181 CHECK_EQ(1, top_down_stub_children->length());
182 CHECK_EQ(
"ddd", top_down_stub_children->last()->entry()->name());
184 top_down_stub_children->
last()->children();
185 CHECK_EQ(0, top_down_ddd_children->length());
188 profile->bottom_up()->root()->children();
189 CHECK_EQ(3, bottom_up_root_children_unsorted->length());
191 bottom_up_root_children.AddAll(*bottom_up_root_children_unsorted);
192 bottom_up_root_children.Sort(&CompareProfileNodes);
193 CHECK_EQ(
"5", bottom_up_root_children[0]->entry()->name());
194 CHECK_EQ(
"bbb", bottom_up_root_children[1]->entry()->name());
195 CHECK_EQ(
"ddd", bottom_up_root_children[2]->entry()->name());
197 bottom_up_root_children[0]->children();
198 CHECK_EQ(1, bottom_up_stub_children->length());
199 CHECK_EQ(
"bbb", bottom_up_stub_children->
last()->entry()->name());
201 bottom_up_root_children[1]->children();
202 CHECK_EQ(0, bottom_up_bbb_children->length());
204 bottom_up_root_children[2]->children();
205 CHECK_EQ(1, bottom_up_ddd_children->length());
206 CHECK_EQ(
"5", bottom_up_ddd_children->last()->entry()->name());
208 bottom_up_ddd_children->
last()->children();
209 CHECK_EQ(1, bottom_up_ddd_stub_children->length());
210 CHECK_EQ(
"bbb", bottom_up_ddd_stub_children->last()->entry()->name());
216 TEST(CrashIfStoppingLastNonExistentProfile) {
218 TestSetup test_setup;
219 CpuProfiler::SetUp();
220 CpuProfiler::StartProfiling(
"1");
221 CpuProfiler::StopProfiling(
"2");
222 CpuProfiler::StartProfiling(
"1");
223 CpuProfiler::StopProfiling(
"");
224 CpuProfiler::TearDown();
231 TestSetup test_setup;
232 CpuProfilesCollection profiles;
233 profiles.StartProfiling(
"", 1);
235 ProfilerEventsProcessor processor(&generator);
238 processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
244 sample->
pc = ToAddress(0x1200);
248 sample->
stack[i] = ToAddress(0x1200);
253 CpuProfile* profile =
254 profiles.StopProfiling(TokenEnumerator::kNoSecurityToken,
"", 1);
257 int actual_depth = 0;
258 const ProfileNode* node = profile->top_down()->root();
259 while (node->children()->length() > 0) {
260 node = node->children()->last();
270 TestSetup test_setup;
271 CpuProfiler::SetUp();
272 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
273 CpuProfiler::DeleteAllProfiles();
274 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
276 CpuProfiler::StartProfiling(
"1");
277 CpuProfiler::StopProfiling(
"1");
278 CHECK_EQ(1, CpuProfiler::GetProfilesCount());
279 CpuProfiler::DeleteAllProfiles();
280 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
281 CpuProfiler::StartProfiling(
"1");
282 CpuProfiler::StartProfiling(
"2");
283 CpuProfiler::StopProfiling(
"2");
284 CpuProfiler::StopProfiling(
"1");
285 CHECK_EQ(2, CpuProfiler::GetProfilesCount());
286 CpuProfiler::DeleteAllProfiles();
287 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
290 CpuProfiler::StartProfiling(
"1");
291 CpuProfiler::StartProfiling(
"2");
292 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
293 CpuProfiler::DeleteAllProfiles();
294 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
296 CpuProfiler::TearDown();
310 unsigned uid1 = p1->
GetUid();
313 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
321 unsigned uid2 = p2->
GetUid();
322 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
330 unsigned uid3 = p3->
GetUid();
331 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
339 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
346 TEST(DeleteCpuProfileDifferentTokens) {
356 unsigned uid1 = p1->
GetUid();
364 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
368 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
376 unsigned uid2 = p2_t2->
GetUid();
377 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
385 unsigned uid3 = p3->
GetUid();
386 CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
397 CHECK_EQ(0, CpuProfiler::GetProfilesCount());
#define CHECK_EQ(expected, value)
static V8EXPORT Local< String > New(const char *data, int length=-1)
static const CpuProfile * FindProfile(unsigned uid, Handle< Value > security_token=Handle< Value >())
Address stack[kMaxFramesCount]
static void StartProfiling(Handle< String > title)
#define CHECK_NE(unexpected, value)
int StrLength(const char *string)
#define T(name, string, precedence)
static const int kMaxFramesCount
static int GetProfilesCount()
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static const CpuProfile * StopProfiling(Handle< String > title, Handle< Value > security_token=Handle< Value >())
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print more details following each garbage collection print amount of external allocated memory after each time it is adjusted flush code that we expect not to use again before full gc do incremental marking steps track object counts and memory usage use caching Perform compaction on every full GC Never perform compaction on full GC testing only Compact code space on full incremental collections Default seed for initializing random generator(0, the default, means to use system random).") DEFINE_bool(use_verbose_printer