Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add c_profile rake tasks for MacOS, using the Xcode instruments command #62

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ tmp
*.bundle
ext/*/Makefile
*.so
instruments*.trace
*.cpu
*.object
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions performance/c_profile.rb
Original file line number Diff line number Diff line change
@@ -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)