From ecb8c0e706c8664d0a9b31b39b811da397724320 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Wed, 18 Dec 2013 15:43:23 -0800 Subject: Pass user-requested attributes from CLI to whitelist This greatly speeds up running ohai from the command line when given a set of attributes to display (like `ohai ec2`). Prior to this patch, ohai would run all plugins and then filter out the data. With this patch, ohai only runs relevant plugins. As an unscientific test `bin/ohai network` on my laptop takes ~4s without this patch compared to ~1.1s with the patch. --- lib/ohai/application.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb index 023cfdb8..e1640e8c 100644 --- a/lib/ohai/application.rb +++ b/lib/ohai/application.rb @@ -77,6 +77,7 @@ class Ohai::Application def configure_ohai @attributes = parse_options + @attributes = nil if @attributes.empty? Ohai::Config.merge!(config) if Ohai::Config[:directory] @@ -94,9 +95,9 @@ class Ohai::Application if Ohai::Config[:file] ohai.from_file(Ohai::Config[:file]) else - ohai.all_plugins + ohai.all_plugins(@attributes) end - if @attributes.length > 0 + if @attributes @attributes.each do |a| puts ohai.attributes_print(a) end -- cgit v1.2.1