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

Side by Side Diff: src/cpu-profiler.cc

Issue 151603004: A64: Synchronize with r16587. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/cpu-profiler.h ('k') | src/d8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 #undef PROFILER_TYPE_CASE 97 #undef PROFILER_TYPE_CASE
98 default: return true; // Skip record. 98 default: return true; // Skip record.
99 } 99 }
100 last_processed_code_event_id_ = record.generic.order; 100 last_processed_code_event_id_ = record.generic.order;
101 return true; 101 return true;
102 } 102 }
103 return false; 103 return false;
104 } 104 }
105 105
106 ProfilerEventsProcessor::SampleProcessingResult
107 ProfilerEventsProcessor::ProcessOneSample() {
108 if (!ticks_from_vm_buffer_.IsEmpty()
109 && ticks_from_vm_buffer_.Peek()->order ==
110 last_processed_code_event_id_) {
111 TickSampleEventRecord record;
112 ticks_from_vm_buffer_.Dequeue(&record);
113 generator_->RecordTickSample(record.sample);
114 return OneSampleProcessed;
115 }
106 116
107 bool ProfilerEventsProcessor::ProcessTicks() { 117 const TickSampleEventRecord* record = ticks_buffer_.Peek();
108 while (true) { 118 if (record == NULL) {
109 while (!ticks_from_vm_buffer_.IsEmpty() 119 if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue;
110 && ticks_from_vm_buffer_.Peek()->order == 120 return FoundSampleForNextCodeEvent;
111 last_processed_code_event_id_) {
112 TickSampleEventRecord record;
113 ticks_from_vm_buffer_.Dequeue(&record);
114 generator_->RecordTickSample(record.sample);
115 }
116
117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
119 if (record->order != last_processed_code_event_id_) return true;
120 generator_->RecordTickSample(record->sample);
121 ticks_buffer_.FinishDequeue();
122 } 121 }
123 } 122 if (record->order != last_processed_code_event_id_) {
124 123 return FoundSampleForNextCodeEvent;
125
126 void ProfilerEventsProcessor::ProcessEventsAndDoSample() {
127 ElapsedTimer timer;
128 timer.Start();
129 // Keep processing existing events until we need to do next sample.
130 while (!timer.HasExpired(period_)) {
131 if (ProcessTicks()) {
132 // All ticks of the current dequeue_order are processed,
133 // proceed to the next code event.
134 ProcessCodeEvent();
135 }
136 } 124 }
137 // Schedule next sample. sampler_ is NULL in tests. 125 generator_->RecordTickSample(record->sample);
138 if (sampler_) sampler_->DoSample(); 126 ticks_buffer_.Remove();
127 return OneSampleProcessed;
139 } 128 }
140 129
141 130
142 void ProfilerEventsProcessor::Run() { 131 void ProfilerEventsProcessor::Run() {
143 while (running_) { 132 while (running_) {
144 ProcessEventsAndDoSample(); 133 ElapsedTimer timer;
134 timer.Start();
135 // Keep processing existing events until we need to do next sample.
136 do {
137 if (FoundSampleForNextCodeEvent == ProcessOneSample()) {
138 // All ticks of the current last_processed_code_event_id_ are
139 // processed, proceed to the next code event.
140 ProcessCodeEvent();
141 }
142 } while (!timer.HasExpired(period_));
143
144 // Schedule next sample. sampler_ is NULL in tests.
145 if (sampler_) sampler_->DoSample();
145 } 146 }
146 147
147 // Process remaining tick events. 148 // Process remaining tick events.
148 do { 149 do {
149 ProcessTicks(); 150 SampleProcessingResult result;
151 do {
152 result = ProcessOneSample();
153 } while (result == OneSampleProcessed);
150 } while (ProcessCodeEvent()); 154 } while (ProcessCodeEvent());
151 } 155 }
152 156
153 157
154 int CpuProfiler::GetProfilesCount() { 158 int CpuProfiler::GetProfilesCount() {
155 // The count of profiles doesn't depend on a security token. 159 // The count of profiles doesn't depend on a security token.
156 return profiles_->profiles()->length(); 160 return profiles_->profiles()->length();
157 } 161 }
158 162
159 163
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; 240 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
237 rec->start = code->address(); 241 rec->start = code->address();
238 rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name)); 242 rec->entry = profiles_->NewCodeEntry(tag, profiles_->GetFunctionName(name));
239 if (info) { 243 if (info) {
240 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges()); 244 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
241 } 245 }
242 if (shared->script()->IsScript()) { 246 if (shared->script()->IsScript()) {
243 ASSERT(Script::cast(shared->script())); 247 ASSERT(Script::cast(shared->script()));
244 Script* script = Script::cast(shared->script()); 248 Script* script = Script::cast(shared->script());
245 rec->entry->set_script_id(script->id()->value()); 249 rec->entry->set_script_id(script->id()->value());
250 rec->entry->set_bailout_reason(
251 GetBailoutReason(shared->DisableOptimizationReason()));
246 } 252 }
247 rec->size = code->ExecutableSize(); 253 rec->size = code->ExecutableSize();
248 rec->shared = shared->address(); 254 rec->shared = shared->address();
249 processor_->Enqueue(evt_rec); 255 processor_->Enqueue(evt_rec);
250 } 256 }
251 257
252 258
253 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 259 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
254 Code* code, 260 Code* code,
255 SharedFunctionInfo* shared, 261 SharedFunctionInfo* shared,
(...skipping 10 matching lines...) Expand all
266 profiles_->GetName(source), 272 profiles_->GetName(source),
267 line); 273 line);
268 if (info) { 274 if (info) {
269 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges()); 275 rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
270 } 276 }
271 ASSERT(Script::cast(shared->script())); 277 ASSERT(Script::cast(shared->script()));
272 Script* script = Script::cast(shared->script()); 278 Script* script = Script::cast(shared->script());
273 rec->entry->set_script_id(script->id()->value()); 279 rec->entry->set_script_id(script->id()->value());
274 rec->size = code->ExecutableSize(); 280 rec->size = code->ExecutableSize();
275 rec->shared = shared->address(); 281 rec->shared = shared->address();
282 rec->entry->set_bailout_reason(
283 GetBailoutReason(shared->DisableOptimizationReason()));
276 processor_->Enqueue(evt_rec); 284 processor_->Enqueue(evt_rec);
277 } 285 }
278 286
279 287
280 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, 288 void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
281 Code* code, 289 Code* code,
282 int args_count) { 290 int args_count) {
283 if (FilterOutCodeCreateEvent(tag)) return; 291 if (FilterOutCodeCreateEvent(tag)) return;
284 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION); 292 CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
285 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; 293 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 profiles_->GetName(name), 364 profiles_->GetName(name),
357 "set "); 365 "set ");
358 rec->size = 1; 366 rec->size = 1;
359 rec->shared = NULL; 367 rec->shared = NULL;
360 processor_->Enqueue(evt_rec); 368 processor_->Enqueue(evt_rec);
361 } 369 }
362 370
363 371
364 CpuProfiler::CpuProfiler(Isolate* isolate) 372 CpuProfiler::CpuProfiler(Isolate* isolate)
365 : isolate_(isolate), 373 : isolate_(isolate),
374 sampling_interval_(TimeDelta::FromMicroseconds(
375 FLAG_cpu_profiler_sampling_interval)),
366 profiles_(new CpuProfilesCollection()), 376 profiles_(new CpuProfilesCollection()),
367 next_profile_uid_(1), 377 next_profile_uid_(1),
368 generator_(NULL), 378 generator_(NULL),
369 processor_(NULL), 379 processor_(NULL),
370 is_profiling_(false) { 380 is_profiling_(false) {
371 } 381 }
372 382
373 383
374 CpuProfiler::CpuProfiler(Isolate* isolate, 384 CpuProfiler::CpuProfiler(Isolate* isolate,
375 CpuProfilesCollection* test_profiles, 385 CpuProfilesCollection* test_profiles,
376 ProfileGenerator* test_generator, 386 ProfileGenerator* test_generator,
377 ProfilerEventsProcessor* test_processor) 387 ProfilerEventsProcessor* test_processor)
378 : isolate_(isolate), 388 : isolate_(isolate),
389 sampling_interval_(TimeDelta::FromMicroseconds(
390 FLAG_cpu_profiler_sampling_interval)),
379 profiles_(test_profiles), 391 profiles_(test_profiles),
380 next_profile_uid_(1), 392 next_profile_uid_(1),
381 generator_(test_generator), 393 generator_(test_generator),
382 processor_(test_processor), 394 processor_(test_processor),
383 is_profiling_(false) { 395 is_profiling_(false) {
384 } 396 }
385 397
386 398
387 CpuProfiler::~CpuProfiler() { 399 CpuProfiler::~CpuProfiler() {
388 ASSERT(!is_profiling_); 400 ASSERT(!is_profiling_);
389 delete profiles_; 401 delete profiles_;
390 } 402 }
391 403
392 404
405 void CpuProfiler::set_sampling_interval(TimeDelta value) {
406 ASSERT(!is_profiling_);
407 sampling_interval_ = value;
408 }
409
410
393 void CpuProfiler::ResetProfiles() { 411 void CpuProfiler::ResetProfiles() {
394 delete profiles_; 412 delete profiles_;
395 profiles_ = new CpuProfilesCollection(); 413 profiles_ = new CpuProfilesCollection();
396 } 414 }
397 415
398 416
399 void CpuProfiler::StartProfiling(const char* title, bool record_samples) { 417 void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
400 if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) { 418 if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) {
401 StartProcessorIfNotStarted(); 419 StartProcessorIfNotStarted();
402 } 420 }
403 processor_->AddCurrentStack(isolate_); 421 processor_->AddCurrentStack(isolate_);
404 } 422 }
405 423
406 424
407 void CpuProfiler::StartProfiling(String* title, bool record_samples) { 425 void CpuProfiler::StartProfiling(String* title, bool record_samples) {
408 StartProfiling(profiles_->GetName(title), record_samples); 426 StartProfiling(profiles_->GetName(title), record_samples);
409 } 427 }
410 428
411 429
412 void CpuProfiler::StartProcessorIfNotStarted() { 430 void CpuProfiler::StartProcessorIfNotStarted() {
413 if (processor_ == NULL) { 431 if (processor_ == NULL) {
414 Logger* logger = isolate_->logger(); 432 Logger* logger = isolate_->logger();
415 // Disable logging when using the new implementation. 433 // Disable logging when using the new implementation.
416 saved_is_logging_ = logger->is_logging_; 434 saved_is_logging_ = logger->is_logging_;
417 logger->is_logging_ = false; 435 logger->is_logging_ = false;
418 generator_ = new ProfileGenerator(profiles_); 436 generator_ = new ProfileGenerator(profiles_);
419 Sampler* sampler = logger->sampler(); 437 Sampler* sampler = logger->sampler();
420 processor_ = new ProfilerEventsProcessor( 438 processor_ = new ProfilerEventsProcessor(
421 generator_, sampler, 439 generator_, sampler, sampling_interval_);
422 TimeDelta::FromMicroseconds(FLAG_cpu_profiler_sampling_interval));
423 is_profiling_ = true; 440 is_profiling_ = true;
424 // Enumerate stuff we already have in the heap. 441 // Enumerate stuff we already have in the heap.
425 ASSERT(isolate_->heap()->HasBeenSetUp()); 442 ASSERT(isolate_->heap()->HasBeenSetUp());
426 if (!FLAG_prof_browser_mode) { 443 if (!FLAG_prof_browser_mode) {
427 logger->LogCodeObjects(); 444 logger->LogCodeObjects();
428 } 445 }
429 logger->LogCompiledFunctions(); 446 logger->LogCompiledFunctions();
430 logger->LogAccessorCallbacks(); 447 logger->LogAccessorCallbacks();
431 LogBuiltins(); 448 LogBuiltins();
432 // Enable stack sampling. 449 // Enable stack sampling.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; 501 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
485 Builtins::Name id = static_cast<Builtins::Name>(i); 502 Builtins::Name id = static_cast<Builtins::Name>(i);
486 rec->start = builtins->builtin(id)->address(); 503 rec->start = builtins->builtin(id)->address();
487 rec->builtin_id = id; 504 rec->builtin_id = id;
488 processor_->Enqueue(evt_rec); 505 processor_->Enqueue(evt_rec);
489 } 506 }
490 } 507 }
491 508
492 509
493 } } // namespace v8::internal 510 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698