我有一个基于类型记录的React项目,在这个项目中,我正在运行开玩笑的测试(也是在TS中)。我可以很好地运行测试,但我试图分析一些需要相当长时间运行的测试的性能。我试过使用用于测试的Chrome Devtools,但是它失败了,因为它是TS而不是普通的Js。是否有任何方法可以单独分析我的测试,以查看性能问题在哪里发生?使用VS代码。
发布于 2022-11-17 17:49:49
对于我来说,这不是一个React项目,它只是一个常规的TypeScript库,但我敢打赌,这也适用于您的用例。我要把这个留在这里,如果它是有用的,或者是为了将来的我。
我发现唯一有效的解决方案是手动设置分析器V8-分析器-下一个。
import v8Profiler from 'v8-profiler-next';
v8Profiler.setGenerateType(1);
const title = 'good-name';
describe('Should be able to generate with inputs', () => {
v8Profiler.startProfiling(title, true);
afterAll(() => {
const profile = v8Profiler.stopProfiling(title);
profile.export(function (error, result: any) {
// if it doesn't have the extension .cpuprofile then
// chrome's profiler tool won't like it.
// examine the profile:
// Navigate to chrome://inspect
// Click Open dedicated DevTools for Node
// Select the profiler tab
// Load your file
fs.writeFileSync(`${title}.cpuprofile`, result);
profile.delete();
});
});
test('....', async () => {
// Add test
});
});这将为您提供这样的CPU配置文件,它可以很好地用于TypeScript。

https://stackoverflow.com/questions/70771838
复制相似问题