node/deps/v8/test/mjsunit/asm/log-lazy-code.js
Michaël Zasso 9d7cd9b864
deps: update V8 to 12.8.374.13
PR-URL: https://github.com/nodejs/node/pull/54077
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2024-08-16 16:03:01 +02:00

59 lines
1.7 KiB
JavaScript

// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --log-function-events
// Increase the profiler sampling interval to avoid a data race between
// interval-triggered samples and explicitly triggered samples. The goal of the
// big interval is to avoid any interval-triggered samples.
// Flags: --cpu-profiler-sampling-interval=1000000
let sampleCollected = false;
function OnProfilerSampleCallback(profile) {
profile = profile.replaceAll('\\', '/');
profile = JSON.parse(profile);
let functionNames = profile.nodes.map(n => n.callFrame.functionName);
for (let i = 0; i < functionNames.length; ++i) {
if (functionNames[i].startsWith('js-to-wasm')) {
assertTrue(functionNames[i + 1].startsWith('f'));
assertTrue(functionNames[i + 2].startsWith('wasm-to-js'));
assertTrue(functionNames[i + 3].startsWith('g'));
// {sampleCollected} is set at the end because the asserts above don't
// show up in the test runner, probably because this function is called as
// a callback from d8.
sampleCollected = true;
return;
}
}
assertUnreachable();
}
d8.profiler.setOnProfileEndListener(OnProfilerSampleCallback);
function Asm(stdlib, imports, buffer) {
"use asm";
var g = imports.g;
function f(i) {
i = i|0;
return g() | 0;
}
return { f: f };
}
var heap = new ArrayBuffer(64*1024);
function g() {
d8.profiler.triggerSample();
console.profileEnd();
return 42;
}
var asm = Asm(this, {g: g}, heap);
assertTrue(%IsAsmWasmCode(Asm));
console.profile();
asm.f(3);
assertTrue(sampleCollected);