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

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

Issue 6551011: Fix CPU profiling for Crankshaft. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 class CpuProfile; 43 class CpuProfile;
44 class CpuProfilesCollection; 44 class CpuProfilesCollection;
45 class HashMap; 45 class HashMap;
46 class ProfileGenerator; 46 class ProfileGenerator;
47 class TokenEnumerator; 47 class TokenEnumerator;
48 48
49 #define CODE_EVENTS_TYPE_LIST(V) \ 49 #define CODE_EVENTS_TYPE_LIST(V) \
50 V(CODE_CREATION, CodeCreateEventRecord) \ 50 V(CODE_CREATION, CodeCreateEventRecord) \
51 V(CODE_MOVE, CodeMoveEventRecord) \ 51 V(CODE_MOVE, CodeMoveEventRecord) \
52 V(CODE_DELETE, CodeDeleteEventRecord) \ 52 V(CODE_DELETE, CodeDeleteEventRecord) \
53 V(CODE_ALIAS, CodeAliasEventRecord) 53 V(SFI_MOVE, SFIMoveEventRecord)
54 54
55 55
56 class CodeEventRecord { 56 class CodeEventRecord {
57 public: 57 public:
58 #define DECLARE_TYPE(type, ignore) type, 58 #define DECLARE_TYPE(type, ignore) type,
59 enum Type { 59 enum Type {
60 NONE = 0, 60 NONE = 0,
61 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) 61 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE)
62 NUMBER_OF_TYPES 62 NUMBER_OF_TYPES
63 }; 63 };
64 #undef DECLARE_TYPE 64 #undef DECLARE_TYPE
65 65
66 Type type; 66 Type type;
67 unsigned order; 67 unsigned order;
68 }; 68 };
69 69
70 70
71 class CodeCreateEventRecord : public CodeEventRecord { 71 class CodeCreateEventRecord : public CodeEventRecord {
72 public: 72 public:
73 Address start; 73 Address start;
74 CodeEntry* entry; 74 CodeEntry* entry;
75 unsigned size; 75 unsigned size;
76 Address sfi_address;
76 77
77 INLINE(void UpdateCodeMap(CodeMap* code_map)); 78 INLINE(void UpdateCodeMap(CodeMap* code_map));
78 }; 79 };
79 80
80 81
81 class CodeMoveEventRecord : public CodeEventRecord { 82 class CodeMoveEventRecord : public CodeEventRecord {
82 public: 83 public:
83 Address from; 84 Address from;
84 Address to; 85 Address to;
85 86
86 INLINE(void UpdateCodeMap(CodeMap* code_map)); 87 INLINE(void UpdateCodeMap(CodeMap* code_map));
87 }; 88 };
88 89
89 90
90 class CodeDeleteEventRecord : public CodeEventRecord { 91 class CodeDeleteEventRecord : public CodeEventRecord {
91 public: 92 public:
92 Address start; 93 Address start;
93 94
94 INLINE(void UpdateCodeMap(CodeMap* code_map)); 95 INLINE(void UpdateCodeMap(CodeMap* code_map));
95 }; 96 };
96 97
97 98
98 class CodeAliasEventRecord : public CodeEventRecord { 99 class SFIMoveEventRecord : public CodeEventRecord {
99 public: 100 public:
100 Address start; 101 Address from;
101 CodeEntry* entry; 102 Address to;
102 Address code_start;
103 103
104 INLINE(void UpdateCodeMap(CodeMap* code_map)); 104 INLINE(void UpdateCodeMap(CodeMap* code_map));
105 }; 105 };
106 106
107 107
108 class TickSampleEventRecord BASE_EMBEDDED { 108 class TickSampleEventRecord BASE_EMBEDDED {
109 public: 109 public:
110 TickSampleEventRecord() 110 TickSampleEventRecord()
111 : filler(1) { 111 : filler(1) {
112 ASSERT(filler != SamplingCircularQueue::kClear); 112 ASSERT(filler != SamplingCircularQueue::kClear);
(...skipping 14 matching lines...) Expand all
127 127
128 INLINE(static TickSampleEventRecord* init(void* value)); 128 INLINE(static TickSampleEventRecord* init(void* value));
129 }; 129 };
130 130
131 131
132 // This class implements both the profile events processor thread and 132 // This class implements both the profile events processor thread and
133 // methods called by event producers: VM and stack sampler threads. 133 // methods called by event producers: VM and stack sampler threads.
134 class ProfilerEventsProcessor : public Thread { 134 class ProfilerEventsProcessor : public Thread {
135 public: 135 public:
136 explicit ProfilerEventsProcessor(ProfileGenerator* generator); 136 explicit ProfilerEventsProcessor(ProfileGenerator* generator);
137 virtual ~ProfilerEventsProcessor(); 137 virtual ~ProfilerEventsProcessor() {}
138 138
139 // Thread control. 139 // Thread control.
140 virtual void Run(); 140 virtual void Run();
141 inline void Stop() { running_ = false; } 141 inline void Stop() { running_ = false; }
142 INLINE(bool running()) { return running_; } 142 INLINE(bool running()) { return running_; }
143 143
144 // Events adding methods. Called by VM threads. 144 // Events adding methods. Called by VM threads.
145 void CallbackCreateEvent(Logger::LogEventsAndTags tag, 145 void CallbackCreateEvent(Logger::LogEventsAndTags tag,
146 const char* prefix, String* name, 146 const char* prefix, String* name,
147 Address start); 147 Address start);
148 void CodeCreateEvent(Logger::LogEventsAndTags tag, 148 void CodeCreateEvent(Logger::LogEventsAndTags tag,
149 String* name, 149 String* name,
150 String* resource_name, int line_number, 150 String* resource_name, int line_number,
151 Address start, unsigned size); 151 Address start, unsigned size,
152 Address sfi_address);
152 void CodeCreateEvent(Logger::LogEventsAndTags tag, 153 void CodeCreateEvent(Logger::LogEventsAndTags tag,
153 const char* name, 154 const char* name,
154 Address start, unsigned size); 155 Address start, unsigned size);
155 void CodeCreateEvent(Logger::LogEventsAndTags tag, 156 void CodeCreateEvent(Logger::LogEventsAndTags tag,
156 int args_count, 157 int args_count,
157 Address start, unsigned size); 158 Address start, unsigned size);
158 void CodeMoveEvent(Address from, Address to); 159 void CodeMoveEvent(Address from, Address to);
159 void CodeDeleteEvent(Address from); 160 void CodeDeleteEvent(Address from);
160 void FunctionCreateEvent(Address alias, Address start, int security_token_id); 161 void SFIMoveEvent(Address from, Address to);
161 void FunctionMoveEvent(Address from, Address to);
162 void FunctionDeleteEvent(Address from);
163 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, 162 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag,
164 const char* prefix, String* name, 163 const char* prefix, String* name,
165 Address start, unsigned size); 164 Address start, unsigned size);
166 // Puts current stack into tick sample events buffer. 165 // Puts current stack into tick sample events buffer.
167 void AddCurrentStack(); 166 void AddCurrentStack();
168 bool IsKnownFunction(Address start);
169 void ProcessMovedFunctions();
170 void RememberMovedFunction(JSFunction* function);
171 167
172 // Tick sample events are filled directly in the buffer of the circular 168 // Tick sample events are filled directly in the buffer of the circular
173 // queue (because the structure is of fixed width, but usually not all 169 // queue (because the structure is of fixed width, but usually not all
174 // stack frame entries are filled.) This method returns a pointer to the 170 // stack frame entries are filled.) This method returns a pointer to the
175 // next record of the buffer. 171 // next record of the buffer.
176 INLINE(TickSample* TickSampleEvent()); 172 INLINE(TickSample* TickSampleEvent());
177 173
178 private: 174 private:
179 union CodeEventsContainer { 175 union CodeEventsContainer {
180 CodeEventRecord generic; 176 CodeEventRecord generic;
181 #define DECLARE_CLASS(ignore, type) type type##_; 177 #define DECLARE_CLASS(ignore, type) type type##_;
182 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) 178 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS)
183 #undef DECLARE_TYPE 179 #undef DECLARE_TYPE
184 }; 180 };
185 181
186 // Called from events processing thread (Run() method.) 182 // Called from events processing thread (Run() method.)
187 bool ProcessCodeEvent(unsigned* dequeue_order); 183 bool ProcessCodeEvent(unsigned* dequeue_order);
188 bool ProcessTicks(unsigned dequeue_order); 184 bool ProcessTicks(unsigned dequeue_order);
189 185
190 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); 186 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag));
191 INLINE(static bool AddressesMatch(void* key1, void* key2)) {
192 return key1 == key2;
193 }
194 INLINE(static uint32_t AddressHash(Address addr)) {
195 return ComputeIntegerHash(
196 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)));
197 }
198 187
199 ProfileGenerator* generator_; 188 ProfileGenerator* generator_;
200 bool running_; 189 bool running_;
201 UnboundQueue<CodeEventsContainer> events_buffer_; 190 UnboundQueue<CodeEventsContainer> events_buffer_;
202 SamplingCircularQueue ticks_buffer_; 191 SamplingCircularQueue ticks_buffer_;
203 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; 192 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_;
204 unsigned enqueue_order_; 193 unsigned enqueue_order_;
205
206 // Used from the VM thread.
207 HashMap* known_functions_;
208 List<JSFunction*> moved_functions_;
209 }; 194 };
210 195
211 } } // namespace v8::internal 196 } } // namespace v8::internal
212 197
213 198
214 #define PROFILE(Call) \ 199 #define PROFILE(Call) \
215 LOG(Call); \ 200 LOG(Call); \
216 do { \ 201 do { \
217 if (v8::internal::CpuProfiler::is_profiling()) { \ 202 if (v8::internal::CpuProfiler::is_profiling()) { \
218 v8::internal::CpuProfiler::Call; \ 203 v8::internal::CpuProfiler::Call; \
(...skipping 25 matching lines...) Expand all
244 static TickSample* TickSampleEvent(); 229 static TickSample* TickSampleEvent();
245 230
246 // Must be called via PROFILE macro, otherwise will crash when 231 // Must be called via PROFILE macro, otherwise will crash when
247 // profiling is not enabled. 232 // profiling is not enabled.
248 static void CallbackEvent(String* name, Address entry_point); 233 static void CallbackEvent(String* name, Address entry_point);
249 static void CodeCreateEvent(Logger::LogEventsAndTags tag, 234 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
250 Code* code, const char* comment); 235 Code* code, const char* comment);
251 static void CodeCreateEvent(Logger::LogEventsAndTags tag, 236 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
252 Code* code, String* name); 237 Code* code, String* name);
253 static void CodeCreateEvent(Logger::LogEventsAndTags tag, 238 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
254 Code* code, String* name, 239 Code* code,
240 SharedFunctionInfo *shared,
241 String* name);
242 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
243 Code* code,
244 SharedFunctionInfo *shared,
255 String* source, int line); 245 String* source, int line);
256 static void CodeCreateEvent(Logger::LogEventsAndTags tag, 246 static void CodeCreateEvent(Logger::LogEventsAndTags tag,
257 Code* code, int args_count); 247 Code* code, int args_count);
258 static void CodeMovingGCEvent() {} 248 static void CodeMovingGCEvent() {}
259 static void CodeMoveEvent(Address from, Address to); 249 static void CodeMoveEvent(Address from, Address to);
260 static void CodeDeleteEvent(Address from); 250 static void CodeDeleteEvent(Address from);
261 static void FunctionCreateEvent(JSFunction* function);
262 // Reports function creation in case we had missed it (e.g.
263 // if it was created from compiled code).
264 static void FunctionCreateEventFromMove(JSFunction* function);
265 static void FunctionMoveEvent(Address from, Address to);
266 static void FunctionDeleteEvent(Address from);
267 static void GetterCallbackEvent(String* name, Address entry_point); 251 static void GetterCallbackEvent(String* name, Address entry_point);
268 static void RegExpCodeCreateEvent(Code* code, String* source); 252 static void RegExpCodeCreateEvent(Code* code, String* source);
269 static void ProcessMovedFunctions();
270 static void SetterCallbackEvent(String* name, Address entry_point); 253 static void SetterCallbackEvent(String* name, Address entry_point);
254 static void SFIMoveEvent(Address from, Address to);
271 255
272 static INLINE(bool is_profiling()) { 256 static INLINE(bool is_profiling()) {
273 return NoBarrier_Load(&is_profiling_); 257 return NoBarrier_Load(&is_profiling_);
274 } 258 }
275 259
276 private: 260 private:
277 CpuProfiler(); 261 CpuProfiler();
278 ~CpuProfiler(); 262 ~CpuProfiler();
279 void StartCollectingProfile(const char* title); 263 void StartCollectingProfile(const char* title);
280 void StartCollectingProfile(String* title); 264 void StartCollectingProfile(String* title);
(...skipping 17 matching lines...) Expand all
298 #endif // ENABLE_LOGGING_AND_PROFILING 282 #endif // ENABLE_LOGGING_AND_PROFILING
299 283
300 private: 284 private:
301 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); 285 DISALLOW_COPY_AND_ASSIGN(CpuProfiler);
302 }; 286 };
303 287
304 } } // namespace v8::internal 288 } } // namespace v8::internal
305 289
306 290
307 #endif // V8_CPU_PROFILER_H_ 291 #endif // V8_CPU_PROFILER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698