Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

souremaps arent being applied #446

Open
mbrevda opened this issue Nov 7, 2023 · 5 comments
Open

souremaps arent being applied #446

mbrevda opened this issue Nov 7, 2023 · 5 comments

Comments

@mbrevda
Copy link

mbrevda commented Nov 7, 2023

Hi - trying to run speedscope to help optimize program startup. It doesn't seem like sourcemaps are being applied, making tracing operations challenging.

Screenshot 2023-11-07 at 10 36 16 AM

Here is a standalone script that closely mimics my setup, illustrating the issue:

test.sh
set -e
tmpdir=$(mktemp -d)

cat << EOF > $tmpdir/bar.ts
import http from "node:http";
function listenCallBack() {
  console.log("Server is running");
  setTimeout(() => {
    console.log("exiting server...");
    process.exit(0);
  }, 100);
};

const server = () => {
  const server = http.createServer((req, res) => {
    res.end("Hello World");
  });
  server.listen("8080", listenCallBack);
  return server;
};

export default server;
EOF

cat << EOF > $tmpdir/index.ts
import('./bar.ts').then((bar) => bar.default());
EOF

cd $tmpdir

npx esbuild --bundle --splitting --minify --sourcemap=linked --platform=node --format=esm --out-extension:.js=.mjs --outdir=./ index.ts

node --prof --enable-source-maps $tmpdir/index.mjs
node --prof-process --preprocess -j isolate*.log | npx speedscope -
rm -rf $tmpdir

Thanks!

@jlfwong
Copy link
Owner

jlfwong commented Nov 7, 2023

Hey! As far as I remember, there's no circumstance where source-maps are automatically applied. That said, speedscope lets you apply sourcemaps after-the-fact.

See #317

@mbrevda
Copy link
Author

mbrevda commented Nov 7, 2023

speedscope lets you apply sourcemaps after-the-fact.

Thats cool! Unfortunately, dropping sourcemaps doesn't seem to have any effect on paths or symbols. Is there another way to load them that I can try?

@mbrevda
Copy link
Author

mbrevda commented Nov 9, 2023

Could this be related to esm code? I tried generating my code as .js (from .mjs) but that didn't help. Any way to debug sourcemaps to see if they are finding anything to apply?

@jlfwong
Copy link
Owner

jlfwong commented Nov 9, 2023

I'm not sure offhand if this would have anything to do with esm!

If you want to debug, your best bet would be to step through the code here:

let fileMatches = false

To get up and running locally, check out https://github.com/jlfwong/speedscope/blob/main/CONTRIBUTING.md

@mbrevda
Copy link
Author

mbrevda commented Nov 20, 2023

Good call! It seems that the prof traces aren't having their filename/line/column populated. Not sure if this is the best way to do it, but the following patch fixes that:

diff --git a/src/lib/profile.ts b/src/lib/profile.ts
index 4e04742..13b189b 100644
--- a/src/lib/profile.ts
+++ b/src/lib/profile.ts
@@ -66,6 +66,15 @@ export class Frame extends HasWeights {

   private constructor(info: FrameInfo) {
     super()
+    if (!info.file && !info.line && !info.col) {
+      const matches = info.name.match(/(?:\/\/?)?([^:]+):(\d+):(\d+)/)
+      if (matches) {
+        info.file = matches[1]
+        info.line = parseInt(matches[2], 10)
+        info.col = parseInt(matches[3], 10)
+      }
+    }
+
     this.key = info.key
     this.name = info.name
     this.file = info.file

However, even with this patch, the frames aren't remapped to their proper sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants