From f373b1003da2a31b72638f44a86bb0e0d4066556 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Thu, 13 Mar 2014 23:18:57 -0400 Subject: [PATCH] Use stackprof for profiling. --- .gitignore | 1 + Gemfile | 3 +++ liquid.gemspec | 4 ++++ performance/profile.rb | 23 ++++++++--------------- performance/theme_runner.rb | 35 ----------------------------------- 5 files changed, 16 insertions(+), 50 deletions(-) create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore index ebfa0ed..0e27775 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ pkg *.rbc .rvmrc .ruby-version +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/liquid.gemspec b/liquid.gemspec index e4b401e..297a716 100644 --- a/liquid.gemspec +++ b/liquid.gemspec @@ -23,4 +23,8 @@ Gem::Specification.new do |s| s.extra_rdoc_files = ["History.md", "README.md"] s.require_path = "lib" + + s.add_development_dependency 'stackprof' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0") + s.add_development_dependency 'rake' + s.add_development_dependency 'activesupport' end diff --git a/performance/profile.rb b/performance/profile.rb index 017435f..5ff4201 100644 --- a/performance/profile.rb +++ b/performance/profile.rb @@ -1,19 +1,12 @@ -require 'rubygems' -require 'ruby-prof' rescue fail("install ruby-prof extension/gem") +require 'stackprof' rescue fail("install stackprof extension/gem") require File.dirname(__FILE__) + '/theme_runner' profiler = ThemeRunner.new - -puts 'Running profiler...' - -results = profiler.run_profile - -puts 'Success' -puts - -[RubyProf::FlatPrinter, RubyProf::GraphHtmlPrinter, RubyProf::CallTreePrinter, RubyProf::DotPrinter].each do |klass| - filename = (ENV['TMP'] || '/tmp') + (klass.name.include?('Html') ? "/liquid.#{klass.name.downcase}.html" : "/callgrind.liquid.#{klass.name.downcase}.txt") - filename.gsub!(/:+/, '_') - File.open(filename, "w+") { |fp| klass.new(results).print(fp, :print_file => true, :min_percent => 3) } - $stderr.puts "wrote #{klass.name} output to #{filename}" +profiler.run +results = StackProf.run(mode: :cpu) do + 100.times do + profiler.run + end end +StackProf::Report.new(results).print_text(false, 20) +File.write(ENV['FILENAME'], Marshal.dump(results)) if ENV['FILENAME'] diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index 9c15a3d..f1caf9a 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -64,41 +64,6 @@ class ThemeRunner end - def run_profile - RubyProf.measure_mode = RubyProf::WALL_TIME - - # Dup assigns because will make some changes to them - assigns = Database.tables.dup - - @tests.each do |liquid, layout, template_name| - - # Compute page_tempalte outside of profiler run, uninteresting to profiler - html = nil - page_template = File.basename(template_name, File.extname(template_name)) - - unless @started - RubyProf.start - RubyProf.pause - @started = true - end - - html = nil - - RubyProf.resume - html = compile_and_render(liquid, layout, assigns, page_template, template_name) - RubyProf.pause - - - # return the result and the MD5 of the content, this can be used to detect regressions between liquid version - $stdout.puts "* rendered template %s, content: %s" % [template_name, Digest::MD5.hexdigest(html)] - - # Uncomment to dump html files to /tmp so that you can inspect for errors - # File.open("/tmp/#{File.basename(template_name)}.html", "w+") { |fp| fp <