Skip to content

Instantly share code, notes, and snippets.

@skyeagle
Created May 7, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyeagle/564b2cb8b0f6869d2db1cacac3b202a8 to your computer and use it in GitHub Desktop.
Save skyeagle/564b2cb8b0f6869d2db1cacac3b202a8 to your computer and use it in GitHub Desktop.
ENV['RAILS_ENV'] = 'production'
require File.expand_path('../../../config/environment', __FILE__)
require 'flamegraph'
require 'ruby-prof'
def helper_method(*args); end
include RablHelper
include PermissionHelper
include ApplicationHelper
include Api::DateTimeHelper
include Concerns::Api::HelperMethods
include TimesheetsHelper
include ActiveSupport::Benchmarkable
$current_user = User.find(553665)
@start_date = Time.zone.parse('04/15/2018').to_date
@end_date = Time.zone.parse('04/30/2018').to_date
def current_user
$current_user
end
def location
current_user.locations.last
end
def logger
@logger ||= Logger.new(STDOUT)
end
@presenter = TimesheetPresenter.new(location, @start_date..@end_date, { filter_pending_jobs: true })
@template_name = 'detailed'
logger.level = 0
Rails.logger.level = 0
template = 'timesheets/index'
ActiveRecord::Base.connection.enable_query_cache!
benchmark "measure #{template} rendering" do
Flamegraph.generate(Rails.root.join("tmp/#{template.parameterize}.flamegraph.html")) do
@presenter.preload!
# result = RubyProf.profile do
ap rabl_render(nil, template)
# end
# printer = RubyProf::GraphHtmlPrinter.new(result)
# File.open(Rail.root.join("tmp/#{tempate.parameterize}.rubyprof.html"), 'w') do |file|
# printer.print(file)
# end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment