diff --git a/.gitignore b/.gitignore index 82a921c1..84cdac5a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ tmp *.bundle ext/*/Makefile *.so +instruments*.trace +*.cpu +*.object diff --git a/Rakefile b/Rakefile index 500a5540..168481b3 100644 --- a/Rakefile +++ b/Rakefile @@ -45,6 +45,13 @@ namespace :benchmark do end end +namespace :c_profile do + %i(run compile render).each do |task_name| + task(task_name) do + ruby "./performance/c_profile.rb #{task_name}" + end + end +end namespace :profile do desc "Run the liquid profile/performance coverage" diff --git a/performance/c_profile.rb b/performance/c_profile.rb new file mode 100644 index 00000000..7612116d --- /dev/null +++ b/performance/c_profile.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'liquid' +require 'liquid/c' +liquid_lib_dir = $LOAD_PATH.detect{ |p| File.exists?(File.join(p, 'liquid.rb')) } +require File.join(File.dirname(liquid_lib_dir), "performance/theme_runner") + +TASK_NAMES = %w(run compile render) +task_name = ARGV.first || 'run' +unless TASK_NAMES.include?(task_name) + raise "Unsupported task '#{task_name}' (must be one of #{TASK_NAMES})" +end +task = ThemeRunner.new.method(task_name) + +runner_id = fork do + end_time = Time.now + 5.0 + until Time.now >= end_time + task.call + end +end + +profiler_pid = spawn "instruments -t 'Time Profiler' -p #{runner_id}" + +Process.waitpid(runner_id) +Process.waitpid(profiler_pid)