summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-09-26 22:11:18 -0700
committerTim Smith <tsmith@chef.io>2018-10-29 21:39:28 -0700
commit5ce65255c3211ff12620143aa6091cc4b9850007 (patch)
tree6849e5009e8906db2c86ac5f3a45678b77947c79
parent678f326b6f41be8f4b0d71c8b5d45185f0be01bc (diff)
downloadohai-less_sysctl.tar.gz
Avoid gathering all data with sysctl which seems to hangless_sysctl
While it works fine for me @bdausses was seeing chef-client hang forever. It turns out running sysctl -a on his host was causing the system to hang. Besides this crash it actually takes about 2x longer to gather the additional data. This shaves a whole 0.033255 seconds from the total runtime. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/darwin/cpu.rb4
-rw-r--r--spec/unit/plugins/darwin/cpu_spec.rb4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/ohai/plugins/darwin/cpu.rb b/lib/ohai/plugins/darwin/cpu.rb
index a0c90532..d8210c9d 100644
--- a/lib/ohai/plugins/darwin/cpu.rb
+++ b/lib/ohai/plugins/darwin/cpu.rb
@@ -1,7 +1,7 @@
#
# Author:: Nathan L Smith (<nlloyds@gmail.com>)
# Author:: Tim Smith (<tsmith@chef.io>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2013-2018 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@ Ohai.plugin(:CPU) do
collect_data(:darwin) do
cpu Mash.new
- shell_out("sysctl -a").stdout.lines.each do |line|
+ shell_out("sysctl hw machdep").stdout.lines.each do |line|
case line
when /^hw.packages: (.*)$/
cpu[:real] = Regexp.last_match[1].to_i
diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb
index a6945962..082b95f4 100644
--- a/spec/unit/plugins/darwin/cpu_spec.rb
+++ b/spec/unit/plugins/darwin/cpu_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Nathan L Smith (<nlloyds@gmail.com>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2013-2018 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -78,7 +78,7 @@ machdep.cpu.max_basic: 13
CTL
allow(@plugin).to receive(:collect_os).and_return(:darwin)
- allow(@plugin).to receive(:shell_out).with("sysctl -a").and_return(mock_shell_out(0, @stdout, ""))
+ allow(@plugin).to receive(:shell_out).with("sysctl hw machdep").and_return(mock_shell_out(0, @stdout, ""))
@plugin.run
end