[wasm] register WASM code creation event for profilers
Also remove duplicate code Disassemble, which is already done in TF pipeline. BUG= Review URL: https://codereview.chromium.org/1634653002 Cr-Commit-Position: refs/heads/master@{#33610}
This commit is contained in:
parent
5a7bb33e3f
commit
5c7134a98e
@ -29,6 +29,9 @@
|
||||
|
||||
#include "src/code-factory.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/factory.h"
|
||||
#include "src/log-inl.h"
|
||||
#include "src/profiler/cpu-profiler.h"
|
||||
|
||||
#include "src/wasm/ast-decoder.h"
|
||||
#include "src/wasm/wasm-module.h"
|
||||
@ -1871,6 +1874,28 @@ Node* WasmGraphBuilder::String(const char* string) {
|
||||
Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); }
|
||||
|
||||
|
||||
static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
||||
CompilationInfo* info,
|
||||
const char* message, uint32_t index,
|
||||
const char* func_name) {
|
||||
Isolate* isolate = info->isolate();
|
||||
if (isolate->logger()->is_logging_code_events() ||
|
||||
isolate->cpu_profiler()->is_profiling()) {
|
||||
ScopedVector<char> buffer(128);
|
||||
SNPrintF(buffer, "%s#%d:%s", message, index, func_name);
|
||||
Handle<String> name_str =
|
||||
isolate->factory()->NewStringFromAsciiChecked(buffer.start());
|
||||
Handle<String> script_str =
|
||||
isolate->factory()->NewStringFromAsciiChecked("(WASM)");
|
||||
Handle<Code> code = info->code();
|
||||
Handle<SharedFunctionInfo> shared =
|
||||
isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
|
||||
PROFILE(isolate,
|
||||
CodeCreateEvent(tag, *code, *shared, info, *script_str, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<JSFunction> CompileJSToWasmWrapper(
|
||||
Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name,
|
||||
Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) {
|
||||
@ -1942,21 +1967,8 @@ Handle<JSFunction> CompileJSToWasmWrapper(
|
||||
CompilationInfo info("js-to-wasm", isolate, &zone, flags);
|
||||
Handle<Code> code =
|
||||
Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
// Disassemble the wrapper code for debugging.
|
||||
if (!code.is_null() && FLAG_print_opt_code) {
|
||||
Vector<char> buffer;
|
||||
const char* name = "";
|
||||
if (func->name_offset > 0) {
|
||||
const byte* ptr = module->module->module_start + func->name_offset;
|
||||
name = reinterpret_cast<const char*>(ptr);
|
||||
}
|
||||
SNPrintF(buffer, "JS->WASM function wrapper #%d:%s", index, name);
|
||||
OFStream os(stdout);
|
||||
code->Disassemble(buffer.start(), os);
|
||||
}
|
||||
#endif
|
||||
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index,
|
||||
module->module->GetName(func->name_offset));
|
||||
// Set the JSFunction's machine code.
|
||||
function->set_code(*code);
|
||||
}
|
||||
@ -2017,20 +2029,8 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
|
||||
CompilationInfo info("wasm-to-js", isolate, &zone, flags);
|
||||
code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
// Disassemble the wrapper code for debugging.
|
||||
if (!code.is_null() && FLAG_print_opt_code) {
|
||||
Vector<char> buffer;
|
||||
const char* name = "";
|
||||
if (func->name_offset > 0) {
|
||||
const byte* ptr = module->module->module_start + func->name_offset;
|
||||
name = reinterpret_cast<const char*>(ptr);
|
||||
}
|
||||
SNPrintF(buffer, "WASM->JS function wrapper #%d:%s", index, name);
|
||||
OFStream os(stdout);
|
||||
code->Disassemble(buffer.start(), os);
|
||||
}
|
||||
#endif
|
||||
RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index,
|
||||
module->module->GetName(func->name_offset));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
@ -2081,7 +2081,7 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
|
||||
os << "Compilation failed: " << result << std::endl;
|
||||
}
|
||||
// Add the function as another context for the exception
|
||||
Vector<char> buffer;
|
||||
ScopedVector<char> buffer(128);
|
||||
SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index,
|
||||
module_env->module->GetName(function.name_offset));
|
||||
thrower.Failed(buffer.start(), result);
|
||||
@ -2092,24 +2092,29 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
|
||||
CallDescriptor* descriptor = const_cast<CallDescriptor*>(
|
||||
module_env->GetWasmCallDescriptor(&zone, function.sig));
|
||||
Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION);
|
||||
CompilationInfo info("wasm", isolate, &zone, flags);
|
||||
// add flags here if a meaningful name is helpful for debugging.
|
||||
bool debugging =
|
||||
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
|
||||
const char* func_name = "wasm";
|
||||
Vector<char> buffer;
|
||||
if (debugging) {
|
||||
buffer = Vector<char>::New(128);
|
||||
SNPrintF(buffer, "WASM_function_#%d:%s", index,
|
||||
module_env->module->GetName(function.name_offset));
|
||||
func_name = buffer.start();
|
||||
}
|
||||
CompilationInfo info(func_name, isolate, &zone, flags);
|
||||
Handle<Code> code =
|
||||
Pipeline::GenerateCodeForTesting(&info, descriptor, &graph);
|
||||
if (debugging) {
|
||||
buffer.Dispose();
|
||||
}
|
||||
if (!code.is_null()) {
|
||||
RecordFunctionCompilation(
|
||||
Logger::FUNCTION_TAG, &info, "WASM_function", index,
|
||||
module_env->module->GetName(function.name_offset));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
// Disassemble the code for debugging.
|
||||
if (!code.is_null() && FLAG_print_opt_code) {
|
||||
Vector<char> buffer;
|
||||
const char* name = "";
|
||||
if (function.name_offset > 0) {
|
||||
const byte* ptr = module_env->module->module_start + function.name_offset;
|
||||
name = reinterpret_cast<const char*>(ptr);
|
||||
}
|
||||
SNPrintF(buffer, "WASM function #%d:%s", index, name);
|
||||
OFStream os(stdout);
|
||||
code->Disassemble(buffer.start(), os);
|
||||
}
|
||||
#endif
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -105,8 +105,8 @@ struct WasmModule {
|
||||
|
||||
// Get a pointer to a string stored in the module bytes representing a name.
|
||||
const char* GetName(uint32_t offset) {
|
||||
CHECK(BoundsCheck(offset, offset + 1));
|
||||
if (offset == 0) return "<?>"; // no name.
|
||||
CHECK(BoundsCheck(offset, offset + 1));
|
||||
return reinterpret_cast<const char*>(module_start + offset);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user