facebook / memlab

A framework for finding JavaScript memory leaks and analyzing heap snapshots
https://facebook.github.io/memlab/
MIT License
4.37k stars 119 forks source link

how to get leak info from memlab console #115

Closed susakin closed 6 months ago

susakin commented 7 months ago

c828a1cad4cfb89b11c3bff12fe3176 image

你好 我现在利用memlab 我其实需要最终 memlab console 出来的信息 ,如果我利用run方法或者findLeaks 这两个方法,最终输出来的结果没有,memlab执行再控制台输出的 直观,是不是用错方法了,或者还有其他方式能 获取这些leak信息

谢谢

JacksonGL commented 7 months ago

node.js 里用 run API 和 findLeaks API,输出结果应该和 CLI 里面用 memlab run ...memlab find-leaks ... 在console里面输出结果是一样的(就像你的第一个截图)。第二张截图好像不是 memlab run 或者 find-leaks 的输出。

所有console输出同时也在 ${workDir}/data/cur/console-log.txt 里面有备份。


In Node.js, using the run API and findLeaks API should produce the same console output as using memlab run ... and memlab find-leaks ... in the command-line interface (similar to your first screenshot). It seems like the output in the second screenshot isn't from the memlab run or find-leaks command.

All console outputs are also backed up in ${workDir}/data/cur/console-log.txt.

susakin commented 7 months ago

你好 谢谢回复 我没有表达清楚我的意思,第一张是使用memlab cli 跑出直接输出的内容,第二个截图使用program api,一个是用cli命令 一个是直接使用memlab 提供的api 执行的结果,两者输出的关于leak 格式不太一致。

JacksonGL commented 7 months ago

能否share一下得到第二个截图的代码?这个是JSON.stringify序列化了run API 的返回值吗?


Can you share your code that got you the second screenshot? Did you pass the return value of the run API to JSON.stringify?

susakin commented 6 months ago

image 你好这个就是 我使用的方式,跟直接cli 抛出来输出的信息不一致

JacksonGL commented 6 months ago

CLI 输出的是无结构的string representation方便阅读。findLeaks API 调用返回的是结构化的memory leak信息便于调用程序进行后续处理。如果需要得到CLI的string输出结果可以从${workDir}/data/cur/console-log.txt读取。

const fs = require('fs');
const path = require('path');

const workDir = createMyWorkDir();
const runResult = await takeSnapshots({scenario, workDir})
const leaks = await findLeaks(runResult);
const cliOutput = fs.readFileSync(path.resolve(workDir, 'data', 'cur', 'console-log.txt'), 'UTF-8');

The CLI outputs a non-structured string representation for easy reading, while the findLeaks API returns structured leaks representation that is handy for post-processing. If you need to obtain the string output the CLI, you can read them from ${workDir}/data/cur/console-log.txt.

susakin commented 6 months ago

谢谢我试试看