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

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: Don't create extra copy of event 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
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; 43 static const size_t kTickSampleBufferSize = 1 * MB;
44 static const int kTickSamplesBufferChunksCount = 16;
45 static const int kProfilerStackSize = 64 * KB; 44 static const int kProfilerStackSize = 64 * KB;
46 45
47 46
48 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator) 47 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
49 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), 48 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)),
50 generator_(generator), 49 generator_(generator),
51 running_(true), 50 running_(true),
52 ticks_buffer_(sizeof(TickSampleEventRecord), 51 ticks_buffer_(sizeof(TickSampleEventRecord),
53 kTickSamplesBufferChunkSize, 52 kTickSampleBufferSize / sizeof(TickSampleEventRecord)),
54 kTickSamplesBufferChunksCount),
55 last_code_event_id_(0), last_processed_code_event_id_(0) { 53 last_code_event_id_(0), last_processed_code_event_id_(0) {
56 } 54 }
57 55
58 56
59 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) { 57 void ProfilerEventsProcessor::Enqueue(const CodeEventsContainer& event) {
60 event.generic.order = ++last_code_event_id_; 58 event.generic.order = ++last_code_event_id_;
61 events_buffer_.Enqueue(event); 59 events_buffer_.Enqueue(event);
62 } 60 }
63 61
64 62
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool ProfilerEventsProcessor::ProcessTicks() { 105 bool ProfilerEventsProcessor::ProcessTicks() {
108 while (true) { 106 while (true) {
109 while (!ticks_from_vm_buffer_.IsEmpty() 107 while (!ticks_from_vm_buffer_.IsEmpty()
110 && ticks_from_vm_buffer_.Peek()->order == 108 && ticks_from_vm_buffer_.Peek()->order ==
111 last_processed_code_event_id_) { 109 last_processed_code_event_id_) {
112 TickSampleEventRecord record; 110 TickSampleEventRecord record;
113 ticks_from_vm_buffer_.Dequeue(&record); 111 ticks_from_vm_buffer_.Dequeue(&record);
114 generator_->RecordTickSample(record.sample); 112 generator_->RecordTickSample(record.sample);
115 } 113 }
116 114
117 const TickSampleEventRecord* rec = 115 const TickSampleEventRecord* record =
118 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue()); 116 TickSampleEventRecord::cast(ticks_buffer_.StartDequeue());
119 if (rec == NULL) return !ticks_from_vm_buffer_.IsEmpty(); 117 if (record == NULL) return !ticks_from_vm_buffer_.IsEmpty();
120 // Make a local copy of tick sample record to ensure that it won't 118 // Make a local copy of tick sample record to ensure that it won't
121 // be modified as we are processing it. This is possible as the 119 // 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 120 // 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 121 // will get far behind, a record may be modified right under its
124 // feet. 122 // feet.
Benedikt Meurer 2013/08/13 09:31:32 We do no longer make a local copy here, so this co
yurys 2013/08/13 14:10:29 Done.
125 TickSampleEventRecord record = *rec; 123 if (record->order != last_processed_code_event_id_) return true;
126 if (record.order != last_processed_code_event_id_) return true; 124 generator_->RecordTickSample(record->sample);
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(); 125 ticks_buffer_.FinishDequeue();
135 } 126 }
136 } 127 }
137 128
138 129
139 void ProfilerEventsProcessor::Run() { 130 void ProfilerEventsProcessor::Run() {
140 while (running_) { 131 while (running_) {
141 // Process ticks until we have any. 132 // Process ticks until we have any.
142 if (ProcessTicks()) { 133 if (ProcessTicks()) {
143 // All ticks of the current last_processed_code_event_id_ are processed, 134 // All ticks of the current last_processed_code_event_id_ are processed,
144 // proceed to the next code event. 135 // proceed to the next code event.
145 ProcessCodeEvent(); 136 ProcessCodeEvent();
146 } 137 }
147 YieldCPU(); 138 YieldCPU();
148 } 139 }
149 140
150 // Process remaining tick events. 141 // Process remaining tick events.
151 ticks_buffer_.FlushResidualRecords();
152 do { 142 do {
153 ProcessTicks(); 143 ProcessTicks();
154 } while (ProcessCodeEvent()); 144 } while (ProcessCodeEvent());
155 } 145 }
156 146
157 147
158 int CpuProfiler::GetProfilesCount() { 148 int CpuProfiler::GetProfilesCount() {
159 // The count of profiles doesn't depend on a security token. 149 // The count of profiles doesn't depend on a security token.
160 return profiles_->profiles()->length(); 150 return profiles_->profiles()->length();
161 } 151 }
162 152
163 153
164 CpuProfile* CpuProfiler::GetProfile(int index) { 154 CpuProfile* CpuProfiler::GetProfile(int index) {
165 return profiles_->profiles()->at(index); 155 return profiles_->profiles()->at(index);
166 } 156 }
167 157
168 158
169 TickSample* CpuProfiler::TickSampleEvent() {
170 if (is_profiling_) return processor_->TickSampleEvent();
171 return NULL;
172 }
173
174
175 void CpuProfiler::DeleteAllProfiles() { 159 void CpuProfiler::DeleteAllProfiles() {
176 if (is_profiling_) StopProcessor(); 160 if (is_profiling_) StopProcessor();
177 ResetProfiles(); 161 ResetProfiles();
178 } 162 }
179 163
180 164
181 void CpuProfiler::DeleteProfile(CpuProfile* profile) { 165 void CpuProfiler::DeleteProfile(CpuProfile* profile) {
182 profiles_->RemoveProfile(profile); 166 profiles_->RemoveProfile(profile);
183 delete profile; 167 delete profile;
184 } 168 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; 484 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_;
501 Builtins::Name id = static_cast<Builtins::Name>(i); 485 Builtins::Name id = static_cast<Builtins::Name>(i);
502 rec->start = builtins->builtin(id)->address(); 486 rec->start = builtins->builtin(id)->address();
503 rec->builtin_id = id; 487 rec->builtin_id = id;
504 processor_->Enqueue(evt_rec); 488 processor_->Enqueue(evt_rec);
505 } 489 }
506 } 490 }
507 491
508 492
509 } } // namespace v8::internal 493 } } // namespace v8::internal
OLDNEW
« src/circular-queue-inl.h ('K') | « 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