-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 optional ruby-profiling with --profile-ruby #4034
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,11 @@ | |
require 'chef/mixin/deprecation' | ||
require 'ohai' | ||
require 'rbconfig' | ||
begin | ||
require 'ruby-prof' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not do this in start_profiling or profiling_prereqs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 6 of one, half dozen of the other? I certainly can... |
||
rescue LoadError | ||
# ruby-prof is optional. | ||
end | ||
|
||
class Chef | ||
# == Chef::Client | ||
|
@@ -232,6 +237,8 @@ def initialize(json_attribs=nil, args={}) | |
# @return Always returns true. | ||
# | ||
def run | ||
start_profiling | ||
|
||
run_error = nil | ||
|
||
runlock = RunLock.new(Chef::Config.lockfile) | ||
|
@@ -284,6 +291,9 @@ def run | |
run_completed_successfully | ||
events.run_completed(node) | ||
|
||
# keep this inside the main loop to get exception backtraces | ||
end_profiling | ||
|
||
# rebooting has to be the last thing we do, no exceptions. | ||
Chef::Platform::Rebooter.reboot_if_needed!(node) | ||
rescue Exception => run_error | ||
|
@@ -891,6 +901,28 @@ def run_failed_notifications | |
attr_reader :override_runlist | ||
attr_reader :specific_recipes | ||
|
||
def profiling_prereqs! | ||
if !defined? RubyProf | ||
raise "You must have the ruby-prof gem installed in order to use --profile-ruby" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a truly trivial nitpick, the |
||
end | ||
|
||
def start_profiling | ||
return unless Chef::Config[:profile_ruby] | ||
profiling_prereqs! | ||
RubyProf.start | ||
end | ||
|
||
def end_profiling | ||
return unless Chef::Config[:profile_ruby] | ||
profiling_prereqs! | ||
path = Chef::FileCache.create_cache_path("graph_profile.out", false) | ||
File.open(path, "w+") do |file| | ||
RubyProf::GraphPrinter.new(RubyProf.stop).print(file, {}) | ||
end | ||
Chef::Log.warn("Ruby execution profile dumped to #{path}") | ||
end | ||
|
||
def empty_directory?(path) | ||
!File.exists?(path) || (Dir.entries(path).size <= 2) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to copy the scary here, too?