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

Side by Side Diff: src/profile-generator.h

Issue 910002: Start migrating profiles processing to C++. (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
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_PROFILE_GENERATOR_H_
29 #define V8_PROFILE_GENERATOR_H_
30
31 #include "hashmap.h"
32
33 namespace v8 {
34 namespace internal {
35
36
37 class CodeEntry {
38 public:
39 virtual ~CodeEntry() { }
40
41 virtual const char* name() = 0;
42 INLINE(bool is_js_function());
43
44 protected:
45 INLINE(explicit CodeEntry(Logger::LogEventsAndTags tag))
46 : tag_(tag) { }
47
48 private:
49 Logger::LogEventsAndTags tag_;
50
51 DISALLOW_COPY_AND_ASSIGN(CodeEntry);
52 };
53
54
55 class StaticNameCodeEntry : public CodeEntry {
56 public:
57 INLINE(StaticNameCodeEntry(Logger::LogEventsAndTags tag,
58 const char* name));
59
60 INLINE(virtual const char* name()) { return name_ != NULL ? name_ : ""; }
61
62 private:
63 const char* name_;
64
65 DISALLOW_COPY_AND_ASSIGN(StaticNameCodeEntry);
66 };
67
68
69 class ManagedNameCodeEntry : public CodeEntry {
70 public:
71 INLINE(ManagedNameCodeEntry(Logger::LogEventsAndTags tag,
72 String* name,
73 const char* resource_name, int line_number));
74
75 INLINE(virtual const char* name()) { return !name_.is_empty() ? *name_ : ""; }
76
77 private:
78 SmartPointer<char> name_;
79 const char* resource_name_;
80 int line_number_;
81
82 DISALLOW_COPY_AND_ASSIGN(ManagedNameCodeEntry);
83 };
84
85
86 class ProfileNode {
87 public:
88 INLINE(explicit ProfileNode(CodeEntry* entry));
89
90 ProfileNode* FindChild(CodeEntry* entry);
91 ProfileNode* FindOrAddChild(CodeEntry* entry);
92 INLINE(void IncrementSelfTicks()) { ++self_ticks_; }
93 INLINE(void IncreaseTotalTicks(unsigned amount)) { total_ticks_ += amount; }
94
95 INLINE(unsigned total_ticks()) { return total_ticks_; }
96 INLINE(unsigned self_ticks()) { return self_ticks_; }
97
98 void Print(int indent);
99
100 private:
101 INLINE(static bool CodeEntriesMatch(void* key1, void* key2)) {
102 return key1 == key2;
103 }
104
105 INLINE(static bool CodeEntryHash(CodeEntry* entry)) {
106 return static_cast<int32_t>(reinterpret_cast<intptr_t>(entry));
107 }
108
109 CodeEntry* entry_;
110 unsigned total_ticks_;
111 unsigned self_ticks_;
112 // CodeEntry* -> ProfileNode*
113 HashMap children_;
114
115 friend class ProfileTree;
116
117 DISALLOW_COPY_AND_ASSIGN(ProfileNode);
118 };
119
120
121 class ProfileTree BASE_EMBEDDED {
122 public:
123 ProfileTree() : root_(new ProfileNode(NULL)) { }
124 ~ProfileTree();
125
126 void AddPathFromEnd(const Vector<CodeEntry*>& path);
127 void AddPathFromStart(const Vector<CodeEntry*>& path);
128 void CalculateTotalTicks();
129
130 ProfileNode* root() { return root_; }
131
132 void ShortPrint();
133 void Print() {
134 root_->Print(0);
135 }
136
137 private:
138 template <typename Callback>
139 void TraverseBreadthFirstPostOrder(Callback* callback);
140
141 ProfileNode* root_;
142
143 DISALLOW_COPY_AND_ASSIGN(ProfileTree);
144 };
145
146
147 class CpuProfile BASE_EMBEDDED {
148 public:
149 CpuProfile() { }
150 // Add pc -> ... -> main() call path to the profile.
151 void AddPath(const Vector<CodeEntry*>& path);
152 void CalculateTotalTicks();
153
154 void ShortPrint();
155 void Print();
156
157 private:
158 ProfileTree top_down_;
159 ProfileTree bottom_up_;
160
161 DISALLOW_COPY_AND_ASSIGN(CpuProfile);
162 };
163
164
165 class CodeMap BASE_EMBEDDED {
166 public:
167 CodeMap() { }
168 INLINE(void AddCode(Address addr, CodeEntry* entry, unsigned size));
169 INLINE(void MoveCode(Address from, Address to));
170 INLINE(void DeleteCode(Address addr));
171 void AddAlias(Address alias, Address addr);
172 CodeEntry* FindEntry(Address addr);
173
174 private:
175 struct CodeEntryInfo {
176 CodeEntryInfo(CodeEntry* an_entry, unsigned a_size)
177 : entry(an_entry), size(a_size) { }
178 CodeEntry* entry;
179 unsigned size;
180 };
181
182 struct CodeTreeConfig {
183 typedef Address Key;
184 typedef CodeEntryInfo Value;
185 static const Key kNoKey;
186 static const Value kNoValue;
187 static int Compare(const Key& a, const Key& b) {
188 return a < b ? -1 : (a > b ? 1 : 0);
189 }
190 };
191 typedef SplayTree<CodeTreeConfig> CodeTree;
192
193 CodeTree tree_;
194
195 DISALLOW_COPY_AND_ASSIGN(CodeMap);
196 };
197
198
199 class ProfileGenerator {
200 public:
201 ProfileGenerator();
202 ~ProfileGenerator();
203
204 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag,
205 String* name, String* resource_name, int line_number);
206 CodeEntry* NewCodeEntry(Logger::LogEventsAndTags tag, const char* name);
207
208 INLINE(CpuProfile* profile()) { return &profile_; }
209 INLINE(CodeMap* code_map()) { return &code_map_; }
210
211 private:
212 INLINE(static bool StringsMatch(void* key1, void* key2)) {
213 return key1 == key2;
214 }
215
216 INLINE(static bool StringEntryHash(String* entry)) {
217 return entry->Hash();
218 }
219
220 CpuProfile profile_;
221 CodeMap code_map_;
222 typedef List<CodeEntry*> CodeEntryList;
223 CodeEntryList code_entries_;
224 // String::Hash -> const char*
225 HashMap resource_names_;
226
227 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator);
228 };
229
230
231 } } // namespace v8::internal
232
233 #endif // V8_PROFILE_GENERATOR_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/profile-generator.cc » ('j') | src/profile-generator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698