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

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

Issue 22849002: Rewrite SamplingCircularQueue (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use V8_ALIGNAS from include/v8config.h Created 7 years, 4 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/cpu-profiler-inl.h » ('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 22 matching lines...) Expand all
33 #include "frames-inl.h" 33 #include "frames-inl.h"
34 #include "hashmap.h" 34 #include "hashmap.h"
35 #include "log-inl.h" 35 #include "log-inl.h"
36 #include "vm-state-inl.h" 36 #include "vm-state-inl.h"
37 37
38 #include "../include/v8-profiler.h" 38 #include "../include/v8-profiler.h"
39 39
40 namespace v8 { 40 namespace v8 {
41 namespace internal { 41 namespace internal {
42 42
43 static const int kTickSamplesBufferChunkSize = 64 * KB;
44 static const int kTickSamplesBufferChunksCount = 16;
45 static const int kProfilerStackSize = 64 * KB; 43 static const int kProfilerStackSize = 64 * KB;
46 44
47 45
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) 46 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 47 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
50 generator_(generator), 48 generator_(generator),
51 running_(true), 49 running_(true),
52 ticks_buffer_(sizeof(TickSampleEventRecord),
53 kTickSamplesBufferChunkSize,
54 kTickSamplesBufferChunksCount),
55 last_code_event_id_(0), last_processed_code_event_id_(0) { 50 last_code_event_id_(0), last_processed_code_event_id_(0) {
56 } 51 }
57 52
58 53
59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { 54 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
60 event.generic.order = ++last_code_event_id_; 55 event.generic.order = ++last_code_event_id_;
61 events_buffer_.Enqueue(event); 56 events_buffer_.Enqueue(event);
62 } 57 }
63 58
64 59
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool ProfilerEventsProcessor::ProcessTicks() { 102 bool ProfilerEventsProcessor::ProcessTicks() {
108 while (true) { 103 while (true) {
109 while (!ticks_from_vm_buffer_.IsEmpty() 104 while (!ticks_from_vm_buffer_.IsEmpty()
110 && ticks_from_vm_buffer_.Peek()->order == 105 && ticks_from_vm_buffer_.Peek()->order ==
111 last_processed_code_event_id_) { 106 last_processed_code_event_id_) {
112 TickSampleEventRecord record; 107 TickSampleEventRecord record;
113 ticks_from_vm_buffer_.Dequeue(&record); 108 ticks_from_vm_buffer_.Dequeue(&record);
114 generator_->RecordTickSample(record.sample); 109 generator_->RecordTickSample(record.sample);
115 } 110 }
116 111
117 const TickSampleEventRecord* rec = 112 const TickSampleEventRecord* record = ticks_buffer_.StartDequeue();
118 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); 113 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
119 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); 114 if (record->order != last_processed_code_event_id_) return true;
120 // Make a local copy of tick sample record to ensure that it won't 115 generator_->RecordTickSample(record->sample);
121 // be modified as we are processing it. This is possible as the
122 // sampler writes w/o any sync to the queue, so if the processor
123 // will get far behind, a record may be modified right under its
124 // feet.
125 TickSampleEventRecord record = *rec;
126 if (record.order != last_processed_code_event_id_) return true;
127
128 // A paranoid check to make sure that we don't get a memory overrun
129 // in case of frames_count having a wild value.
130 if (record.sample.frames_count < 0
131 || record.sample.frames_count > TickSample::kMaxFramesCount)
132 record.sample.frames_count = 0;
133 generator_->RecordTickSample(record.sample);
134 ticks_buffer_.FinishDequeue(); 116 ticks_buffer_.FinishDequeue();
135 } 117 }
136 } 118 }
137 119
138 120
139 void ProfilerEventsProcessor::Run() { 121 void ProfilerEventsProcessor::Run() {
140 while (running_) { 122 while (running_) {
141 // Process ticks until we have any. 123 // Process ticks until we have any.
142 if (ProcessTicks()) { 124 if (ProcessTicks()) {
143 // All ticks of the current last_processed_code_event_id_ are processed, 125 // All ticks of the current last_processed_code_event_id_ are processed,
144 // proceed to the next code event. 126 // proceed to the next code event.
145 ProcessCodeEvent(); 127 ProcessCodeEvent();
146 } 128 }
147 YieldCPU(); 129 YieldCPU();
148 } 130 }
149 131
150 // Process remaining tick events. 132 // Process remaining tick events.
151 ticks_buffer_.FlushResidualRecords();
152 do { 133 do {
153 ProcessTicks(); 134 ProcessTicks();
154 } while (ProcessCodeEvent()); 135 } while (ProcessCodeEvent());
155 } 136 }
156 137
157 138
158 int CpuProfiler::GetProfilesCount() { 139 int CpuProfiler::GetProfilesCount() {
159 // The count of profiles doesn't depend on a security token. 140 // The count of profiles doesn't depend on a security token.
160 return profiles_->profiles()->length(); 141 return profiles_->profiles()->length();
161 } 142 }
162 143
163 144
164 CpuProfile* CpuProfiler::GetProfile(int index) { 145 CpuProfile* CpuProfiler::GetProfile(int index) {
165 return profiles_->profiles()->at(index); 146 return profiles_->profiles()->at(index);
166 } 147 }
167 148
168 149
169 TickSample* CpuProfiler::TickSampleEvent() {
170 if (is_profiling_) return processor_->TickSampleEvent();
171 return NULL;
172 }
173
174
175 void CpuProfiler::DeleteAllProfiles() { 150 void CpuProfiler::DeleteAllProfiles() {
176 if (is_profiling_) StopProcessor(); 151 if (is_profiling_) StopProcessor();
177 ResetProfiles(); 152 ResetProfiles();
178 } 153 }
179 154
180 155
181 void CpuProfiler::DeleteProfile(CpuProfile* profile) { 156 void CpuProfiler::DeleteProfile(CpuProfile* profile) {
182 profiles_->RemoveProfile(profile); 157 profiles_->RemoveProfile(profile);
183 delete profile; 158 delete profile;
184 } 159 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; 475 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
501 Builtins::Name id = static_cast<Builtins::Name>(i); 476 Builtins::Name id = static_cast<Builtins::Name>(i);
502 rec->start = builtins->builtin(id)->address(); 477 rec->start = builtins->builtin(id)->address();
503 rec->builtin_id = id; 478 rec->builtin_id = id;
504 processor_->Enqueue(evt_rec); 479 processor_->Enqueue(evt_rec);
505 } 480 }
506 } 481 }
507 482
508 483
509 } } // namespace v8::internal 484 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cpu-profiler.h ('k') | src/cpu-profiler-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698