oink 0.1.0

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,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe OinkedRequest do
4
+ it "should be comparable" do
5
+ lr1 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 10)
6
+ lr2 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 5)
7
+
8
+ (lr1 > lr2).should == true
9
+ (lr1 == lr2).should == false
10
+ end
11
+
12
+ it "should sort by memory used" do
13
+ lr1 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 10)
14
+ lr2 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 5)
15
+ lr3 = OinkedRequest.new("Controller#Action", "February 1 10:20", [], 30)
16
+
17
+ [lr1, lr2, lr3].sort.should == [lr2, lr1, lr3]
18
+ end
19
+
20
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe PriorityQueue do
4
+
5
+ describe "size" do
6
+
7
+ it "should report the right size" do
8
+ pq = PriorityQueue.new(5)
9
+ pq.push(1)
10
+ pq.size.should == 1
11
+ pq.push(2)
12
+ pq.size.should == 2
13
+ end
14
+
15
+ it "should be limited to the size initialized with" do
16
+ pq = PriorityQueue.new(5)
17
+ pq.push(1)
18
+ pq.push(2)
19
+ pq.push(3)
20
+ pq.push(4)
21
+ pq.push(5)
22
+ pq.push(6)
23
+ pq.size.should == 5
24
+ end
25
+
26
+ end
27
+
28
+ describe "order" do
29
+
30
+ it "should be in order from highest to lowest" do
31
+ pq = PriorityQueue.new(5)
32
+ pq.push(1)
33
+ pq.push(2)
34
+ pq.push(3)
35
+ pq.to_a.should == [3,2,1]
36
+ end
37
+
38
+ it "should throw out the lower value when adding a new value" do
39
+ pq = PriorityQueue.new(3)
40
+ pq.push(1)
41
+ pq.push(2)
42
+ pq.push(3)
43
+ pq.push(4)
44
+ pq.to_a.should == [4,3,2]
45
+ end
46
+
47
+ it "should not make it into the queue if it's smaller than the items in the queue" do
48
+ pq = PriorityQueue.new(3)
49
+ pq.push(2)
50
+ pq.push(3)
51
+ pq.push(4)
52
+ pq.push(1)
53
+ pq.to_a.should == [4,3,2]
54
+ end
55
+
56
+ end
57
+
58
+ describe "each" do
59
+ it "should return each item in turn" do
60
+ arr = []
61
+ pq = PriorityQueue.new(5)
62
+ pq.push(2)
63
+ pq.push(3)
64
+ pq.push(4)
65
+ pq.push(1)
66
+ pq.push(5)
67
+ pq.each do |i|
68
+ arr << i
69
+ end
70
+ arr.should == [5,4,3,2,1]
71
+ end
72
+ end
73
+
74
+
75
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Oink::OinkInstanceTypeCounterInstanceMethods do
4
+ before :each do
5
+ ActiveRecord::Base.reset_instance_type_count
6
+ end
7
+
8
+ describe "hash" do
9
+ it "should not count objects not instantiated" do
10
+ ActiveRecord::Base.instantiated_hash["Pig"].should == nil
11
+ end
12
+
13
+ it "should include the objects instantiated" do
14
+ Pig.create(:name => "Babe")
15
+ Pig.first
16
+ ActiveRecord::Base.instantiated_hash["Pig"].should == 2
17
+ end
18
+
19
+ it "should count instantiations for multiple classes" do
20
+ Pig.create(:name => "Babe")
21
+ Pen.create(:location => "Backyard")
22
+ Pig.first
23
+ ActiveRecord::Base.instantiated_hash["Pen"].should == 1
24
+ end
25
+
26
+ it "should report the total number of objects instantiated" do
27
+ Pig.create(:name => "Babe")
28
+ Pen.create(:location => "Backyard")
29
+ Pig.first
30
+ ActiveRecord::Base.total_objects_instantiated.should == 3
31
+ end
32
+ end
33
+
34
+ describe "reset" do
35
+ it "should reset the total count" do
36
+ Pig.create(:name => "Babe")
37
+ ActiveRecord::Base.instantiated_hash["Pig"].should == 1
38
+ ActiveRecord::Base.reset_instance_type_count
39
+ ActiveRecord::Base.total_objects_instantiated.should == 0
40
+ Pig.create(:name => "Babe")
41
+ ActiveRecord::Base.total_objects_instantiated.should == 0
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ class ApplicationController
4
+ attr_accessor :backtick
5
+
6
+ class Logger
7
+ attr_accessor :log
8
+
9
+ def info(*args)
10
+ (@log ||= []) << [:info, *args]
11
+ end
12
+ end
13
+
14
+ class << self
15
+ attr_accessor :after_filters
16
+
17
+ def after_filter method
18
+ (@after_filters ||= []) << method
19
+ end
20
+ end
21
+
22
+ include Oink::MemoryUsageLogger
23
+
24
+ def index
25
+ run_after_filters
26
+ end
27
+
28
+ def logger
29
+ @logger ||= Logger.new
30
+ end
31
+
32
+ def `(*args)
33
+ (@backtick ||= []) << args
34
+ '915'
35
+ end
36
+
37
+ protected
38
+ def run_after_filters
39
+ self.class.after_filters.each { |filter| self.send(filter) }
40
+ end
41
+ end
42
+
43
+ describe Oink::MemoryUsageLogger do
44
+ unless defined? WIN32OLE
45
+ describe "get_memory_usage" do
46
+ it "should work on linux" do
47
+ proc_file = <<-STR
48
+ Header
49
+
50
+ Size: 25
51
+ Size: 13 trailing
52
+
53
+ leading Size: 4
54
+
55
+ Footer
56
+
57
+ STR
58
+
59
+ File.should_receive(:new).with("/proc/#{$$}/smaps").and_return(proc_file)
60
+ controller = ApplicationController.new
61
+ controller.index
62
+ [[:info, "Memory usage: 42 | PID: #{$$}"]].should == controller.logger.log
63
+ end
64
+
65
+ it "should work on non-linux" do
66
+ File.stub!(:new).and_raise(Errno::ENOENT.new("No such file or directory"))
67
+ controller = ApplicationController.new
68
+ controller.index
69
+ [["ps -o vsz= -p #{$$}"]].should == controller.backtick
70
+ [[:info, "Memory usage: 915 | PID: #{$$}"]].should == controller.logger.log
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,37 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require 'ostruct'
4
+
5
+ dir = File.dirname(__FILE__)
6
+ require File.join(dir, "/../lib/oink.rb")
7
+ require "oink/rails/instance_type_counter"
8
+ require "oink/rails/memory_usage_logger"
9
+ require File.join(dir, '../config/environment')
10
+
11
+ class PsuedoOutput < Array
12
+
13
+ def puts(line)
14
+ self << line
15
+ end
16
+
17
+ end
18
+
19
+ Spec::Runner.configure do |config|
20
+
21
+ config.before :suite do
22
+ load File.join(dir, "../db/schema.rb")
23
+ end
24
+
25
+ config.before :each do
26
+ Pig.delete_all
27
+ Pen.delete_all
28
+ end
29
+
30
+ config.before :suite do
31
+ ActiveRecord::Base.send(:include, Oink::OinkInstanceTypeCounterInstanceMethods)
32
+ Pig = Class.new(ActiveRecord::Base)
33
+ Pen = Class.new(ActiveRecord::Base)
34
+ Pig.belongs_to :pen
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oink
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Noah Davis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-10 00:00:00 -04:00
18
+ default_executable: oink
19
+ dependencies: []
20
+
21
+ description: Log parser to identify actions which significantly increase VM heap size
22
+ email: noahd1@yahoo.com
23
+ executables:
24
+ - oink
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ files:
30
+ - History.txt
31
+ - MIT-LICENSE
32
+ - README.rdoc
33
+ - Rakefile
34
+ - bin/oink
35
+ - lib/oink.rb
36
+ - lib/oink/active_record_instantiation_reporter.rb
37
+ - lib/oink/base.rb
38
+ - lib/oink/cli.rb
39
+ - lib/oink/memory_usage_reporter.rb
40
+ - lib/oink/oinked_request/oinked_ar_request.rb
41
+ - lib/oink/oinked_request/oinked_memory_request.rb
42
+ - lib/oink/oinked_request/oinked_request.rb
43
+ - lib/oink/priority_queue.rb
44
+ - lib/oink/rails.rb
45
+ - lib/oink/rails/instance_type_counter.rb
46
+ - lib/oink/rails/memory_usage_logger.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/noahd1/oink
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Log parser to identify actions which significantly increase VM heap size
77
+ test_files:
78
+ - spec/oink/active_record_instantiation_reporter_spec.rb
79
+ - spec/oink/memory_usage_reporter_spec.rb
80
+ - spec/oinked_request/oinked_request_spec.rb
81
+ - spec/priority_queue/priority_queue_spec.rb
82
+ - spec/rails/instance_type_counter_spec.rb
83
+ - spec/rails/memory_usage_logger_spec.rb
84
+ - spec/spec_helper.rb