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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 int filler; | 115 int filler; |
116 unsigned order; | 116 unsigned order; |
117 TickSample sample; | 117 TickSample sample; |
118 | 118 |
119 static TickSampleEventRecord* cast(void* value) { | 119 static TickSampleEventRecord* cast(void* value) { |
120 return reinterpret_cast<TickSampleEventRecord*>(value); | 120 return reinterpret_cast<TickSampleEventRecord*>(value); |
121 } | 121 } |
122 }; | 122 }; |
123 | 123 |
124 | 124 |
125 class CodeEventsContainer { | |
126 public: | |
127 explicit CodeEventsContainer( | |
128 CodeEventRecord::Type type = CodeEventRecord::NONE) { | |
129 generic.type = type; | |
130 } | |
131 union { | |
132 CodeEventRecord generic; | |
133 #define DECLARE_CLASS(ignore, type) type type##_; | |
134 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | |
135 #undef DECLARE_TYPE | |
136 }; | |
137 }; | |
138 | |
139 | |
125 // This class implements both the profile events processor thread and | 140 // This class implements both the profile events processor thread and |
126 // methods called by event producers: VM and stack sampler threads. | 141 // methods called by event producers: VM and stack sampler threads. |
127 class ProfilerEventsProcessor : public Thread { | 142 class ProfilerEventsProcessor : public Thread { |
128 public: | 143 public: |
129 ProfilerEventsProcessor(ProfileGenerator* generator, | 144 ProfilerEventsProcessor(ProfileGenerator* generator, |
130 CpuProfilesCollection* profiles); | 145 CpuProfilesCollection* profiles); |
131 virtual ~ProfilerEventsProcessor() {} | 146 virtual ~ProfilerEventsProcessor() {} |
132 | 147 |
133 // Thread control. | 148 // Thread control. |
134 virtual void Run(); | 149 virtual void Run(); |
135 inline void Stop() { running_ = false; } | 150 inline void Stop() { running_ = false; } |
136 INLINE(bool running()) { return running_; } | 151 INLINE(bool running()) { return running_; } |
yurys
2013/06/28 11:33:43
I don't see much sense in marking these methods in
loislo
2013/06/28 12:33:12
Done.
| |
152 INLINE(void Enqueue(CodeEventsContainer* event)); | |
137 | 153 |
138 // Events adding methods. Called by VM threads. | 154 // Events adding methods. Called by VM threads. |
139 void CallbackCreateEvent(Logger::LogEventsAndTags tag, | |
140 const char* prefix, Name* name, | |
141 Address start); | |
142 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
143 Name* name, | |
144 String* resource_name, int line_number, | |
145 Address start, unsigned size, | |
146 Address shared, | |
147 CompilationInfo* info); | |
148 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
149 const char* name, | |
150 Address start, unsigned size); | |
151 void CodeCreateEvent(Logger::LogEventsAndTags tag, | |
152 int args_count, | |
153 Address start, unsigned size); | |
154 void CodeMoveEvent(Address from, Address to); | 155 void CodeMoveEvent(Address from, Address to); |
155 void CodeDeleteEvent(Address from); | 156 void CodeDeleteEvent(Address from); |
156 void SharedFunctionInfoMoveEvent(Address from, Address to); | 157 void SharedFunctionInfoMoveEvent(Address from, Address to); |
157 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, | |
158 const char* prefix, String* name, | |
159 Address start, unsigned size); | |
160 // Puts current stack into tick sample events buffer. | 158 // Puts current stack into tick sample events buffer. |
161 void AddCurrentStack(); | 159 void AddCurrentStack(); |
162 | 160 |
163 // Tick sample events are filled directly in the buffer of the circular | 161 // Tick sample events are filled directly in the buffer of the circular |
164 // queue (because the structure is of fixed width, but usually not all | 162 // queue (because the structure is of fixed width, but usually not all |
165 // stack frame entries are filled.) This method returns a pointer to the | 163 // stack frame entries are filled.) This method returns a pointer to the |
166 // next record of the buffer. | 164 // next record of the buffer. |
167 INLINE(TickSample* TickSampleEvent()); | 165 INLINE(TickSample* TickSampleEvent()); |
168 | 166 |
169 private: | 167 private: |
170 union CodeEventsContainer { | |
171 CodeEventRecord generic; | |
172 #define DECLARE_CLASS(ignore, type) type type##_; | |
173 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | |
174 #undef DECLARE_TYPE | |
175 }; | |
176 | |
177 // Called from events processing thread (Run() method.) | 168 // Called from events processing thread (Run() method.) |
178 bool ProcessCodeEvent(unsigned* dequeue_order); | 169 bool ProcessCodeEvent(unsigned* dequeue_order); |
179 bool ProcessTicks(unsigned dequeue_order); | 170 bool ProcessTicks(unsigned dequeue_order); |
180 | 171 |
181 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | |
182 | |
183 ProfileGenerator* generator_; | 172 ProfileGenerator* generator_; |
184 CpuProfilesCollection* profiles_; | 173 CpuProfilesCollection* profiles_; |
185 bool running_; | 174 bool running_; |
186 UnboundQueue<CodeEventsContainer> events_buffer_; | 175 UnboundQueue<CodeEventsContainer> events_buffer_; |
187 SamplingCircularQueue ticks_buffer_; | 176 SamplingCircularQueue ticks_buffer_; |
188 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 177 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
189 unsigned enqueue_order_; | 178 unsigned enqueue_order_; |
190 }; | 179 }; |
191 | 180 |
192 | 181 |
193 #define PROFILE(IsolateGetter, Call) \ | 182 #define PROFILE(IsolateGetter, Call) \ |
194 do { \ | 183 do { \ |
195 Isolate* cpu_profiler_isolate = (IsolateGetter); \ | 184 Isolate* cpu_profiler_isolate = (IsolateGetter); \ |
196 LOG_CODE_EVENT(cpu_profiler_isolate, Call); \ | 185 LOG_CODE_EVENT(cpu_profiler_isolate, Call); \ |
197 CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \ | 186 CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \ |
198 if (cpu_profiler->is_profiling()) { \ | 187 if (cpu_profiler->is_profiling()) { \ |
199 cpu_profiler->Call; \ | 188 cpu_profiler->Call; \ |
200 } \ | 189 } \ |
201 } while (false) | 190 } while (false) |
202 | 191 |
203 | 192 |
204 class CpuProfiler { | 193 class CpuProfiler { |
205 public: | 194 public: |
206 explicit CpuProfiler(Isolate* isolate); | 195 explicit CpuProfiler(Isolate* isolate); |
196 | |
197 CpuProfiler(Isolate* isolate, | |
198 CpuProfilesCollection* test_collection, | |
199 ProfileGenerator* test_generator, | |
200 ProfilerEventsProcessor* test_processor); | |
201 | |
207 ~CpuProfiler(); | 202 ~CpuProfiler(); |
208 | 203 |
209 void StartProfiling(const char* title, bool record_samples = false); | 204 void StartProfiling(const char* title, bool record_samples = false); |
210 void StartProfiling(String* title, bool record_samples); | 205 void StartProfiling(String* title, bool record_samples); |
211 CpuProfile* StopProfiling(const char* title); | 206 CpuProfile* StopProfiling(const char* title); |
212 CpuProfile* StopProfiling(Object* security_token, String* title); | 207 CpuProfile* StopProfiling(Object* security_token, String* title); |
213 int GetProfilesCount(); | 208 int GetProfilesCount(); |
214 CpuProfile* GetProfile(Object* security_token, int index); | 209 CpuProfile* GetProfile(Object* security_token, int index); |
215 CpuProfile* FindProfile(Object* security_token, unsigned uid); | 210 CpuProfile* FindProfile(Object* security_token, unsigned uid); |
216 void DeleteAllProfiles(); | 211 void DeleteAllProfiles(); |
(...skipping 29 matching lines...) Expand all Loading... | |
246 void RegExpCodeCreateEvent(Code* code, String* source); | 241 void RegExpCodeCreateEvent(Code* code, String* source); |
247 void SetterCallbackEvent(Name* name, Address entry_point); | 242 void SetterCallbackEvent(Name* name, Address entry_point); |
248 void SharedFunctionInfoMoveEvent(Address from, Address to); | 243 void SharedFunctionInfoMoveEvent(Address from, Address to); |
249 | 244 |
250 INLINE(bool is_profiling() const) { return is_profiling_; } | 245 INLINE(bool is_profiling() const) { return is_profiling_; } |
251 bool* is_profiling_address() { | 246 bool* is_profiling_address() { |
252 return &is_profiling_; | 247 return &is_profiling_; |
253 } | 248 } |
254 | 249 |
255 private: | 250 private: |
251 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | |
yurys
2013/06/28 11:33:43
I'd rather make it a static function in cpu-profi
loislo
2013/06/28 12:33:12
Done.
| |
252 | |
256 void StartProcessorIfNotStarted(); | 253 void StartProcessorIfNotStarted(); |
257 void StopProcessorIfLastProfile(const char* title); | 254 void StopProcessorIfLastProfile(const char* title); |
258 void StopProcessor(); | 255 void StopProcessor(); |
259 void ResetProfiles(); | 256 void ResetProfiles(); |
260 | 257 |
261 Isolate* isolate_; | 258 Isolate* isolate_; |
262 CpuProfilesCollection* profiles_; | 259 CpuProfilesCollection* profiles_; |
263 unsigned next_profile_uid_; | 260 unsigned next_profile_uid_; |
264 TokenEnumerator* token_enumerator_; | 261 TokenEnumerator* token_enumerator_; |
265 ProfileGenerator* generator_; | 262 ProfileGenerator* generator_; |
266 ProfilerEventsProcessor* processor_; | 263 ProfilerEventsProcessor* processor_; |
267 int saved_logging_nesting_; | 264 int saved_logging_nesting_; |
268 bool need_to_stop_sampler_; | 265 bool need_to_stop_sampler_; |
269 bool is_profiling_; | 266 bool is_profiling_; |
270 | 267 |
271 private: | 268 private: |
272 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 269 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
273 }; | 270 }; |
274 | 271 |
275 } } // namespace v8::internal | 272 } } // namespace v8::internal |
276 | 273 |
277 | 274 |
278 #endif // V8_CPU_PROFILER_H_ | 275 #endif // V8_CPU_PROFILER_H_ |
OLD | NEW |