question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: Is it possible to add return value to heap-analysis plugins?

See original GitHub issue

Hi team,

Thanks for a lot for let this amazing project open source!

I am from the Lark desktop Team of ByteDance, and we would like to use memlab to help us find memory leaks.

In our scenario, Lark is a desktop app, not a SPA webpage, we can’t use memlab to start a puppeteer and run the e2e test, and the cost to rewrite all of out test cases using memlab is too high to afford.

Thus we want to use our existing e2e framwork to take snapshot, and pass it to a node server running memlab to analyse it.

Here is a minimal demo running memlab at a node server https://github.com/MoonShadowV/memlab-demo-server

It works fine for findLeaks as it dumps the result to the disk => /data/out/leaks.txt

import { findLeaks, BrowserInteractionResultReader } from '@memlab/api';
import { MEMLAB_WORKDIR } from './constant';
async function memlabFindLeak() {
  try {
    const reader = BrowserInteractionResultReader.from(MEMLAB_WORKDIR);
    const leaks = await findLeaks(reader);
    return Boolean(leaks);
  } catch (error) {
    throw new Error(`memlab analyse failed: ${error}`);
  }
}

export { memlabFindLeak };

But if we want to analyse single snapshot, the heap-analysis plugin return nothing, just print it to the termianl. We can’t get the output.

eg: https://github.com/facebook/memlab/blob/main/packages/heap-analysis/src/plugins/DetachedDOMElementAnalysis.ts#L50 In this plugin, the process function just call

  async process(options: HeapAnalysisOptions): Promise<void> {
    const snapshot = await pluginUtils.loadHeapSnapshot(options);
    this.detachedElements = pluginUtils.filterOutLargestObjects(
      snapshot,
      utils.isDetachedDOMNode,
    );
    pluginUtils.printNodeListInTerminal(this.detachedElements); // print result to terminal, return nothing
  }

to print the detachedElements in the terminal.

we can not access it from outside. ↓

(async function () {
  const analyse = new DetachedDOMElementAnalysis();
  await analyse.analyzeSnapshotFromFile(`./s2.heapsnapshot`); // just return null
})();

Is it possible to add return value to heap-analysis plugins so that we can to access it’s result in the code?

(async function () {
  const analyse = new DetachedDOMElementAnalysis();
  // get the detachedeElements
  const result = await analyse.analyzeSnapshotFromFile(`./s2.heapsnapshot`); 
})();

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JacksonGLcommented, Nov 23, 2022

That makes sense. We can add the option that supports setting an optional working directory for heap analysis calls

0reactions
JacksonGLcommented, Dec 9, 2022

@MoonShadowV I added support for setting optional working directory. Let me know if the new API is flexible for your use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rekall/heap_analysis.py at master - GitHub
rekall/rekall-core/rekall/plugins/linux/heap_analysis.py ... """Returns a list of dicts, containing the ebp,esp and pid values. for each thread.""".
Read more >
Question: How do you handle oversized heap analysis? : r/java
We have some VMs with 500GB worth of heap allocated to them. I'd very much like to know what is requiring that much...
Read more >
Why are some Java objects alive? - IBM
"Why are some Java objects alive?" is one of the most important questions in Java heap analysis. By the end of this article,...
Read more >
Making a Go program faster with a one-character change
A canonical Go function returns either Success(value) or Error(err not nil, meaningless auxiliary value). And this code has “meaningless ...
Read more >
Analist: A Tool for Improved Static Type Analysis for Ruby
Ideally, a developers team should be able to add the tool as a step ... The return value of the code in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found