Last active
October 26, 2020 17:26
-
-
Save benoittgt/c579b614652b3cebdaada56c76c78d2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # With get process mem Gem from Richard | |
| class MemoryDiff | |
| class << self | |
| def print_usage_before_and_after(description) | |
| mem = GetProcessMem.new.mb | |
| puts "MEM:BEFORE:#{description.inspect} - MEMORY USAGE(MB): #{mem.round(2)}mb" | |
| yield | |
| after_mem = GetProcessMem.new.mb | |
| puts "MEM:AFTER:#{description.inspect} - MEMORY USAGE(MB): #{after_mem.round(2)}mb. Diff: #{display_diff(after_mem - mem)}" | |
| end | |
| private | |
| def display_diff(sum) | |
| if sum.positive? | |
| "⬆ +#{sum.round(2)}mb" | |
| elsif sum.negative? | |
| "⬇ #{sum.round(2)}mb" | |
| else | |
| "NO DIFF" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment