Move cli-support temporary files to subdirectory in /tmp?
Currently, running speedscope from the cli ($ speedscope /path/to/prof) creates temporary files in /tmp that never get cleaned. Over time one can accumulate quite a few files there. It may be slightly cleaner to put the files in a subdirectory, e.g. /tmp/speedscope.
Thanks!
Oh whoops, I never saw this issue until now!
@anntzer I'm happy to accept a PR to change this. The relevant code is here: https://github.com/jlfwong/speedscope/blob/fd4195da100bea8e200d952d54bc07f79d9f6ba7/bin/cli.js#L75-L85
My JS-skills are (literally) non-existent, so I'll just post a suggested patch here
diff --git i/bin/cli.js w/bin/cli.js
index 2755390..8f0414a 100755
--- i/bin/cli.js
+++ w/bin/cli.js
@@ -70,9 +70,11 @@ async function main() {
const jsSource = `speedscope.loadFileFromBase64(${JSON.stringify(filename)}, ${JSON.stringify(
sourceBase64,
)})`
+ const tmpdir = path.join(os.tmpdir(), 'speedscope')
+ fs.mkdir(tmpdir, { recursive: true }, (err) => { if (err) throw err; })
const filePrefix = `speedscope-${+new Date()}-${process.pid}`
- const jsPath = path.join(os.tmpdir(), `${filePrefix}.js`)
+ const jsPath = path.join(tmpdir, `${filePrefix}.js`)
console.log(`Creating temp file ${jsPath}`)
fs.writeFileSync(jsPath, jsSource)
urlToOpen += `#localProfilePath=${jsPath}`
@@ -80,7 +82,7 @@ async function main() {
// For some silly reason, the OS X open command ignores any query parameters or hash parameters
// passed as part of the URL. To get around this weird issue, we'll create a local HTML file
// that just redirects.
- const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
+ const htmlPath = path.join(tmpdir, `${filePrefix}.html`)
console.log(`Creating temp file ${htmlPath}`)
fs.writeFileSync(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
which should work I guess? but is totally untested.