OLD | NEW |
---|---|
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 106 |
107 bool ProfilerEventsProcessor::ProcessTicks() { | 107 bool ProfilerEventsProcessor::ProcessOneSample() { |
108 while (true) { | 108 if (!ticks_from_vm_buffer_.IsEmpty() |
109 while (!ticks_from_vm_buffer_.IsEmpty() | 109 && ticks_from_vm_buffer_.Peek()->order == |
110 && ticks_from_vm_buffer_.Peek()->order == | 110 last_processed_code_event_id_) { |
111 last_processed_code_event_id_) { | 111 TickSampleEventRecord record; |
112 TickSampleEventRecord record; | 112 ticks_from_vm_buffer_.Dequeue(&record); |
113 ticks_from_vm_buffer_.Dequeue(&record); | 113 generator_->RecordTickSample(record.sample); |
114 generator_->RecordTickSample(record.sample); | 114 return false; |
115 } | 115 } |
116 | 116 |
117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue(); | 117 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue(); |
loislo
2013/09/04 14:35:37
please rename StartDequeue to peek and FinishDeque
| |
118 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty(); | 118 if (record == NULL) return true; |
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 return false; |
123 } | |
124 | |
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 } | |
137 // Schedule next sample. sampler_ is NULL in tests. | |
138 if (sampler_) sampler_->DoSample(); | |
139 } | 123 } |
140 | 124 |
141 | 125 |
142 void ProfilerEventsProcessor::Run() { | 126 void ProfilerEventsProcessor::Run() { |
143 while (running_) { | 127 while (running_) { |
144 ProcessEventsAndDoSample(); | 128 ElapsedTimer timer; |
129 timer.Start(); | |
130 // Keep processing existing events until we need to do next sample. | |
131 do { | |
132 if (ProcessOneSample()) { | |
133 // All ticks of the current last_processed_code_event_id_ are | |
134 // processed, proceed to the next code event. | |
135 ProcessCodeEvent(); | |
136 } | |
137 } while (!timer.HasExpired(period_)); | |
138 | |
139 // Schedule next sample. sampler_ is NULL in tests. | |
140 if (sampler_) sampler_->DoSample(); | |
145 } | 141 } |
146 | 142 |
147 // Process remaining tick events. | 143 // Process remaining tick events. |
148 do { | 144 do { |
149 ProcessTicks(); | 145 while (!ProcessOneSample()); |
150 } while (ProcessCodeEvent()); | 146 } while (ProcessCodeEvent()); |
151 } | 147 } |
152 | 148 |
153 | 149 |
154 int CpuProfiler::GetProfilesCount() { | 150 int CpuProfiler::GetProfilesCount() { |
155 // The count of profiles doesn't depend on a security token. | 151 // The count of profiles doesn't depend on a security token. |
156 return profiles_->profiles()->length(); | 152 return profiles_->profiles()->length(); |
157 } | 153 } |
158 | 154 |
159 | 155 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 489 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
494 Builtins::Name id = static_cast<Builtins::Name>(i); | 490 Builtins::Name id = static_cast<Builtins::Name>(i); |
495 rec->start = builtins->builtin(id)->address(); | 491 rec->start = builtins->builtin(id)->address(); |
496 rec->builtin_id = id; | 492 rec->builtin_id = id; |
497 processor_->Enqueue(evt_rec); | 493 processor_->Enqueue(evt_rec); |
498 } | 494 } |
499 } | 495 } |
500 | 496 |
501 | 497 |
502 } } // namespace v8::internal | 498 } } // namespace v8::internal |
OLD | NEW |