Created
July 8, 2011 04:48
-
-
Save cannikin/1071169 to your computer and use it in GitHub Desktop.
Shows memory usage as the Gmail gem is reading emails and attachments
This file contains 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
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