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

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

Issue 23455036: Check if timeout has expired after processing each sample (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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') | no next file » | 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;
loislo 2013/09/05 14:56:51 I'd move this statement to line 109
yurys 2013/09/05 15:00:03 Along with lines 117 and 118? Note that we need to
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_.Peek();
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_.Remove();
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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; 501 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
498 Builtins::Name id = static_cast<Builtins::Name>(i); 502 Builtins::Name id = static_cast<Builtins::Name>(i);
499 rec->start = builtins->builtin(id)->address(); 503 rec->start = builtins->builtin(id)->address();
500 rec->builtin_id = id; 504 rec->builtin_id = id;
501 processor_->Enqueue(evt_rec); 505 processor_->Enqueue(evt_rec);
502 } 506 }
503 } 507 }
504 508
505 509
506 } } // namespace v8::internal 510 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698