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/ic/ic-stats.cc

Issue 2503183002: [Tracing] Implement IC statistics in tracing. (Closed)
Patch Set: update Created 4 years 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 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/ic/ic-stats.h"
6
7 #include "src/flags.h"
8 #include "src/objects-inl.h"
9 #include "src/tracing/trace-event.h"
10 #include "src/tracing/traced-value.h"
11 #include "src/v8.h"
12
13 namespace v8 {
14 namespace internal {
15
16 base::LazyInstance<ICStats>::type ICStats::instance_ =
17 LAZY_INSTANCE_INITIALIZER;
18
19 ICStats::ICStats() : ic_infos_(MAX_IC_INFO), pos_(0) {
20 base::NoBarrier_Store(&enabled_, 0);
21 }
22
23 void ICStats::Begin() {
24 if (V8_LIKELY(!FLAG_ic_stats)) return;
25 base::NoBarrier_Store(&enabled_, 1);
26 }
27
28 void ICStats::End() {
29 if (base::NoBarrier_Load(&enabled_) != 1) return;
30 ++pos_;
31 if (pos_ == MAX_IC_INFO) {
32 Dump();
33 }
34 base::NoBarrier_Store(&enabled_, 0);
35 }
36
37 void ICStats::Reset() {
38 for (auto ic_info : ic_infos_) {
39 ic_info.Reset();
40 }
41 pos_ = 0;
42 }
43
44 void ICStats::Dump() {
45 auto value = v8::tracing::TracedValue::Create();
46 value->BeginArray("data");
47 for (int i = 0; i < pos_; ++i) {
48 ic_infos_[i].AppendToTracedValue(value.get());
49 }
50 value->EndArray();
51
52 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("v8.ic_stats"), "V8.ICStats",
53 TRACE_EVENT_SCOPE_THREAD, "ic-stats", std::move(value));
54 Reset();
55 }
56
57 const char* ICStats::GetOrCacheScriptName(Object* obj) {
58 if (script_name_map_.find(obj) != script_name_map_.end()) {
59 return script_name_map_[obj].get();
60 }
61 Script* script = Script::cast(obj);
62 Object* script_name_raw = script->name();
63 if (script_name_raw->IsString()) {
64 String* script_name = String::cast(script_name_raw);
65 char* c_script_name =
66 script_name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL)
67 .release();
68 script_name_map_.insert(
69 std::make_pair(obj, std::unique_ptr<char[]>(c_script_name)));
70 return c_script_name;
71 } else {
72 script_name_map_.insert(
73 std::make_pair(obj, std::unique_ptr<char[]>(nullptr)));
74 return nullptr;
75 }
76 return nullptr;
77 }
78
79 const char* ICStats::GetOrCacheFunctionName(JSFunction* function) {
80 if (function_name_map_.find(function) != function_name_map_.end()) {
81 return function_name_map_[function].get();
82 }
83 SharedFunctionInfo* shared = function->shared();
84 ic_infos_[pos_].is_optimized = function->IsOptimized();
85 char* function_name = shared->DebugName()->ToCString().release();
86 function_name_map_.insert(
87 std::make_pair(function, std::unique_ptr<char[]>(function_name)));
88 return function_name;
89 }
90
91 ICInfo::ICInfo()
92 : function_name(nullptr),
93 script_offset(0),
94 script_name(nullptr),
95 line_num(-1),
96 is_constructor(false),
97 is_optimized(false),
98 map(nullptr),
99 is_dictionary_map(0),
100 number_of_own_descriptors(0) {}
101
102 void ICInfo::Reset() {
103 type.clear();
104 function_name = nullptr;
105 script_offset = 0;
106 script_name = nullptr;
107 line_num = -1;
108 is_constructor = false;
109 is_optimized = false;
110 state.clear();
111 map = nullptr;
112 is_dictionary_map = false;
113 number_of_own_descriptors = 0;
114 instance_type.clear();
115 }
116
117 void ICInfo::AppendToTracedValue(v8::tracing::TracedValue* value) const {
118 value->BeginDictionary();
119 value->SetString("type", type);
120 if (function_name) {
121 value->SetString("functionName", function_name);
122 if (is_optimized) {
123 value->SetInteger("optimized", is_optimized);
124 }
125 }
126 if (script_offset) value->SetInteger("offset", script_offset);
127 if (script_name) value->SetString("scriptName", script_name);
128 if (line_num != -1) value->SetInteger("lineNum", line_num);
129 if (is_constructor) value->SetInteger("constructor", is_constructor);
130 if (!state.empty()) value->SetString("state", state);
131 if (map) {
132 // V8 cannot represent integer above 2^53 - 1 in JavaScript from JSON,
133 // thus `map` should be converted to a string rather than an integer.
134 std::stringstream ss;
135 ss << map;
136 value->SetString("map", ss.str());
137 }
138 if (map) value->SetInteger("dict", is_dictionary_map);
139 if (map) value->SetInteger("own", number_of_own_descriptors);
140 if (!instance_type.empty()) value->SetString("instanceType", instance_type);
141 value->EndDictionary();
142 }
143
144 } // namespace internal
145 } // namespace v8
OLDNEW
« src/frames.cc ('K') | « src/ic/ic-stats.h ('k') | src/tracing/tracing-category-observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698