From 90ade588426898f4d9cdebf03868afd6c56a862c Mon Sep 17 00:00:00 2001 From: erwanlr Date: Sat, 5 Oct 2013 13:06:56 +0100 Subject: [PATCH] Memory Usage output --- lib/common/common_helper.rb | 5 +++++ lib/common/hacks.rb | 9 +++++++++ wpscan.rb | 10 +++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/common/common_helper.rb b/lib/common/common_helper.rb index e4387f65..ea05d66e 100644 --- a/lib/common/common_helper.rb +++ b/lib/common/common_helper.rb @@ -160,3 +160,8 @@ def remove_base64_images_from_html(html) imageregex = %r{data\s*:\s*image/[^\s;]+\s*;\s*base64\s*,\s*} html.gsub(/["']\s*#{imageregex}#{base64regex}\s*["']/, '""') end + +# @return [ Integer ] The memory of the current process in Bytes +def get_memory_usage + `ps -o rss= -p #{Process.pid}`.to_i * 1024 # ps returns the value in KB +end diff --git a/lib/common/hacks.rb b/lib/common/hacks.rb index 47d9c608..fbc420a0 100644 --- a/lib/common/hacks.rb +++ b/lib/common/hacks.rb @@ -97,3 +97,12 @@ module Terminal end end end + +class Numeric + def bytes_to_human + units = %w{B KB MB GB TB} + e = (Math.log(self)/Math.log(1024)).floor + s = "%.3f" % (to_f / 1024**e) + s.sub(/\.?0*$/, ' ' + units[e]) + end +end diff --git a/wpscan.rb b/wpscan.rb index 039e8ba4..7d367e4b 100755 --- a/wpscan.rb +++ b/wpscan.rb @@ -103,7 +103,8 @@ def main end # Output runtime data - start_time = Time.now + start_time = Time.now + start_memory = get_memory_usage puts "| URL: #{wp_target.url}" puts "| Started on #{start_time.asctime}" puts @@ -332,10 +333,13 @@ def main end end - stop_time = Time.now + stop_time = Time.now + elapsed = stop_time - start_time + used_memory = get_memory_usage - start_memory + puts puts green("[+] Finished at #{stop_time.asctime}") - elapsed = stop_time - start_time + puts green("[+] Memory Used: #{used_memory.bytes_to_human}") puts green("[+] Elapsed time: #{Time.at(elapsed).utc.strftime('%H:%M:%S')}") exit(0) # must exit!