| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static TickSampleEventRecord* cast(void* value) { | 117 static TickSampleEventRecord* cast(void* value) { |
| 118 return reinterpret_cast<TickSampleEventRecord*>(value); | 118 return reinterpret_cast<TickSampleEventRecord*>(value); |
| 119 } | 119 } |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 | 122 |
| 123 // This class implements both the profile events processor thread and | 123 // This class implements both the profile events processor thread and |
| 124 // methods called by event producers: VM and stack sampler threads. | 124 // methods called by event producers: VM and stack sampler threads. |
| 125 class ProfilerEventsProcessor : public Thread { | 125 class ProfilerEventsProcessor : public Thread { |
| 126 public: | 126 public: |
| 127 explicit ProfilerEventsProcessor(ProfileGenerator* generator, | 127 explicit ProfilerEventsProcessor(ProfileGenerator* generator); |
| 128 Sampler* sampler, | |
| 129 int period_in_useconds); | |
| 130 virtual ~ProfilerEventsProcessor() {} | 128 virtual ~ProfilerEventsProcessor() {} |
| 131 | 129 |
| 132 // Thread control. | 130 // Thread control. |
| 133 virtual void Run(); | 131 virtual void Run(); |
| 134 inline void Stop() { running_ = false; } | 132 inline void Stop() { running_ = false; } |
| 135 INLINE(bool running()) { return running_; } | 133 INLINE(bool running()) { return running_; } |
| 136 | 134 |
| 137 // Events adding methods. Called by VM threads. | 135 // Events adding methods. Called by VM threads. |
| 138 void CallbackCreateEvent(Logger::LogEventsAndTags tag, | 136 void CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| 139 const char* prefix, String* name, | 137 const char* prefix, String* name, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 151 Address start, unsigned size); | 149 Address start, unsigned size); |
| 152 void CodeMoveEvent(Address from, Address to); | 150 void CodeMoveEvent(Address from, Address to); |
| 153 void CodeDeleteEvent(Address from); | 151 void CodeDeleteEvent(Address from); |
| 154 void SharedFunctionInfoMoveEvent(Address from, Address to); | 152 void SharedFunctionInfoMoveEvent(Address from, Address to); |
| 155 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, | 153 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, |
| 156 const char* prefix, String* name, | 154 const char* prefix, String* name, |
| 157 Address start, unsigned size); | 155 Address start, unsigned size); |
| 158 // Puts current stack into tick sample events buffer. | 156 // Puts current stack into tick sample events buffer. |
| 159 void AddCurrentStack(); | 157 void AddCurrentStack(); |
| 160 | 158 |
| 161 // StartTickSampleEvent returns a pointer only if the ticks_buffer_ is empty, | 159 // Tick sample events are filled directly in the buffer of the circular |
| 162 // FinishTickSampleEvent marks the ticks_buffer_ as filled. | 160 // queue (because the structure is of fixed width, but usually not all |
| 163 // Finish should be called only after successful Start (returning non-NULL | 161 // stack frame entries are filled.) This method returns a pointer to the |
| 164 // pointer). | 162 // next record of the buffer. |
| 165 INLINE(TickSample* StartTickSampleEvent()); | 163 INLINE(TickSample* TickSampleEvent()); |
| 166 INLINE(void FinishTickSampleEvent()); | |
| 167 | 164 |
| 168 private: | 165 private: |
| 169 union CodeEventsContainer { | 166 union CodeEventsContainer { |
| 170 CodeEventRecord generic; | 167 CodeEventRecord generic; |
| 171 #define DECLARE_CLASS(ignore, type) type type##_; | 168 #define DECLARE_CLASS(ignore, type) type type##_; |
| 172 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | 169 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) |
| 173 #undef DECLARE_TYPE | 170 #undef DECLARE_TYPE |
| 174 }; | 171 }; |
| 175 | 172 |
| 176 // Called from events processing thread (Run() method.) | 173 // Called from events processing thread (Run() method.) |
| 177 bool ProcessCodeEvent(unsigned* dequeue_order); | 174 bool ProcessCodeEvent(unsigned* dequeue_order); |
| 178 bool ProcessTicks(unsigned dequeue_order); | 175 bool ProcessTicks(unsigned dequeue_order); |
| 179 void ProcessEventsQueue(int64_t stop_time, unsigned* dequeue_order); | |
| 180 | 176 |
| 181 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | 177 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); |
| 182 | 178 |
| 183 ProfileGenerator* generator_; | 179 ProfileGenerator* generator_; |
| 184 Sampler* sampler_; | |
| 185 bool running_; | 180 bool running_; |
| 186 // Sampling period in microseconds. | |
| 187 const int period_in_useconds_; | |
| 188 UnboundQueue<CodeEventsContainer> events_buffer_; | 181 UnboundQueue<CodeEventsContainer> events_buffer_; |
| 189 TickSampleEventRecord ticks_buffer_; | 182 SamplingCircularQueue ticks_buffer_; |
| 190 bool ticks_buffer_is_empty_; | |
| 191 bool ticks_buffer_is_initialized_; | |
| 192 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 183 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
| 193 unsigned enqueue_order_; | 184 unsigned enqueue_order_; |
| 194 }; | 185 }; |
| 195 | 186 |
| 196 } } // namespace v8::internal | 187 } } // namespace v8::internal |
| 197 | 188 |
| 198 | 189 |
| 199 #define PROFILE(isolate, Call) \ | 190 #define PROFILE(isolate, Call) \ |
| 200 LOG_CODE_EVENT(isolate, Call); \ | 191 LOG_CODE_EVENT(isolate, Call); \ |
| 201 do { \ | 192 do { \ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 220 static CpuProfile* StopProfiling(const char* title); | 211 static CpuProfile* StopProfiling(const char* title); |
| 221 static CpuProfile* StopProfiling(Object* security_token, String* title); | 212 static CpuProfile* StopProfiling(Object* security_token, String* title); |
| 222 static int GetProfilesCount(); | 213 static int GetProfilesCount(); |
| 223 static CpuProfile* GetProfile(Object* security_token, int index); | 214 static CpuProfile* GetProfile(Object* security_token, int index); |
| 224 static CpuProfile* FindProfile(Object* security_token, unsigned uid); | 215 static CpuProfile* FindProfile(Object* security_token, unsigned uid); |
| 225 static void DeleteAllProfiles(); | 216 static void DeleteAllProfiles(); |
| 226 static void DeleteProfile(CpuProfile* profile); | 217 static void DeleteProfile(CpuProfile* profile); |
| 227 static bool HasDetachedProfiles(); | 218 static bool HasDetachedProfiles(); |
| 228 | 219 |
| 229 // Invoked from stack sampler (thread or signal handler.) | 220 // Invoked from stack sampler (thread or signal handler.) |
| 230 // Finish should be called only after successful Start (returning non-NULL | 221 static TickSample* TickSampleEvent(Isolate* isolate); |
| 231 // pointer). | |
| 232 static TickSample* StartTickSampleEvent(Isolate* isolate); | |
| 233 static void FinishTickSampleEvent(Isolate* isolate); | |
| 234 | 222 |
| 235 // Must be called via PROFILE macro, otherwise will crash when | 223 // Must be called via PROFILE macro, otherwise will crash when |
| 236 // profiling is not enabled. | 224 // profiling is not enabled. |
| 237 static void CallbackEvent(String* name, Address entry_point); | 225 static void CallbackEvent(String* name, Address entry_point); |
| 238 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 226 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 239 Code* code, const char* comment); | 227 Code* code, const char* comment); |
| 240 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 228 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 241 Code* code, String* name); | 229 Code* code, String* name); |
| 242 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 230 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 243 Code* code, | 231 Code* code, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 Atomic32 is_profiling_; | 274 Atomic32 is_profiling_; |
| 287 | 275 |
| 288 private: | 276 private: |
| 289 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 277 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 290 }; | 278 }; |
| 291 | 279 |
| 292 } } // namespace v8::internal | 280 } } // namespace v8::internal |
| 293 | 281 |
| 294 | 282 |
| 295 #endif // V8_CPU_PROFILER_H_ | 283 #endif // V8_CPU_PROFILER_H_ |
| OLD | NEW |