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

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

Issue 1582004: C++ profiles processor: wire up to VM. (Closed)
Patch Set: Created 10 years, 8 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
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_CPU_PROFILER_H_ 28 #ifndef V8_CPU_PROFILER_H_
29 #define V8_CPU_PROFILER_H_ 29 #define V8_CPU_PROFILER_H_
30 30
31 #ifdef ENABLE_CPP_PROFILES_PROCESSOR 31 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
32 32
33 #include "circular-queue.h" 33 #include "circular-queue.h"
34 #include "profile-generator.h"
35 34
36 namespace v8 { 35 namespace v8 {
37 namespace internal { 36 namespace internal {
38 37
38 // Forward declarations.
39 class CodeEntry;
40 class CodeMap;
41 class CpuProfile;
42 class CpuProfilesCollection;
43 class ProfileGenerator;
44
45
39 #define CODE_EVENTS_TYPE_LIST(V) \ 46 #define CODE_EVENTS_TYPE_LIST(V) \
40 V(CODE_CREATION, CodeCreateEventRecord) \ 47 V(CODE_CREATION, CodeCreateEventRecord) \
41 V(CODE_MOVE, CodeMoveEventRecord) \ 48 V(CODE_MOVE, CodeMoveEventRecord) \
42 V(CODE_DELETE, CodeDeleteEventRecord) \ 49 V(CODE_DELETE, CodeDeleteEventRecord) \
43 V(CODE_ALIAS, CodeAliasEventRecord) 50 V(CODE_ALIAS, CodeAliasEventRecord)
44 51
45 52
46 class CodeEventRecord { 53 class CodeEventRecord {
47 public: 54 public:
48 #define DECLARE_TYPE(type, ignore) type, 55 #define DECLARE_TYPE(type, ignore) type,
49 enum Type { 56 enum Type {
50 NONE = 0, 57 NONE = 0,
51 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) 58 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE)
52 NUMBER_OF_TYPES 59 NUMBER_OF_TYPES
53 }; 60 };
54 #undef DECLARE_TYPE 61 #undef DECLARE_TYPE
55 62
56 Type type; 63 Type type;
57 unsigned order; 64 unsigned order;
58 }; 65 };
59 66
60 67
61 class CodeCreateEventRecord : public CodeEventRecord { 68 class CodeCreateEventRecord : public CodeEventRecord {
62 public: 69 public:
63 Address start; 70 Address start;
64 CodeEntry* entry; 71 CodeEntry* entry;
65 unsigned size; 72 unsigned size;
66 73
67 INLINE(void UpdateCodeMap(CodeMap* code_map)) { 74 INLINE(void UpdateCodeMap(CodeMap* code_map));
68 code_map->AddCode(start, entry, size);
69 }
70 }; 75 };
71 76
72 77
73 class CodeMoveEventRecord : public CodeEventRecord { 78 class CodeMoveEventRecord : public CodeEventRecord {
74 public: 79 public:
75 Address from; 80 Address from;
76 Address to; 81 Address to;
77 82
78 INLINE(void UpdateCodeMap(CodeMap* code_map)) { 83 INLINE(void UpdateCodeMap(CodeMap* code_map));
79 code_map->MoveCode(from, to);
80 }
81 }; 84 };
82 85
83 86
84 class CodeDeleteEventRecord : public CodeEventRecord { 87 class CodeDeleteEventRecord : public CodeEventRecord {
85 public: 88 public:
86 Address start; 89 Address start;
87 90
88 INLINE(void UpdateCodeMap(CodeMap* code_map)) { 91 INLINE(void UpdateCodeMap(CodeMap* code_map));
89 code_map->DeleteCode(start);
90 }
91 }; 92 };
92 93
93 94
94 class CodeAliasEventRecord : public CodeEventRecord { 95 class CodeAliasEventRecord : public CodeEventRecord {
95 public: 96 public:
96 Address alias; 97 Address alias;
97 Address start; 98 Address start;
98 99
99 INLINE(void UpdateCodeMap(CodeMap* code_map)) { 100 INLINE(void UpdateCodeMap(CodeMap* code_map));
100 code_map->AddAlias(alias, start);
101 }
102 }; 101 };
103 102
104 103
105 class TickSampleEventRecord BASE_EMBEDDED { 104 class TickSampleEventRecord BASE_EMBEDDED {
106 public: 105 public:
107 // In memory, the first machine word of a TickSampleEventRecord will be the 106 // In memory, the first machine word of a TickSampleEventRecord will be the
108 // first entry of TickSample, that is -- a program counter field. 107 // first entry of TickSample, that is -- a program counter field.
109 // TickSample is put first, because 'order' can become equal to 108 // TickSample is put first, because 'order' can become equal to
110 // SamplingCircularQueue::kClear, while program counter can't. 109 // SamplingCircularQueue::kClear, while program counter can't.
111 TickSample sample; 110 TickSample sample;
(...skipping 14 matching lines...) Expand all
126 public: 125 public:
127 explicit ProfilerEventsProcessor(ProfileGenerator* generator); 126 explicit ProfilerEventsProcessor(ProfileGenerator* generator);
128 virtual ~ProfilerEventsProcessor() { } 127 virtual ~ProfilerEventsProcessor() { }
129 128
130 // Thread control. 129 // Thread control.
131 virtual void Run(); 130 virtual void Run();
132 inline void Stop() { running_ = false; } 131 inline void Stop() { running_ = false; }
133 INLINE(bool running()) { return running_; } 132 INLINE(bool running()) { return running_; }
134 133
135 // Events adding methods. Called by VM threads. 134 // Events adding methods. Called by VM threads.
135 void CallbackCreateEvent(Logger::LogEventsAndTags tag,
136 const char* prefix, String* name,
137 Address start);
136 void CodeCreateEvent(Logger::LogEventsAndTags tag, 138 void CodeCreateEvent(Logger::LogEventsAndTags tag,
137 String* name, 139 String* name,
138 String* resource_name, int line_number, 140 String* resource_name, int line_number,
139 Address start, unsigned size); 141 Address start, unsigned size);
140 void CodeCreateEvent(Logger::LogEventsAndTags tag, 142 void CodeCreateEvent(Logger::LogEventsAndTags tag,
141 const char* name, 143 const char* name,
142 Address start, unsigned size); 144 Address start, unsigned size);
143 void CodeCreateEvent(Logger::LogEventsAndTags tag, 145 void CodeCreateEvent(Logger::LogEventsAndTags tag,
144 int args_count, 146 int args_count,
145 Address start, unsigned size); 147 Address start, unsigned size);
(...skipping 23 matching lines...) Expand all
169 171
170 ProfileGenerator* generator_; 172 ProfileGenerator* generator_;
171 bool running_; 173 bool running_;
172 CircularQueue<CodeEventsContainer> events_buffer_; 174 CircularQueue<CodeEventsContainer> events_buffer_;
173 SamplingCircularQueue ticks_buffer_; 175 SamplingCircularQueue ticks_buffer_;
174 unsigned enqueue_order_; 176 unsigned enqueue_order_;
175 }; 177 };
176 178
177 } } // namespace v8::internal 179 } } // namespace v8::internal
178 180
181
182 #define PROFILE(Call) \
183 LOG(Call); \
184 do { \
185 if (v8::internal::CpuProfiler::is_profiling()) { \
186 v8::internal::CpuProfiler::Call; \
187 } \
188 } while (false)
189 #else
190 #define PROFILE(Call) LOG(Call)
179 #endif // ENABLE_CPP_PROFILES_PROCESSOR 191 #endif // ENABLE_CPP_PROFILES_PROCESSOR
180 192
193
194 namespace v8 {
195 namespace internal {
196
197 class CpuProfiler {
198 public:
199 static void Setup();
200 static void TearDown();
201
202 #ifdef ENABLE_CPP_PROFILES_PROCESSOR
203 static void StartProfiling(const char* title);
204 static void StartProfiling(String* title);
205 static CpuProfile* StopProfiling(const char* title);
206 static CpuProfile* StopProfiling(String* title);
207 static int GetProfilesCount();
208 static CpuProfile* GetProfile(int index);
209 static CpuProfile* FindProfile(unsigned uid);
210
211 // Invoked from stack sampler (thread or signal handler.)
212 static TickSample* TickSampleEvent();
213
214 // Must be called via PROFILE macro, otherwise will crash when
215 // profiling is not enabled.
216 static void CallbackEvent(String* name, Address entry_point);
217 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
218 Code* code, const char* comment);
219 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
220 Code* code, String* name);
221 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
222 Code* code, String* name,
223 String* source, int line);
224 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
225 Code* code, int args_count);
226 static void CodeMoveEvent(Address from, Address to);
227 static void CodeDeleteEvent(Address from);
228 static void FunctionCreateEvent(JSFunction* function);
229 static void FunctionMoveEvent(Address from, Address to);
230 static void FunctionDeleteEvent(Address from);
231 static void GetterCallbackEvent(String* name, Address entry_point);
232 static void RegExpCodeCreateEvent(Code* code, String* source);
233 static void SetterCallbackEvent(String* name, Address entry_point);
234
235 static INLINE(bool is_profiling()) {
236 ASSERT(singleton_ != NULL);
237 return singleton_->processor_ != NULL;
238 }
239
240 private:
241 CpuProfiler();
242 ~CpuProfiler();
243 void StartCollectingProfile(const char* title);
244 void StartCollectingProfile(String* title);
245 void StartProcessorIfNotStarted();
246 CpuProfile* StopCollectingProfile(const char* title);
247 CpuProfile* StopCollectingProfile(String* title);
248 void StopProcessorIfLastProfile();
249
250 CpuProfilesCollection* profiles_;
251 unsigned next_profile_uid_;
252 ProfileGenerator* generator_;
253 ProfilerEventsProcessor* processor_;
254
255 static CpuProfiler* singleton_;
256
257 #else
258 static INLINE(bool is_profiling()) { return false; }
259 #endif // ENABLE_CPP_PROFILES_PROCESSOR
260
261 private:
262 DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
263 };
264
265 } } // namespace v8::internal
266
267
181 #endif // V8_CPU_PROFILER_H_ 268 #endif // V8_CPU_PROFILER_H_
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/cpu-profiler.cc » ('j') | src/platform-linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698