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

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

Issue 1079006: Add basic C++ implementation of CPU profiler. (Closed)
Patch Set: Comments addressed Created 10 years, 9 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
« no previous file with comments | « src/SConscript ('k') | src/cpu-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 #ifndef V8_CPU_PROFILER_H_
29 #define V8_CPU_PROFILER_H_
30
31 #include "circular-queue.h"
32 #include "profile-generator.h"
33
34 namespace v8 {
35 namespace internal {
36
37
38 #define CODE_EVENTS_TYPE_LIST(V) \
39 V(CODE_CREATION, CodeCreateEventRecord) \
40 V(CODE_MOVE, CodeMoveEventRecord) \
41 V(CODE_DELETE, CodeDeleteEventRecord) \
42 V(CODE_ALIAS, CodeAliasEventRecord)
43
44
45 class CodeEventRecord {
46 public:
47 #define DECLARE_TYPE(type, ignore) type,
48 enum Type {
49 NONE = 0,
50 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE)
51 NUMBER_OF_TYPES
52 };
53 #undef DECLARE_TYPE
54
55 Type type;
56 unsigned order;
57 };
58
59
60 class CodeCreateEventRecord : public CodeEventRecord {
61 public:
62 Address start;
63 CodeEntry* entry;
64 unsigned size;
65
66 INLINE(void UpdateCodeMap(CodeMap* code_map)) {
67 code_map->AddCode(start, entry, size);
68 }
69 };
70
71
72 class CodeMoveEventRecord : public CodeEventRecord {
73 public:
74 Address from;
75 Address to;
76
77 INLINE(void UpdateCodeMap(CodeMap* code_map)) {
78 code_map->MoveCode(from, to);
79 }
80 };
81
82
83 class CodeDeleteEventRecord : public CodeEventRecord {
84 public:
85 Address start;
86
87 INLINE(void UpdateCodeMap(CodeMap* code_map)) {
88 code_map->DeleteCode(start);
89 }
90 };
91
92
93 class CodeAliasEventRecord : public CodeEventRecord {
94 public:
95 Address alias;
96 Address start;
97
98 INLINE(void UpdateCodeMap(CodeMap* code_map)) {
99 code_map->AddAlias(alias, start);
100 }
101 };
102
103
104 class TickSampleEventRecord {
105 public:
106 // In memory, the first machine word of a TickSampleEventRecord will be the
107 // first entry of TickSample, that is -- a program counter field.
108 // TickSample is put first, because 'order' can become equal to
109 // SamplingCircularQueue::kClear, while program counter can't.
110 TickSample sample;
111 unsigned order;
112
113 private:
114 // Disable instantiation.
115 TickSampleEventRecord();
116
117 DISALLOW_COPY_AND_ASSIGN(TickSampleEventRecord);
118 };
119
120
121 // This class implements both the profile events processor thread and
122 // methods called by event producers: VM and stack sampler threads.
123 class ProfilerEventsProcessor : public Thread {
124 public:
125 explicit ProfilerEventsProcessor(ProfileGenerator* generator);
126 virtual ~ProfilerEventsProcessor() { }
127
128 // Thread control.
129 virtual void Run();
130 inline void Stop() { running_ = false; }
131
132 // Events adding methods. Called by VM threads.
133 void CodeCreateEvent(Logger::LogEventsAndTags tag,
134 String* name,
135 String* resource_name, int line_number,
136 Address start, unsigned size);
137 void CodeCreateEvent(Logger::LogEventsAndTags tag,
138 const char* name,
139 Address start, unsigned size);
140 void CodeCreateEvent(Logger::LogEventsAndTags tag,
141 int args_count,
142 Address start, unsigned size);
143 void CodeMoveEvent(Address from, Address to);
144 void CodeDeleteEvent(Address from);
145 void FunctionCreateEvent(Address alias, Address start);
146 void FunctionMoveEvent(Address from, Address to);
147 void FunctionDeleteEvent(Address from);
148
149 // Tick sampler registration. Called by sampler thread or signal handler.
150 inline void SetUpSamplesProducer() { ticks_buffer_.SetUpProducer(); }
151 // Tick sample events are filled directly in the buffer of the circular
152 // queue (because the structure is of fixed width, but usually not all
153 // stack frame entries are filled.) This method returns a pointer to the
154 // next record of the buffer.
155 INLINE(TickSample* TickSampleEvent());
156 inline void TearDownSamplesProducer() { ticks_buffer_.TearDownProducer(); }
157
158 private:
159 union CodeEventsContainer {
160 CodeEventRecord generic;
161 #define DECLARE_CLASS(ignore, type) type type##_;
162 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS)
163 #undef DECLARE_TYPE
164 };
165
166 // Called from events processing thread (Run() method.)
167 bool ProcessCodeEvent(unsigned* dequeue_order);
168 bool ProcessTicks(unsigned dequeue_order);
169
170 ProfileGenerator* generator_;
171 bool running_;
172 CircularQueue<CodeEventsContainer> events_buffer_;
173 SamplingCircularQueue ticks_buffer_;
174 unsigned enqueue_order_;
175 };
176
177
178 } } // namespace v8::internal
179
180 #endif // V8_CPU_PROFILER_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/cpu-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698