Skip to content

Instantly share code, notes, and snippets.

@cannikin
Created July 8, 2011 04:48
Show Gist options
  • Save cannikin/1071169 to your computer and use it in GitHub Desktop.
Save cannikin/1071169 to your computer and use it in GitHub Desktop.
Shows memory usage as the Gmail gem is reading emails and attachments
require 'rubygems'
require 'gmail'
require 'memprof'
require 'logger'
def memory_usage
(((`ps -o rss= -p #{Process.pid}`.to_i / 1024.0) * 100).ceil / 100.0).to_s + ' MB'
end
log = Logger.new(STDOUT)
log.debug "START #{memory_usage}"
GMAIL = Gmail.connect!('anonymous@example.com','password')
log.debug " Gmail initialized #{memory_usage}"
Memprof.start
emails = GMAIL.inbox.find(:unread)
log.debug " retrieve inbox #{memory_usage}"
emails.each_with_index do |email,i|
log.debug " email #{i}, about to read #{memory_usage}"
email.attachments
log.debug " message read #{memory_usage}"
end
log.debug "END #{memory_usage}"
Memprof.stats
Memprof.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment