Skip to content

Instantly share code, notes, and snippets.

@kazu69
Last active November 26, 2015 07:50
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 kazu69/8628e1ed92533fd61881 to your computer and use it in GitHub Desktop.
Save kazu69/8628e1ed92533fd61881 to your computer and use it in GitHub Desktop.
# Gemfile
group :test do
...
gem 'stackprof'
...
end
ls tmp
stackprof-api-v1-hogescontroller-get-show-capacity-over-returns-capacity-over.dump
bundle exec stackprof tmp/stackprof-*
==================================
Mode: cpu(2000)
Samples: 606 (0.00% miss rate)
GC: 50 (8.25%)
==================================
TOTAL (pct) SAMPLES (pct) FRAME
552 (49.1%) 552 (49.1%) block in ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter#execute
88 (7.8%) 88 (7.8%) block in Logger::LogDevice#write
25 (2.2%) 21 (1.9%) ActiveSupport::HashWithIndifferentAccess#update
18 (1.6%) 18 (1.6%) ActiveSupport::HashWithIndifferentAccess#convert_value
16 (1.4%) 16 (1.4%) block (2 levels) in <class:Array>
18 (1.6%) 15 (1.3%) ActiveRecord::Type::DateTime#fallback_string_to_time
42 (3.7%) 14 (1.2%) block in ActiveSupport::Dependencies::Loadable#require
17 (1.5%) 12 (1.1%) ActiveSupport::TimeZone#parse
15 (1.3%) 10 (0.9%) ActiveRecord::LazyAttributeHash#assign_default_value
10 (0.9%) 10 (0.9%) Arel::Collectors::Bind#<<
62 (5.5%) 9 (0.8%) ActiveRecord::Attribute#value
32 (2.8%) 9 (0.8%) block in FactoryGirl::Evaluator.define_attribute
7 (0.6%) 7 (0.6%) ActiveRecord::Attribute#initialize
22 (2.0%) 7 (0.6%) ActiveRecord::LazyAttributeHash#[]
6 (0.5%) 6 (0.5%) block in <top (required)>
8 (0.7%) 6 (0.5%) ActiveSupport::TimeWithZone#localtime
24 (2.1%) 6 (0.5%) ActiveSupport::HashWithIndifferentAccess#[]=
6 (0.5%) 6 (0.5%) ActiveRecord::Type::TimeValue#fast_string_to_time
49 (4.4%) 5 (0.4%) ActiveRecord::AttributeMethods::Dirty#store_original_raw_attribute
5 (0.4%) 5 (0.4%) ActiveSupport::Logger::SimpleFormatter#call
5 (0.4%) 5 (0.4%) ThreadSafe::NonConcurrentCacheBackend#[]
5 (0.4%) 5 (0.4%) ActiveRecord::ConnectionAdapters::Mysql2Adapter#each_hash
4 (0.4%) 4 (0.4%) block in ActiveSupport::Dependencies#search_for_file
4 (0.4%) 4 (0.4%) block in ActiveSupport::HashWithIndifferentAccess#update
147 (13.1%) 4 (0.4%) ActiveRecord::AttributeMethods::Dirty#write_attribute
4 (0.4%) 4 (0.4%) LolipopAccount#setup_date
4 (0.4%) 4 (0.4%) ActiveRecord::Associations#association_instance_get
7 (0.6%) 4 (0.4%) FactoryGirl::AttributeList#each
607 (54.0%) 4 (0.4%) ActiveSupport::Callbacks#run_callbacks
4 (0.4%) 4 (0.4%) block in Arel::InsertManager#insert
DEST=stackprof INTERVAL=2000 be rspec spec/controllers/api/v1/account_relocations_controller_spec.rb
RSpec.configure do |config|
...
config.around(:each) do |example|
dest = ENV.fetch('DEST', 'stackprof-test-')
path = Rails.root.join("tmp/#{dest}-#{example.full_description.parameterize}.dump")
interval = ENV.fetch('INTERVAL', 1000).to_i
StackProf.run(mode: :cpu, out: path.to_s, interval: interval) do
example.run
end
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment