OHAI-431: provide basic memory information for Mac OS X #119

Closed
wants to merge 6 commits into from

3 participants

@patcoll

Please see ticket for more info: http://tickets.opscode.com/browse/OHAI-431

@pawelpacana

Would love to have this merged. What else needs to be done here?

@btm btm commented on the diff Jun 19, 2013
lib/ohai/plugins/darwin/memory.rb
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+provides 'memory'
+
+memory Mash.new
+
+installed_memory = from("sysctl -n hw.memsize").to_i / 1024 / 1024.0
+memory[:total] = "#{installed_memory.to_i}MB"
+
+total_consumed = 0
+active = 0
+inactive = 0
+vm_stat = from("vm_stat")
+page_size = begin; /page size of (\d+) bytes/.match(vm_stat)[1].to_i; rescue; 4096; end
@btm
Chef Software, Inc. member
btm added a note Jun 19, 2013

What's the rescue block here for? When would you hit it? Why would we still default to 4096?

@patcoll
patcoll added a note Jun 19, 2013

Relying on parsing stdout is inherently risky, so it's parsing the page size if it can find it, otherwise relying on a reasonable default. A lot of non-ruby implementations I've seen simply hard-code the page size, but that's not very future-proof.

This page unequivocally says the page size in iOS and OS X is 4 kilobytes, so it is a reasonable default:

In both OS X and iOS, the size of a page is 4 kilobytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@btm btm changed the title from provide basic memory information for Mac OS X to OHAI-431: provide basic memory information for Mac OS X May 6, 2014
@btm
Chef Software, Inc. member
btm commented May 6, 2014

This will need some updating to Ohai 7 syntax to continue. I'm going to close the PR for tracking purposes. Please see the ticket for more information.

@btm btm closed this May 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment