Created
March 1, 2014 22:03
-
-
Save vaskoz/9298185 to your computer and use it in GitHub Desktop.
Rails 4.0.3 with TracePoint on Ruby 2.1.1 (MRI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Rails app: config/boot.rb Added by VaskoZ | |
@stats = {} | |
@tp = TracePoint.trace(:a_call) do |tp| | |
@stats[tp.defined_class] ||= {} | |
@stats[tp.defined_class][tp.method_id] ||= 0 | |
@stats[tp.defined_class][tp.method_id] += 1 | |
end | |
@tp.enable | |
##### End VaskoZ changes | |
# Set up gems listed in the Gemfile. | |
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) | |
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### Rails app: app/controllers/hello_controller.rb | |
class HelloController < ApplicationController | |
def index | |
TOPLEVEL_BINDING.eval('@tp.disable') | |
stats = TOPLEVEL_BINDING.eval('@stats') | |
render text: "#{markup_stats(stats)}" | |
end | |
def start | |
TOPLEVEL_BINDING.eval('@stats.clear') | |
TOPLEVEL_BINDING.eval('@tp.enable') | |
render text: "<h1>TracePoint started!!!</h1>" | |
end | |
def stop | |
TOPLEVEL_BINDING.eval('@tp.disable') | |
stats = TOPLEVEL_BINDING.eval('@stats') | |
render text: "#{markup_stats(stats)}" | |
end | |
private | |
def markup_stats(stats) | |
html = "<h1>#{stats.keys.size} classes used</h1>" | |
html += "<h1>#{stats.map{|k,v| v.keys}.flatten.size} methods used</h1>" | |
html += "<h1>#{stats.map{|k,v| v.values}.flatten.sum} methods dispatched</h1>" | |
html += "<br><br>#{stats.inspect}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Rails app: config/routes.rb | |
Easy::Application.routes.draw do | |
get '/start', to: 'hello#start' | |
get '/stop', to: 'hello#stop' | |
get '/', to: 'hello#index' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment