GithubHelp home page GithubHelp logo

Bundle speedscope about singed HOT 1 OPEN

rubyatscale avatar rubyatscale commented on September 6, 2024
Bundle speedscope

from singed.

Comments (1)

technicalpickles avatar technicalpickles commented on September 6, 2024

Looked at this a bit with @nateberkopec yesterday. The speedscope command itself is written in javascript, so needs a node runtime. But, looking at it more closely, it is mostly creating some temporary html and javascript files that eventually load the bundled dist/release/index.html.

Knowing that, we could port it to another language... for example, bash:

#!/bin/bash

set -x

helpString="Usage: speedscope [filepath]

If invoked with no arguments, will open a local copy of speedscope in your default browser.
Once open, you can browse for a profile to import.

If - is used as the filepath, will read from stdin instead.

cat /path/to/profile | speedscope - 
"

function getProfileBuffer() {
    if [ "$1" == "-" ]; then
        cat -
    else
        cat $1
    fi
}

urlToOpen="file://$(realpath "$(dirname $0)/../dist/release/index.html")"

filePrefix="speedscope-$(date +%s)-$$"
tempdir=$(mktemp -d)

jsPath="$tempdir/$filePrefix.js"
echo "Creating temp file $jsPath"
jsSource="speedscope.loadFileFromBase64(\"$1\", \"$(getProfileBuffer $1 | base64 -w 0)\")"
echo "$jsSource" > "$jsPath"
urlToOpen="$urlToOpen#localProfilePath=$jsPath"

htmlPath="$tempdir/$filePrefix.html"
echo "Creating temp file $htmlPath"
cat <<EOF > "$htmlPath"
<script>window.location="${urlToOpen}"</script>
EOF

function openBrowser() {
  if command -v xdg-open > /dev/null; then
    xdg-open $1
  elif command -v open > /dev/null; then
    open $1
  else
    echo "Could not open $1 in a browser. Please open it manually."
  fi
}

urlToOpen="file://${htmlPath}"
echo "Opening $urlToOpen in your default browser"
openBrowser $urlToOpen

This still requires the static files for speedscope to be installed somehwere

One way to do this would be to make part of releasing singed:

  • download the latest speedscope (or a preconfigured version?)
  • include that in the gem
  • write a ruby version of the speedscope command to do the same thing the node version does, using bundled speedscope.

from singed.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.