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

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

Issue 23469013: Reland "Add Chromium-style TimeDelta, Time and TimeTicks classes, and a new ElapsedTimer class." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 7 years, 3 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/deoptimizer.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 28 matching lines...) Expand all
39 39
40 namespace v8 { 40 namespace v8 {
41 namespace internal { 41 namespace internal {
42 42
43 static const int kProfilerStackSize = 64 * KB; 43 static const int kProfilerStackSize = 64 * KB;
44 44
45 45
46 ProfilerEventsProcessor::ProfilerEventsProcessor( 46 ProfilerEventsProcessor::ProfilerEventsProcessor(
47 ProfileGenerator* generator, 47 ProfileGenerator* generator,
48 Sampler* sampler, 48 Sampler* sampler,
49 int period_in_useconds) 49 TimeDelta period)
50 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 50 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
51 generator_(generator), 51 generator_(generator),
52 sampler_(sampler), 52 sampler_(sampler),
53 running_(true), 53 running_(true),
54 period_in_useconds_(period_in_useconds), 54 period_(period),
55 last_code_event_id_(0), last_processed_code_event_id_(0) { 55 last_code_event_id_(0), last_processed_code_event_id_(0) {
56 } 56 }
57 57
58 58
59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { 59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
60 event.generic.order = ++last_code_event_id_; 60 event.generic.order = ++last_code_event_id_;
61 events_buffer_.Enqueue(event); 61 events_buffer_.Enqueue(event);
62 } 62 }
63 63
64 64
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue(); 117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty(); 118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
119 if (record->order != last_processed_code_event_id_) return true; 119 if (record->order != last_processed_code_event_id_) return true;
120 generator_->RecordTickSample(record->sample); 120 generator_->RecordTickSample(record->sample);
121 ticks_buffer_.FinishDequeue(); 121 ticks_buffer_.FinishDequeue();
122 } 122 }
123 } 123 }
124 124
125 125
126 void ProfilerEventsProcessor::ProcessEventsAndDoSample() { 126 void ProfilerEventsProcessor::ProcessEventsAndDoSample() {
127 int64_t stop_time = OS::Ticks() + period_in_useconds_; 127 ElapsedTimer timer;
128 timer.Start();
128 // Keep processing existing events until we need to do next sample. 129 // Keep processing existing events until we need to do next sample.
129 while (OS::Ticks() < stop_time) { 130 while (!timer.HasExpired(period_)) {
130 if (ProcessTicks()) { 131 if (ProcessTicks()) {
131 // All ticks of the current dequeue_order are processed, 132 // All ticks of the current dequeue_order are processed,
132 // proceed to the next code event. 133 // proceed to the next code event.
133 ProcessCodeEvent(); 134 ProcessCodeEvent();
134 } 135 }
135 } 136 }
136 // Schedule next sample. sampler_ is NULL in tests. 137 // Schedule next sample. sampler_ is NULL in tests.
137 if (sampler_) sampler_->DoSample(); 138 if (sampler_) sampler_->DoSample();
138 } 139 }
139 140
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 428
428 void CpuProfiler::StartProcessorIfNotStarted() { 429 void CpuProfiler::StartProcessorIfNotStarted() {
429 if (processor_ == NULL) { 430 if (processor_ == NULL) {
430 Logger* logger = isolate_->logger(); 431 Logger* logger = isolate_->logger();
431 // Disable logging when using the new implementation. 432 // Disable logging when using the new implementation.
432 saved_logging_nesting_ = logger->logging_nesting_; 433 saved_logging_nesting_ = logger->logging_nesting_;
433 logger->logging_nesting_ = 0; 434 logger->logging_nesting_ = 0;
434 generator_ = new ProfileGenerator(profiles_); 435 generator_ = new ProfileGenerator(profiles_);
435 Sampler* sampler = logger->sampler(); 436 Sampler* sampler = logger->sampler();
436 processor_ = new ProfilerEventsProcessor( 437 processor_ = new ProfilerEventsProcessor(
437 generator_, sampler, FLAG_cpu_profiler_sampling_interval); 438 generator_, sampler,
439 TimeDelta::FromMicroseconds(FLAG_cpu_profiler_sampling_interval));
438 is_profiling_ = true; 440 is_profiling_ = true;
439 // Enumerate stuff we already have in the heap. 441 // Enumerate stuff we already have in the heap.
440 ASSERT(isolate_->heap()->HasBeenSetUp()); 442 ASSERT(isolate_->heap()->HasBeenSetUp());
441 if (!FLAG_prof_browser_mode) { 443 if (!FLAG_prof_browser_mode) {
442 logger->LogCodeObjects(); 444 logger->LogCodeObjects();
443 } 445 }
444 logger->LogCompiledFunctions(); 446 logger->LogCompiledFunctions();
445 logger->LogAccessorCallbacks(); 447 logger->LogAccessorCallbacks();
446 LogBuiltins(); 448 LogBuiltins();
447 // Enable stack sampling. 449 // Enable stack sampling.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; 513 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
512 Builtins::Name id = static_cast<Builtins::Name>(i); 514 Builtins::Name id = static_cast<Builtins::Name>(i);
513 rec->start = builtins->builtin(id)->address(); 515 rec->start = builtins->builtin(id)->address();
514 rec->builtin_id = id; 516 rec->builtin_id = id;
515 processor_->Enqueue(evt_rec); 517 processor_->Enqueue(evt_rec);
516 } 518 }
517 } 519 }
518 520
519 521
520 } } // namespace v8::internal 522 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/deoptimizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698