Commit 14ad529b authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cpu-profiler] Add a codeType to the tracing output

DevTools can't unambiguously determine whether code is JS or wasm.
This CL adds a string to the tracing output that will be 'JS', 'wasm' or
'other'.

Bug: chromium:1168052
Change-Id: Iaacb5ea9a83327e22d60bf6114f607e6fa5532ad
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2637859
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72193}
parent 2d2ae175
......@@ -16,9 +16,10 @@ CodeEntry::CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name,
const char* resource_name, int line_number,
int column_number,
std::unique_ptr<SourcePositionTable> line_info,
bool is_shared_cross_origin)
bool is_shared_cross_origin, CodeType code_type)
: bit_field_(TagField::encode(tag) |
BuiltinIdField::encode(Builtins::builtin_count) |
CodeTypeField::encode(code_type) |
SharedCrossOriginField::encode(is_shared_cross_origin)),
name_(name),
resource_name_(resource_name),
......
......@@ -98,28 +98,43 @@ base::LazyDynamicInstance<CodeEntry, CodeEntry::RootEntryCreateTrait>::type
CodeEntry::kRootEntry = LAZY_DYNAMIC_INSTANCE_INITIALIZER;
CodeEntry* CodeEntry::ProgramEntryCreateTrait::Create() {
return new CodeEntry(CodeEventListener::FUNCTION_TAG,
CodeEntry::kProgramEntryName);
return new CodeEntry(
CodeEventListener::FUNCTION_TAG, CodeEntry::kProgramEntryName,
CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo,
v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false,
CodeEntry::CodeType::OTHER);
}
CodeEntry* CodeEntry::IdleEntryCreateTrait::Create() {
return new CodeEntry(CodeEventListener::FUNCTION_TAG,
CodeEntry::kIdleEntryName);
CodeEntry::kIdleEntryName, CodeEntry::kEmptyResourceName,
v8::CpuProfileNode::kNoLineNumberInfo,
v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false,
CodeEntry::CodeType::OTHER);
}
CodeEntry* CodeEntry::GCEntryCreateTrait::Create() {
return new CodeEntry(CodeEventListener::BUILTIN_TAG,
CodeEntry::kGarbageCollectorEntryName);
return new CodeEntry(
CodeEventListener::BUILTIN_TAG, CodeEntry::kGarbageCollectorEntryName,
CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo,
v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false,
CodeEntry::CodeType::OTHER);
}
CodeEntry* CodeEntry::UnresolvedEntryCreateTrait::Create() {
return new CodeEntry(CodeEventListener::FUNCTION_TAG,
CodeEntry::kUnresolvedFunctionName);
return new CodeEntry(
CodeEventListener::FUNCTION_TAG, CodeEntry::kUnresolvedFunctionName,
CodeEntry::kEmptyResourceName, v8::CpuProfileNode::kNoLineNumberInfo,
v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false,
CodeEntry::CodeType::OTHER);
}
CodeEntry* CodeEntry::RootEntryCreateTrait::Create() {
return new CodeEntry(CodeEventListener::FUNCTION_TAG,
CodeEntry::kRootEntryName);
CodeEntry::kRootEntryName, CodeEntry::kEmptyResourceName,
v8::CpuProfileNode::kNoLineNumberInfo,
v8::CpuProfileNode::kNoColumnNumberInfo, nullptr, false,
CodeEntry::CodeType::OTHER);
}
uint32_t CodeEntry::GetHash() const {
......@@ -562,6 +577,7 @@ void BuildNodeValue(const ProfileNode* node, TracedValue* value) {
if (entry->column_number()) {
value->SetInteger("columnNumber", entry->column_number() - 1);
}
value->SetString("codeType", entry->code_type_string());
value->EndDictionary();
value->SetInteger("id", node->id());
if (node->parent()) {
......
......@@ -59,6 +59,8 @@ struct CodeEntryAndLineNumber;
class CodeEntry {
public:
enum class CodeType { JS, WASM, OTHER };
// CodeEntry may reference strings (|name|, |resource_name|) managed by a
// StringsStorage instance. These must be freed via ReleaseStrings.
inline CodeEntry(CodeEventListener::LogEventsAndTags tag, const char* name,
......@@ -66,7 +68,8 @@ class CodeEntry {
int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
int column_number = v8::CpuProfileNode::kNoColumnNumberInfo,
std::unique_ptr<SourcePositionTable> line_info = nullptr,
bool is_shared_cross_origin = false);
bool is_shared_cross_origin = false,
CodeType code_type = CodeType::JS);
CodeEntry(const CodeEntry&) = delete;
CodeEntry& operator=(const CodeEntry&) = delete;
......@@ -102,6 +105,17 @@ class CodeEntry {
void mark_used() { bit_field_ = UsedField::update(bit_field_, true); }
bool used() const { return UsedField::decode(bit_field_); }
const char* code_type_string() const {
switch (CodeTypeField::decode(bit_field_)) {
case CodeType::JS:
return "JS";
case CodeType::WASM:
return "wasm";
case CodeType::OTHER:
return "other";
}
}
void FillFunctionInfo(SharedFunctionInfo shared);
void SetBuiltinId(Builtins::Name id);
......@@ -213,13 +227,16 @@ class CodeEntry {
CodeEntry, RootEntryCreateTrait>::type kRootEntry;
using TagField = base::BitField<CodeEventListener::LogEventsAndTags, 0, 8>;
using BuiltinIdField = base::BitField<Builtins::Name, 8, 22>;
using BuiltinIdField = base::BitField<Builtins::Name, 8, 20>;
static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues,
"builtin_count exceeds size of bitfield");
using CodeTypeField = base::BitField<CodeType, 28, 2>;
using UsedField = base::BitField<bool, 30, 1>;
using SharedCrossOriginField = base::BitField<bool, 31, 1>;
uint32_t bit_field_;
// Atomic because Used is written from the profiler thread while CodeType is
// read from the main thread.
std::atomic<std::uint32_t> bit_field_;
const char* name_;
const char* resource_name_;
int line_number_;
......
......@@ -208,8 +208,9 @@ void ProfilerListener::CodeCreateEvent(LogEventsAndTags tag,
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
rec->instruction_start = code->instruction_start();
rec->entry = new CodeEntry(tag, GetName(name), GetName(source_url), 1,
code_offset + 1, nullptr, true);
rec->entry =
new CodeEntry(tag, GetName(name), GetName(source_url), 1, code_offset + 1,
nullptr, true, CodeEntry::CodeType::WASM);
rec->entry->set_script_id(script_id);
rec->entry->set_position(code_offset);
rec->instruction_size = code->instructions().length();
......
......@@ -2925,7 +2925,10 @@ TEST(TracingCpuProfiler) {
const profile_header = json[0];
if (typeof profile_header['startTime'] !== 'number')
return false;
return json.some(event => (event.lines || []).some(line => line));
return json.some(event => (event.lines || []).some(line => line)) &&
json.filter(e => e.cpuProfile && e.cpuProfile.nodes)
.some(e => e.cpuProfile.nodes
.some(n => n.callFrame.codeType == "JS"));
}
checkProfile()" + profile_json +
")";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment