jlfwong / speedscope

🔬 A fast, interactive web-based viewer for performance profiles.
https://www.speedscope.app
MIT License
5.59k stars 245 forks source link

Feature request: Import speedscope to open profiles #334

Open maddie-j opened 3 years ago

maddie-j commented 3 years ago

So currently, the only way to import profiles with the speedscope package (as in, programatically and not through uploading to the website) is to first install the speedscope package globally and then running from the command line with speedscope [profile-location]. However, this makes it difficult to integrate speedscope with other tools, requiring spawning a subcommand and hoping the person running it has speedscope installed.

Is it possible to expose that same functionality from the module so that people can just import speedscope from 'speedscope' in their Node code and then be able to do something like speedscope('profile-location.cpuprofile') to auto-open the profile?

Context: I'm writing a CLI that retrieves a CPU profile (that was generated on a different server) to save and then open locally using speedscope. Thing is, I can't expect the end user to have speedscope already installed, and it would be much easier to just include speedscope as a dependency in the package.json and then call speedscope from the code rather than having to spawn a separate process.

jlfwong commented 3 years ago

Hi @maddie-j!

I'm not opposed to this, but I think there's already a reasonable workaround. When you add speedscope as a dependency to your package and install it, it will place the speedscope executable in node_modules/.bin. So you can then run node_modules/.bin/speedscope from inside your project without requiring a global installation from end users.

Does that work? The npm bin command gives you the path to the .bin directory in case you don't want to rely on that specific path.

maddie-j commented 3 years ago

Unfortunately node_modules is no longer accessible after bundling a package into an executable. I understand though that this is a very niche edge-case and 100% get if you don't think it's worth the extra dev effort to support.

YiniXu9506 commented 3 years ago

Hi @maddie-j This is a very usefully feature that I am looking for. Did you find it out how to import speedscope to open profiles in other applications?