| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 public: | 56 public: |
| 57 #define DECLARE_TYPE(type, ignore) type, | 57 #define DECLARE_TYPE(type, ignore) type, |
| 58 enum Type { | 58 enum Type { |
| 59 NONE = 0, | 59 NONE = 0, |
| 60 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) | 60 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) |
| 61 NUMBER_OF_TYPES | 61 NUMBER_OF_TYPES |
| 62 }; | 62 }; |
| 63 #undef DECLARE_TYPE | 63 #undef DECLARE_TYPE |
| 64 | 64 |
| 65 Type type; | 65 Type type; |
| 66 mutable unsigned order; | 66 unsigned order; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 | 69 |
| 70 class CodeCreateEventRecord : public CodeEventRecord { | 70 class CodeCreateEventRecord : public CodeEventRecord { |
| 71 public: | 71 public: |
| 72 Address start; | 72 Address start; |
| 73 CodeEntry* entry; | 73 CodeEntry* entry; |
| 74 unsigned size; | 74 unsigned size; |
| 75 Address shared; | 75 Address shared; |
| 76 | 76 |
| (...skipping 38 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 | |
| 140 // This class implements both the profile events processor thread and | 125 // This class implements both the profile events processor thread and |
| 141 // methods called by event producers: VM and stack sampler threads. | 126 // methods called by event producers: VM and stack sampler threads. |
| 142 class ProfilerEventsProcessor : public Thread { | 127 class ProfilerEventsProcessor : public Thread { |
| 143 public: | 128 public: |
| 144 ProfilerEventsProcessor(ProfileGenerator* generator, | 129 ProfilerEventsProcessor(ProfileGenerator* generator, |
| 145 CpuProfilesCollection* profiles); | 130 CpuProfilesCollection* profiles); |
| 146 virtual ~ProfilerEventsProcessor() {} | 131 virtual ~ProfilerEventsProcessor() {} |
| 147 | 132 |
| 148 // Thread control. | 133 // Thread control. |
| 149 virtual void Run(); | 134 virtual void Run(); |
| 150 inline void Stop() { running_ = false; } | 135 inline void Stop() { running_ = false; } |
| 151 INLINE(bool running()) { return running_; } | 136 INLINE(bool running()) { return running_; } |
| 152 void Enqueue(const CodeEventsContainer& event); | |
| 153 | 137 |
| 138 // 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 CodeDeleteEvent(Address from); |
| 156 void SharedFunctionInfoMoveEvent(Address from, Address to); |
| 157 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, |
| 158 const char* prefix, String* name, |
| 159 Address start, unsigned size); |
| 154 // Puts current stack into tick sample events buffer. | 160 // Puts current stack into tick sample events buffer. |
| 155 void AddCurrentStack(); | 161 void AddCurrentStack(); |
| 156 | 162 |
| 157 // Tick sample events are filled directly in the buffer of the circular | 163 // Tick sample events are filled directly in the buffer of the circular |
| 158 // queue (because the structure is of fixed width, but usually not all | 164 // queue (because the structure is of fixed width, but usually not all |
| 159 // stack frame entries are filled.) This method returns a pointer to the | 165 // stack frame entries are filled.) This method returns a pointer to the |
| 160 // next record of the buffer. | 166 // next record of the buffer. |
| 161 INLINE(TickSample* TickSampleEvent()); | 167 INLINE(TickSample* TickSampleEvent()); |
| 162 | 168 |
| 163 private: | 169 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 |
| 164 // Called from events processing thread (Run() method.) | 177 // Called from events processing thread (Run() method.) |
| 165 bool ProcessCodeEvent(unsigned* dequeue_order); | 178 bool ProcessCodeEvent(unsigned* dequeue_order); |
| 166 bool ProcessTicks(unsigned dequeue_order); | 179 bool ProcessTicks(unsigned dequeue_order); |
| 167 | 180 |
| 181 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); |
| 182 |
| 168 ProfileGenerator* generator_; | 183 ProfileGenerator* generator_; |
| 169 CpuProfilesCollection* profiles_; | 184 CpuProfilesCollection* profiles_; |
| 170 bool running_; | 185 bool running_; |
| 171 UnboundQueue<CodeEventsContainer> events_buffer_; | 186 UnboundQueue<CodeEventsContainer> events_buffer_; |
| 172 SamplingCircularQueue ticks_buffer_; | 187 SamplingCircularQueue ticks_buffer_; |
| 173 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 188 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
| 174 unsigned enqueue_order_; | 189 unsigned enqueue_order_; |
| 175 }; | 190 }; |
| 176 | 191 |
| 177 | 192 |
| 178 #define PROFILE(IsolateGetter, Call) \ | 193 #define PROFILE(IsolateGetter, Call) \ |
| 179 do { \ | 194 do { \ |
| 180 Isolate* cpu_profiler_isolate = (IsolateGetter); \ | 195 Isolate* cpu_profiler_isolate = (IsolateGetter); \ |
| 181 LOG_CODE_EVENT(cpu_profiler_isolate, Call); \ | 196 LOG_CODE_EVENT(cpu_profiler_isolate, Call); \ |
| 182 CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \ | 197 CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \ |
| 183 if (cpu_profiler->is_profiling()) { \ | 198 if (cpu_profiler->is_profiling()) { \ |
| 184 cpu_profiler->Call; \ | 199 cpu_profiler->Call; \ |
| 185 } \ | 200 } \ |
| 186 } while (false) | 201 } while (false) |
| 187 | 202 |
| 188 | 203 |
| 189 class CpuProfiler { | 204 class CpuProfiler { |
| 190 public: | 205 public: |
| 191 explicit CpuProfiler(Isolate* isolate); | 206 explicit CpuProfiler(Isolate* isolate); |
| 192 | |
| 193 CpuProfiler(Isolate* isolate, | |
| 194 CpuProfilesCollection* test_collection, | |
| 195 ProfileGenerator* test_generator, | |
| 196 ProfilerEventsProcessor* test_processor); | |
| 197 | |
| 198 ~CpuProfiler(); | 207 ~CpuProfiler(); |
| 199 | 208 |
| 200 void StartProfiling(const char* title, bool record_samples = false); | 209 void StartProfiling(const char* title, bool record_samples = false); |
| 201 void StartProfiling(String* title, bool record_samples); | 210 void StartProfiling(String* title, bool record_samples); |
| 202 CpuProfile* StopProfiling(const char* title); | 211 CpuProfile* StopProfiling(const char* title); |
| 203 CpuProfile* StopProfiling(Object* security_token, String* title); | 212 CpuProfile* StopProfiling(Object* security_token, String* title); |
| 204 int GetProfilesCount(); | 213 int GetProfilesCount(); |
| 205 CpuProfile* GetProfile(Object* security_token, int index); | 214 CpuProfile* GetProfile(Object* security_token, int index); |
| 206 CpuProfile* FindProfile(Object* security_token, unsigned uid); | 215 CpuProfile* FindProfile(Object* security_token, unsigned uid); |
| 207 void DeleteAllProfiles(); | 216 void DeleteAllProfiles(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 bool is_profiling_; | 269 bool is_profiling_; |
| 261 | 270 |
| 262 private: | 271 private: |
| 263 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 272 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 264 }; | 273 }; |
| 265 | 274 |
| 266 } } // namespace v8::internal | 275 } } // namespace v8::internal |
| 267 | 276 |
| 268 | 277 |
| 269 #endif // V8_CPU_PROFILER_H_ | 278 #endif // V8_CPU_PROFILER_H_ |
| OLD | NEW |