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

Side by Side Diff: src/runtime/runtime.cc

Issue 1615943002: Runtime call counters and timers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tweaks Created 4 years, 11 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/runtime/runtime.h ('k') | src/runtime/runtime-internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime.h" 5 #include "src/runtime/runtime.h"
6 6
7 #include <iomanip>
8
7 #include "src/assembler.h" 9 #include "src/assembler.h"
8 #include "src/contexts.h" 10 #include "src/contexts.h"
9 #include "src/handles-inl.h" 11 #include "src/handles-inl.h"
10 #include "src/heap/heap.h" 12 #include "src/heap/heap.h"
11 #include "src/isolate.h" 13 #include "src/isolate.h"
12 #include "src/runtime/runtime-utils.h" 14 #include "src/runtime/runtime-utils.h"
13 15
14 namespace v8 { 16 namespace v8 {
15 namespace internal { 17 namespace internal {
16 18
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } else { 125 } else {
124 return kIntrinsicFunctions; 126 return kIntrinsicFunctions;
125 } 127 }
126 } 128 }
127 129
128 130
129 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) { 131 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
130 return os << Runtime::FunctionForId(id)->name; 132 return os << Runtime::FunctionForId(id)->name;
131 } 133 }
132 134
135
136 class RuntimeCallStatEntries {
137 public:
138 void Print(std::ostream& os) {
139 if (total_call_count > 0) {
140 std::sort(entries.rbegin(), entries.rend());
141 os << "Runtime function Time "
142 "Count"
143 << std::endl
144 << std::string(70, '=') << std::endl;
145 for (Entry& entry : entries) {
146 entry.Print(os);
147 }
148 os << std::string(60, '-') << std::endl;
149 Entry("Total", total_time, total_call_count).Print(os);
150 }
151 }
152
153 void Add(const char* name, base::TimeDelta time, uint32_t count) {
154 entries.push_back(Entry(name, time, count));
155 total_time += time;
156 total_call_count += count;
157 }
158
159 private:
160 class Entry {
161 public:
162 Entry(const char* name, base::TimeDelta time, uint64_t count)
163 : name_(name), time_(time.InMilliseconds()), count_(count) {}
164
165 bool operator<(const Entry& other) const {
166 if (time_ < other.time_) return true;
167 if (time_ > other.time_) return false;
168 return count_ < other.count_;
169 }
170
171 void Print(std::ostream& os) {
172 os << std::setw(50) << name_;
173 os << std::setw(8) << time_ << "ms";
174 os << std::setw(10) << count_ << std::endl;
175 }
176
177 private:
178 const char* name_;
179 int64_t time_;
180 uint64_t count_;
181 };
182
183 uint64_t total_call_count = 0;
184 base::TimeDelta total_time;
185 std::vector<Entry> entries;
186 };
187
188
189 void RuntimeCallStats::Print(std::ostream& os) {
190 RuntimeCallStatEntries entries;
191
192 #define PRINT_COUNTER(name, nargs, ressize) \
193 if (this->Count_Runtime_##name > 0) { \
194 entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \
195 }
196 FOR_EACH_INTRINSIC(PRINT_COUNTER)
197 #undef PRINT_COUNTER
198 entries.Print(os);
199 }
200
201
202 void RuntimeCallStats::Reset() {
203 #define RESET_COUNTER(name, nargs, ressize) \
204 Count_Runtime_##name = 0; \
205 Time_Runtime_##name = base::TimeDelta();
206 FOR_EACH_INTRINSIC(RESET_COUNTER)
207 #undef RESET_COUNTER
208 }
209
133 } // namespace internal 210 } // namespace internal
134 } // namespace v8 211 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698