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.

Load a profile from URL doesn't work for perf script profiles

See original GitHub issue

Profiles generated using perf script can be opened from the file selection dialog, but loading the same file by URL fails with:

The profile could not be downloaded and decoded. This does not look like a supported file type. 
JSON parsing error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mstangecommented, Jul 13, 2022

You can also give this a try: https://github.com/mstange/fxprof-perf-convert It’s not finished yet but it should work for most use cases.

0reactions
copycommented, Jul 13, 2022

For reference, this minimal patch fixes the issue (but will break other formats):

diff --git a/src/actions/receive-profile.js b/src/actions/receive-profile.js
index 744ccfb0..da8259b9 100644
--- a/src/actions/receive-profile.js
+++ b/src/actions/receive-profile.js
@@ -1224,11 +1224,7 @@ async function _extractProfileOrZipFromResponse(
       // and try to process it as a profile.
       return {
         responseType: 'PROFILE',
-        profile: await _extractJsonFromResponse(
-          response,
-          reportError,
-          contentType
-        ),
+        profile: await response.text()
       };
     default:
       throw assertExhaustiveCheck(contentType);

So now I can write a shell script that runs perf and automatically opens the profile in a local instance of this UI:

#!/bin/bash
set -euo pipefail
perf record -o /tmp/perf.data "$@"
perf script -i /tmp/perf.data -F +pid > ~/www/profiler/dist/test.perf
cd ~/www/profiler/dist
pidof nginx || nginx
xdg-open http://localhost:9000/from-url/%2Ftest.perf

With nginx configured as follows:

    server {
        listen 127.0.0.1:9000;
        server_name  localhost;
        location / {
            root   /home/fabian/www/profiler/dist;
            index  index.html;
            add_header Cache-Control no-cache;
            if_modified_since off;
            expires off;
            etag off;
        }
        error_page  404  =200 /index.html;
    }

Pretty cool!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linux perf Examples - Brendan Gregg
Examples of using the Linux perf command, aka perf_events, for performance analysis and debugging. perf is a profiler and tracer.
Read more >
profiler/guide-perf-profiling.md at main · firefox-devtools/profiler
The perf record command writes the profile into a file called perf. data in the current directory.
Read more >
why does perf script not work? - Stack Overflow
perf script will show you the textual version of the stacks of your programs that you profiles with perf, which can be very...
Read more >
Linux perf Profiler UIs - Mark Hansen's Blog
This post is a quick literature review of CPU profiler user interfaces available for analysing Linux program performance.
Read more >
Using the AWS credentials file and credential Profiles
Each section (e.g., [default] , [project1] ), represents a separate credential profile. You can reference profiles from an SDK configuration file, or when...
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