diff options
-rw-r--r-- | lib/ohai/application.rb | 11 | ||||
-rw-r--r-- | lib/ohai/runner.rb | 41 |
2 files changed, 27 insertions, 25 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb index 51ba6433..3b648e9a 100644 --- a/lib/ohai/application.rb +++ b/lib/ohai/application.rb @@ -20,7 +20,7 @@ require "chef-config/workstation_config_loader" require "ohai" require "ohai/log" require "mixlib/cli" -require "time" +require "benchmark" class Ohai::Application include Mixlib::CLI @@ -75,10 +75,11 @@ class Ohai::Application end def run - start_time = Time.now - configure_ohai - run_application - Ohai::Log.debug("Ohai took #{Time.now - start_time} total seconds to run.") + elapsed = Benchmark.measure do + configure_ohai + run_application + end + Ohai::Log.debug("Ohai took #{elapsed.total} total seconds to run.") end def configure_ohai diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 87a3f1d8..6368cbe3 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -18,7 +18,7 @@ # require "ohai/dsl" -require "time" +require "benchmark" module Ohai class Runner @@ -34,28 +34,29 @@ module Ohai # If force is set to true, then this plugin and its dependencies # will be run even if they have been run before. def run_plugin(plugin) - start_time = Time.now - unless plugin.kind_of?(Ohai::DSL::Plugin) - raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)" - end + elapsed = Benchmark.measure do + unless plugin.kind_of?(Ohai::DSL::Plugin) + raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)" + end - begin - case plugin.version - when :version7 - run_v7_plugin(plugin) - when :version6 - run_v6_plugin(plugin) - else - raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" + begin + case plugin.version + when :version7 + run_v7_plugin(plugin) + when :version6 + run_v6_plugin(plugin) + else + raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" + end + rescue Ohai::Exceptions::Error + raise + rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code + raise + rescue Exception, Errno::ENOENT => e + Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end - rescue Ohai::Exceptions::Error - raise - rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code - raise - rescue Exception, Errno::ENOENT => e - Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end - Ohai::Log.debug("Plugin #{plugin.name} took #{Time.now - start_time} seconds to run.") + Ohai::Log.debug("Plugin #{plugin.name} took #{elapsed.total} seconds to run.") end def run_v6_plugin(plugin) |