OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include "v8.h" |
| 29 |
| 30 #include "cpu-profiler-inl.h" |
| 31 |
| 32 namespace v8 { |
| 33 namespace internal { |
| 34 |
| 35 |
| 36 static const int kEventsBufferSize = 256*KB; |
| 37 static const int kTickSamplesBufferChunkSize = 64*KB; |
| 38 static const int kTickSamplesBufferChunksCount = 16; |
| 39 |
| 40 |
| 41 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) |
| 42 : generator_(generator), |
| 43 running_(false), |
| 44 events_buffer_(kEventsBufferSize), |
| 45 ticks_buffer_(sizeof(TickSampleEventRecord), |
| 46 kTickSamplesBufferChunkSize, |
| 47 kTickSamplesBufferChunksCount), |
| 48 enqueue_order_(0) { } |
| 49 |
| 50 |
| 51 void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 52 String* name, |
| 53 String* resource_name, |
| 54 int line_number, |
| 55 Address start, |
| 56 unsigned size) { |
| 57 CodeEventsContainer evt_rec; |
| 58 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 59 rec->type = CodeEventRecord::CODE_CREATION; |
| 60 rec->order = ++enqueue_order_; |
| 61 rec->start = start; |
| 62 rec->entry = generator_->NewCodeEntry(tag, name, resource_name, line_number); |
| 63 rec->size = size; |
| 64 events_buffer_.Enqueue(evt_rec); |
| 65 } |
| 66 |
| 67 |
| 68 void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 69 const char* name, |
| 70 Address start, |
| 71 unsigned size) { |
| 72 CodeEventsContainer evt_rec; |
| 73 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 74 rec->type = CodeEventRecord::CODE_CREATION; |
| 75 rec->order = ++enqueue_order_; |
| 76 rec->start = start; |
| 77 rec->entry = generator_->NewCodeEntry(tag, name); |
| 78 rec->size = size; |
| 79 events_buffer_.Enqueue(evt_rec); |
| 80 } |
| 81 |
| 82 |
| 83 void ProfilerEventsProcessor::CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 84 int args_count, |
| 85 Address start, |
| 86 unsigned size) { |
| 87 CodeEventsContainer evt_rec; |
| 88 CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_; |
| 89 rec->type = CodeEventRecord::CODE_CREATION; |
| 90 rec->order = ++enqueue_order_; |
| 91 rec->start = start; |
| 92 rec->entry = generator_->NewCodeEntry(tag, args_count); |
| 93 rec->size = size; |
| 94 events_buffer_.Enqueue(evt_rec); |
| 95 } |
| 96 |
| 97 |
| 98 void ProfilerEventsProcessor::CodeMoveEvent(Address from, Address to) { |
| 99 CodeEventsContainer evt_rec; |
| 100 CodeMoveEventRecord* rec = &evt_rec.CodeMoveEventRecord_; |
| 101 rec->type = CodeEventRecord::CODE_MOVE; |
| 102 rec->order = ++enqueue_order_; |
| 103 rec->from = from; |
| 104 rec->to = to; |
| 105 events_buffer_.Enqueue(evt_rec); |
| 106 } |
| 107 |
| 108 |
| 109 void ProfilerEventsProcessor::CodeDeleteEvent(Address from) { |
| 110 CodeEventsContainer evt_rec; |
| 111 CodeDeleteEventRecord* rec = &evt_rec.CodeDeleteEventRecord_; |
| 112 rec->type = CodeEventRecord::CODE_DELETE; |
| 113 rec->order = ++enqueue_order_; |
| 114 rec->start = from; |
| 115 events_buffer_.Enqueue(evt_rec); |
| 116 } |
| 117 |
| 118 |
| 119 void ProfilerEventsProcessor::FunctionCreateEvent(Address alias, |
| 120 Address start) { |
| 121 CodeEventsContainer evt_rec; |
| 122 CodeAliasEventRecord* rec = &evt_rec.CodeAliasEventRecord_; |
| 123 rec->type = CodeEventRecord::CODE_ALIAS; |
| 124 rec->order = ++enqueue_order_; |
| 125 rec->alias = alias; |
| 126 rec->start = start; |
| 127 events_buffer_.Enqueue(evt_rec); |
| 128 } |
| 129 |
| 130 |
| 131 void ProfilerEventsProcessor::FunctionMoveEvent(Address from, Address to) { |
| 132 CodeMoveEvent(from, to); |
| 133 } |
| 134 |
| 135 |
| 136 void ProfilerEventsProcessor::FunctionDeleteEvent(Address from) { |
| 137 CodeDeleteEvent(from); |
| 138 } |
| 139 |
| 140 |
| 141 bool ProfilerEventsProcessor::ProcessCodeEvent(unsigned* dequeue_order) { |
| 142 if (!events_buffer_.IsEmpty()) { |
| 143 CodeEventsContainer record; |
| 144 events_buffer_.Dequeue(&record); |
| 145 switch (record.generic.type) { |
| 146 #define PROFILER_TYPE_CASE(type, clss) \ |
| 147 case CodeEventRecord::type: \ |
| 148 record.clss##_.UpdateCodeMap(generator_->code_map()); \ |
| 149 break; |
| 150 |
| 151 CODE_EVENTS_TYPE_LIST(PROFILER_TYPE_CASE) |
| 152 |
| 153 #undef PROFILER_TYPE_CASE |
| 154 default: return true; // Skip record. |
| 155 } |
| 156 *dequeue_order = record.generic.order; |
| 157 return true; |
| 158 } |
| 159 return false; |
| 160 } |
| 161 |
| 162 |
| 163 bool ProfilerEventsProcessor::ProcessTicks(unsigned dequeue_order) { |
| 164 while (true) { |
| 165 const TickSampleEventRecord* rec = |
| 166 reinterpret_cast<TickSampleEventRecord*>(ticks_buffer_.StartDequeue()); |
| 167 if (rec == NULL) return false; |
| 168 if (rec->order == dequeue_order) { |
| 169 generator_->RecordTickSample(rec->sample); |
| 170 ticks_buffer_.FinishDequeue(); |
| 171 } else { |
| 172 return true; |
| 173 } |
| 174 } |
| 175 } |
| 176 |
| 177 |
| 178 void ProfilerEventsProcessor::Run() { |
| 179 ticks_buffer_.SetUpConsumer(); |
| 180 unsigned dequeue_order = 0; |
| 181 running_ = true; |
| 182 |
| 183 while (running_) { |
| 184 // Process ticks until we have any. |
| 185 if (ProcessTicks(dequeue_order)) { |
| 186 // All ticks of the current dequeue_order are processed, |
| 187 // proceed to the next code event. |
| 188 ProcessCodeEvent(&dequeue_order); |
| 189 } |
| 190 YieldCPU(); |
| 191 } |
| 192 |
| 193 // Process remaining tick events. |
| 194 ticks_buffer_.FlushResidualRecords(); |
| 195 // Perform processing until we have tick events, skip remaining code events. |
| 196 while (ProcessTicks(dequeue_order) && ProcessCodeEvent(&dequeue_order)) { } |
| 197 ticks_buffer_.TearDownConsumer(); |
| 198 } |
| 199 |
| 200 |
| 201 } } // namespace v8::internal |
OLD | NEW |