memlog 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in memlog.gemspec
4
+ gemspec
@@ -0,0 +1,27 @@
1
+ Memlog
2
+ ======
3
+ Memlog is a simple gem to track down memory leaks in your Rails application.
4
+
5
+ Usage
6
+ -----
7
+
8
+ Just include the Memlog module in a rails controller
9
+
10
+ class ApplicationController < ActionController::Base
11
+
12
+ include Memlog
13
+
14
+ # ...
15
+
16
+ end
17
+
18
+ And it will log the following output on each request
19
+
20
+ 2011-12-27 08:42:47 Memory: +1009 KB Now: 311948 KB PID:25430 GET http://publish.mynewsdesk.com/se/edit/pressrelease
21
+
22
+ Notes
23
+ -----
24
+
25
+ Grep for requests that increate memory consumption drastically
26
+
27
+ $ grep 'Memory: +[0-9]\{6\}' log/production.log
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ require "memlog/version"
2
+
3
+ module Memlog
4
+
5
+ def self.included(base)
6
+ base.around_filter :record_memory if base.respond_to? :around_filter
7
+ end
8
+
9
+ def record_memory(&block)
10
+ rss_before_action = memory_usage
11
+ yield
12
+ rss_after_action = memory_usage
13
+ log_memory(rss_before_action, rss_after_action)
14
+ end
15
+
16
+ private
17
+
18
+ def memory_usage
19
+ if File.exists?("/proc/#{Process.pid}/status")
20
+ File.open("/proc/#{Process.pid}/status") do |process_status|
21
+ while rss = process_status.gets
22
+ return rss.split[1].to_i if rss.include?("VmRSS")
23
+ end
24
+ end
25
+ else
26
+ `ps -o rss= -p #{Process.pid}`.to_i
27
+ end
28
+ end
29
+
30
+ def log_memory(before, after)
31
+ logger.info("#{Time.now.strftime "%Y-%m-%d %H:%M:%S"}\tMemory: #{sprintf("%+d", after - before)} KB\tNow: #{after} KB\tPID:#{Process.pid}\t#{request.method} #{request.url}")
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module Memlog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "memlog/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "memlog"
7
+ s.version = Memlog::VERSION
8
+ s.authors = ["David Billskog"]
9
+ s.email = ["billskog@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Locate memory leaks in your Rails application}
12
+ s.description = %q{Memlog is a simple gem to track down memory leaks in your Rails application}
13
+
14
+ s.rubyforge_project = "memlog"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memlog
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - David Billskog
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-28 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Memlog is a simple gem to track down memory leaks in your Rails application
23
+ email:
24
+ - billskog@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/memlog.rb
37
+ - lib/memlog/version.rb
38
+ - memlog.gemspec
39
+ has_rdoc: true
40
+ homepage: ""
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: memlog
69
+ rubygems_version: 1.4.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Locate memory leaks in your Rails application
73
+ test_files: []
74
+