| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 #include "unbound-queue.h" | 34 #include "unbound-queue.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 // Forward declarations. | 39 // Forward declarations. |
| 40 class CodeEntry; | 40 class CodeEntry; |
| 41 class CodeMap; | 41 class CodeMap; |
| 42 class CpuProfile; | 42 class CpuProfile; |
| 43 class CpuProfilesCollection; | 43 class CpuProfilesCollection; |
| 44 class HashMap; |
| 44 class ProfileGenerator; | 45 class ProfileGenerator; |
| 45 class TokenEnumerator; | 46 class TokenEnumerator; |
| 46 | 47 |
| 47 #define CODE_EVENTS_TYPE_LIST(V) \ | 48 #define CODE_EVENTS_TYPE_LIST(V) \ |
| 48 V(CODE_CREATION, CodeCreateEventRecord) \ | 49 V(CODE_CREATION, CodeCreateEventRecord) \ |
| 49 V(CODE_MOVE, CodeMoveEventRecord) \ | 50 V(CODE_MOVE, CodeMoveEventRecord) \ |
| 50 V(CODE_DELETE, CodeDeleteEventRecord) \ | 51 V(CODE_DELETE, CodeDeleteEventRecord) \ |
| 51 V(CODE_ALIAS, CodeAliasEventRecord) | 52 V(CODE_ALIAS, CodeAliasEventRecord) |
| 52 | 53 |
| 53 | 54 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 126 |
| 126 INLINE(static TickSampleEventRecord* init(void* value)); | 127 INLINE(static TickSampleEventRecord* init(void* value)); |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 | 130 |
| 130 // This class implements both the profile events processor thread and | 131 // This class implements both the profile events processor thread and |
| 131 // methods called by event producers: VM and stack sampler threads. | 132 // methods called by event producers: VM and stack sampler threads. |
| 132 class ProfilerEventsProcessor : public Thread { | 133 class ProfilerEventsProcessor : public Thread { |
| 133 public: | 134 public: |
| 134 explicit ProfilerEventsProcessor(ProfileGenerator* generator); | 135 explicit ProfilerEventsProcessor(ProfileGenerator* generator); |
| 135 virtual ~ProfilerEventsProcessor() { } | 136 virtual ~ProfilerEventsProcessor(); |
| 136 | 137 |
| 137 // Thread control. | 138 // Thread control. |
| 138 virtual void Run(); | 139 virtual void Run(); |
| 139 inline void Stop() { running_ = false; } | 140 inline void Stop() { running_ = false; } |
| 140 INLINE(bool running()) { return running_; } | 141 INLINE(bool running()) { return running_; } |
| 141 | 142 |
| 142 // Events adding methods. Called by VM threads. | 143 // Events adding methods. Called by VM threads. |
| 143 void CallbackCreateEvent(Logger::LogEventsAndTags tag, | 144 void CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| 144 const char* prefix, String* name, | 145 const char* prefix, String* name, |
| 145 Address start); | 146 Address start); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 156 void CodeMoveEvent(Address from, Address to); | 157 void CodeMoveEvent(Address from, Address to); |
| 157 void CodeDeleteEvent(Address from); | 158 void CodeDeleteEvent(Address from); |
| 158 void FunctionCreateEvent(Address alias, Address start, int security_token_id); | 159 void FunctionCreateEvent(Address alias, Address start, int security_token_id); |
| 159 void FunctionMoveEvent(Address from, Address to); | 160 void FunctionMoveEvent(Address from, Address to); |
| 160 void FunctionDeleteEvent(Address from); | 161 void FunctionDeleteEvent(Address from); |
| 161 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, | 162 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, |
| 162 const char* prefix, String* name, | 163 const char* prefix, String* name, |
| 163 Address start, unsigned size); | 164 Address start, unsigned size); |
| 164 // Puts current stack into tick sample events buffer. | 165 // Puts current stack into tick sample events buffer. |
| 165 void AddCurrentStack(); | 166 void AddCurrentStack(); |
| 167 bool IsKnownFunction(Address start); |
| 166 | 168 |
| 167 // Tick sample events are filled directly in the buffer of the circular | 169 // Tick sample events are filled directly in the buffer of the circular |
| 168 // queue (because the structure is of fixed width, but usually not all | 170 // queue (because the structure is of fixed width, but usually not all |
| 169 // stack frame entries are filled.) This method returns a pointer to the | 171 // stack frame entries are filled.) This method returns a pointer to the |
| 170 // next record of the buffer. | 172 // next record of the buffer. |
| 171 INLINE(TickSample* TickSampleEvent()); | 173 INLINE(TickSample* TickSampleEvent()); |
| 172 | 174 |
| 173 private: | 175 private: |
| 174 union CodeEventsContainer { | 176 union CodeEventsContainer { |
| 175 CodeEventRecord generic; | 177 CodeEventRecord generic; |
| 176 #define DECLARE_CLASS(ignore, type) type type##_; | 178 #define DECLARE_CLASS(ignore, type) type type##_; |
| 177 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | 179 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) |
| 178 #undef DECLARE_TYPE | 180 #undef DECLARE_TYPE |
| 179 }; | 181 }; |
| 180 | 182 |
| 181 // Called from events processing thread (Run() method.) | 183 // Called from events processing thread (Run() method.) |
| 182 bool ProcessCodeEvent(unsigned* dequeue_order); | 184 bool ProcessCodeEvent(unsigned* dequeue_order); |
| 183 bool ProcessTicks(unsigned dequeue_order); | 185 bool ProcessTicks(unsigned dequeue_order); |
| 184 | 186 |
| 185 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | 187 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); |
| 188 INLINE(static bool AddressesMatch(void* key1, void* key2)) { |
| 189 return key1 == key2; |
| 190 } |
| 191 INLINE(static uint32_t AddressHash(Address addr)) { |
| 192 return ComputeIntegerHash( |
| 193 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr))); |
| 194 } |
| 186 | 195 |
| 187 ProfileGenerator* generator_; | 196 ProfileGenerator* generator_; |
| 188 bool running_; | 197 bool running_; |
| 189 UnboundQueue<CodeEventsContainer> events_buffer_; | 198 UnboundQueue<CodeEventsContainer> events_buffer_; |
| 190 SamplingCircularQueue ticks_buffer_; | 199 SamplingCircularQueue ticks_buffer_; |
| 191 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 200 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
| 192 unsigned enqueue_order_; | 201 unsigned enqueue_order_; |
| 202 |
| 203 // Used from the VM thread. |
| 204 HashMap* known_functions_; |
| 193 }; | 205 }; |
| 194 | 206 |
| 195 } } // namespace v8::internal | 207 } } // namespace v8::internal |
| 196 | 208 |
| 197 | 209 |
| 198 #define PROFILE(Call) \ | 210 #define PROFILE(Call) \ |
| 199 LOG(Call); \ | 211 LOG(Call); \ |
| 200 do { \ | 212 do { \ |
| 201 if (v8::internal::CpuProfiler::is_profiling()) { \ | 213 if (v8::internal::CpuProfiler::is_profiling()) { \ |
| 202 v8::internal::CpuProfiler::Call; \ | 214 v8::internal::CpuProfiler::Call; \ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 247 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 236 Code* code, String* name); | 248 Code* code, String* name); |
| 237 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 249 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 238 Code* code, String* name, | 250 Code* code, String* name, |
| 239 String* source, int line); | 251 String* source, int line); |
| 240 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 252 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 241 Code* code, int args_count); | 253 Code* code, int args_count); |
| 242 static void CodeMoveEvent(Address from, Address to); | 254 static void CodeMoveEvent(Address from, Address to); |
| 243 static void CodeDeleteEvent(Address from); | 255 static void CodeDeleteEvent(Address from); |
| 244 static void FunctionCreateEvent(JSFunction* function); | 256 static void FunctionCreateEvent(JSFunction* function); |
| 257 // Reports function creation in case we had missed it (e.g. |
| 258 // if it was created from compiled code). |
| 259 static void FunctionCreateEventFromMove(JSFunction* function, |
| 260 HeapObject* source); |
| 245 static void FunctionMoveEvent(Address from, Address to); | 261 static void FunctionMoveEvent(Address from, Address to); |
| 246 static void FunctionDeleteEvent(Address from); | 262 static void FunctionDeleteEvent(Address from); |
| 247 static void GetterCallbackEvent(String* name, Address entry_point); | 263 static void GetterCallbackEvent(String* name, Address entry_point); |
| 248 static void RegExpCodeCreateEvent(Code* code, String* source); | 264 static void RegExpCodeCreateEvent(Code* code, String* source); |
| 249 static void SetterCallbackEvent(String* name, Address entry_point); | 265 static void SetterCallbackEvent(String* name, Address entry_point); |
| 250 | 266 |
| 251 static INLINE(bool is_profiling()) { | 267 static INLINE(bool is_profiling()) { |
| 252 return singleton_ != NULL && singleton_->processor_ != NULL; | 268 return singleton_ != NULL && singleton_->processor_ != NULL; |
| 253 } | 269 } |
| 254 | 270 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 276 #endif // ENABLE_LOGGING_AND_PROFILING | 292 #endif // ENABLE_LOGGING_AND_PROFILING |
| 277 | 293 |
| 278 private: | 294 private: |
| 279 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 295 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 280 }; | 296 }; |
| 281 | 297 |
| 282 } } // namespace v8::internal | 298 } } // namespace v8::internal |
| 283 | 299 |
| 284 | 300 |
| 285 #endif // V8_CPU_PROFILER_H_ | 301 #endif // V8_CPU_PROFILER_H_ |
| OLD | NEW |