Permalink
Browse files

update readme

  • Loading branch information...
1 parent 2030fe7 commit acec669c23cac4ca50dde9187c61651794a42c63 @binarylogic committed Mar 1, 2011
Showing with 10 additions and 5 deletions.
  1. +5 −1 README.rdoc
  2. +1 −1 init.rb
  3. +3 −3 lib/memorylogic.rb
  4. +1 −0 rails/init.rb
View
@@ -6,7 +6,11 @@ This is linux specific. The following command retrieves the memory:
The reason I created this was to help track down a memory leak. It worked very well because it adds the process id and memory usage in with *EVERY* single line logged and at the end of each rails request. By every line, I mean every line in your log will end with " (mem #{memory_usage})".
-This way, if you have a cluster, you can monitor each process and scroll through your logs and watch the memory. If it suddenly starts to jump you can look at the request and at least you have a starting point. You can checkout the code for that specific controller action and try to narrow it down.
+This way, if you have a cluster, you can monitor each process and scroll through your logs and watch the memory. If it suddenly starts to jump you can look at the request and at least you have a starting point. You can checkout the code for that specific controller action and try to narrow it down.
+
+== Performance
+
+Please note this is only for doing research. There is a cost to finding the current memory usage on every log output. The average cost is probably in the realm of 20ms per execution. Which means an extra 20ms every time a line is logged.
== Tips
View
@@ -1 +1 @@
-require "memorylogic"
+require File.dirname(__FILE__) + "/rails/init.rb"
View
@@ -4,11 +4,11 @@ def self.included(klass)
after_filter :log_memory_usage
end
end
-
+
private
def log_memory_usage
if logger
- memory_usage = `ps -o rss= -p #{$$}`.to_i
+ memory_usage = `ps -o rss= -p #{Process.pid}`.to_i
logger.info("Memory usage: #{memory_usage} | PID: #{$$}")
end
end
@@ -21,6 +21,6 @@ def add_with_memory_info(severity, message = nil, progname = nil, &block)
message += " (mem #{memory_usage})"
add_without_memory_info(severity, message, progname, &block)
end
-
+
alias_method_chain :add, :memory_info
end
View
@@ -0,0 +1 @@
+require "memorylogic"

0 comments on commit acec669

Please sign in to comment.