Permalink
Browse files

Initial commit

  • Loading branch information...
binarylogic committed Sep 11, 2008
0 parents commit 8c22b44b8a86e64b0d2a13352c303e1506c5639e
Showing with 43 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +10 −0 README.mdown
  3. +1 −0 init.rb
  4. +12 −0 lib/memory_usage_logger.rb
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Ben Johnson of Binary Logic (binarylogic.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,10 @@
+# Memory usage logger
+
+This is linux specific. The following command retrieves the memory:
+
+ memory_usage = `ps -o rss= -p #{$$}`.to_i
+
+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 each rails request. 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.
+
+
+Copyright (c) 2007 Ben Johnson of [Binary Logic](http://www.binarylogic.com), released under the MIT license
@@ -0,0 +1 @@
+require "memory_usage_logger"
@@ -0,0 +1,12 @@
+module BinaryLogic
+ module MemoryUsageLogger
+ private
+ def rendering_runtime(*args)
+ msg = super
+ memory_usage = `ps -o rss= -p #{$$}`.to_i
+ msg + " | PID: #{$$} | Memory Usage: #{memory_usage}"
+ end
+ end
+end
+
+ActionController::Base.send(:include, BinaryLogic::MemoryUsageLogger)

0 comments on commit 8c22b44

Please sign in to comment.