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

Parse meaningful data from stored results #139

Closed
YoranBrondsema opened this issue May 18, 2015 · 22 comments
Closed

Parse meaningful data from stored results #139

YoranBrondsema opened this issue May 18, 2015 · 22 comments

Comments

@YoranBrondsema
Copy link

Hi,

I have an Ember.js application backed by a Rails API. Since the index.html is generated by the front-end, MiniProfiler cannot inject itself onto the page. However, I would still like to use its results.

It seems the output in /tmp/miniprofiler/* cannot be used without parsing it. Is there a way to store the same output that it prints in HTML in a file? Then I can just cURL to actions in my controller and view a meaningful MiniProfiler report.

@silasb
Copy link

silasb commented May 22, 2015

👍 I am in a similar situation where it would be helpful to get profiler information (and flamegraphs) for an mobile API that I'm working on.

@Aldekein
Copy link

+1, I'd like to profile backend for an angular application. All the interaction between frontend and rails is in JSON format and I'd like to parse the mp_timers_* files.

@Aldekein
Copy link

@silasb @YoranBrondsema
I get something that could be human-read if I run the command in rails console and then replace \n with new-lines in Sublime and set View->Syntax->YAML:

YAML::dump(Marshal.load(::File.open('/var/www/project.lc/tmp/miniprofiler/mp_timers_z4h2y3sy5f662liqu2n5',"rb") {|f| f.read}))

@kevinjalbert
Copy link
Contributor

I would love to see some way to get more details on API requests that we feed into a Javascript front-end (i.e., Ember/Angular).

I've seen https://github.com/dejan/rails_panel, which does something like this via a chrome extension, which is an interesting approach.

@SamSaffron
Copy link
Member

You should be able to inject it just fine:

at the moment this is the extra script that is added:

 <script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=12b4b45a3c42e6e15503d7a03810ff33" data-version="12b4b45a3c42e6e15503d7a03810ff33" data-path="/mini-profiler-resources/" data-current-id="redo66j4g1077kto8uh3" data-ids="redo66j4g1077kto8uh3" data-position="left" data-trivial="false" data-children="false" data-max-traces="10" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false" data-collapse-results="true"></script>

Each time we change js versions change... but overall once you include this ... all new requests to API will be added. The version stuff is there to break caching you could simply put something random there every time you build.

@kevinjalbert
Copy link
Contributor

Just wanted to say that the javascript snippet @SamSaffron presented works perfectly for me.

Might be useful to actually have this mentioned in the https://github.com/MiniProfiler/rack-mini-profiler#using-in-spa-applications section?

@SamSaffron
Copy link
Member

cool, yeah a PR to improve doco is welcome!

@kevinjalbert
Copy link
Contributor

@SamSaffron #227 hopefully does the trick for the doc update.

@charlie-wasp
Copy link

@SamSaffron sorry to bring it up again after a long time, but I don't understand data-current-id and data-ids options. What am I supposed to put there? I believe, that I should use suffixes from mp_timers_* files. But they are auto-generated, aren't they?

@kbrock
Copy link
Contributor

kbrock commented Feb 1, 2017

Maybe something you could use as a reference:

I use the following implementation to view my profiling data: https://github.com/kbrock/cli_mini_profiler

I run with something like:

mini_profiler --storage Redis --storage-options db=1 --collapse Rendering --children http://localhost:3000/mini-profiler-resources/results?id=cextuacnfv7a26pk366u

# or
mini_profiler --storage Redis --storage-options db=1 --collapse Rendering --sql --aggro --summary cextuacnfv7a26pk366u

Maybe you could steal some ideas from there. Some of the aggregates are not perfect, so please let me know if you find any issues.

@sheekap
Copy link

sheekap commented May 9, 2017

Apologies as well for adding more conversation to an issue that might be considered closed. I'm having trouble with the data-version and ?v= options that change with every new release of the gem. Might be obvious to some but where do I get this value from?

@tinfoil-globe
Copy link

@charlie-wasp we're you ever able to figure out how to use data-current-id?

@charlie-wasp
Copy link

@jwpari I'm afraid no, I just gave up on it :(

@bf4
Copy link

bf4 commented Jun 22, 2017

Although admittedly a little messy, I was able to get my app to serve an html page with the script so that I could look at API requests

# config/initializers/mini_profiler.rb

  Rails.application.routes.append do
    mini_profiler = Rack::MiniProfiler.new(Rails.application)
    get '/profiler' => ->(env) {
      [200, {}, [<<-BODY.strip_heredoc]]
      <html>
      <head>
      </head>
      <body>
      #{mini_profiler.get_profile_script(env)}
      </body>
      </html>
      BODY
    }
  end

@turboladen
Copy link

FWIW, I just did this from my rails console and copypasta'ed it into my ember app:

007:0> puts Rack::MiniProfiler.new(Rails.application).get_profile_script({})
<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=8f332564e7761fb3795939d6582f992a" data-version="8f332564e7761fb3795939d6582f992a" data-path="/mini-profiler-resources/" data-current-id="" data-ids="[]" data-position="left" data-trivial="false" data-children="false" data-max-traces="20" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false" data-collapse-results="true" data-html-container="body"></script>

@IamNaN
Copy link

IamNaN commented Dec 22, 2018

In Rails 6 (yeah, I know) the javascript was being rendered as plain text. What got me going was @turboladen's solution, put in the header of the application layout file, and then rendered safely.

<html>
  <head>
    <title>MyApp</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all' %>
    <%= javascript_pack_tag 'application' %>
    <%= Rack::MiniProfiler.new(Rails.application).get_profile_script({}).html_safe %>
  </head>
  ...

Oddly, the javascript that was being rendered at the bottom of the page went away. I didn't expect that but I'm not going to look a gift horse in the mouth.

If someone knows off the top of their head where the javascript is being injected, I'll take a look making a PR for something not-so-hacky. It wasn't obvious to me.

@rtymchyk
Copy link

rtymchyk commented Apr 2, 2020

Any insight into making this work with CORS? My API server is different from my web server and the POST to /results fails the pre-flight check. I've tried the following but had no luck:

      allow do
        origins Rails.application.config.web_client_domain
        resource '/mini-profiler-resources/results', methods: [:post, :get]
      end

@OsamaSayegh
Copy link
Collaborator

As of #396, you no longer need to manually inject MP script tag into a page or create a custom route because MP now ships with a special route at /rack-mini-profiler/requests that displays MP speed badge and allows you to see profiling data for requests that don't render HTML.

@mcfiredrill
Copy link

now ships with a special route at /rack-mini-profiler/requests

Anyone know how I can get this to work in prod?

@Bennet-Sunder
Copy link

/rack-mini-profiler/requests is empty in staging environment

@kbrock
Copy link
Contributor

kbrock commented Jun 13, 2023

FWIW/ I store my data in redis, it makes it much easier for other tools to fetch from there.

@nate-at-gusto
Copy link
Contributor

I still don't understand how #396 is supposed to work when it has an empty head and body tag.

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