oink-transcode 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,90 @@
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 :around_filters
16
+
17
+ def around_filter method
18
+ (@around_filters ||= []) << method
19
+ end
20
+ end
21
+
22
+ include Oink::MemoryUsageLogger
23
+
24
+ def index
25
+ run_around_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_around_filters
39
+ self.class.around_filters.each { |filter| self.send(filter) { perform_action } }
40
+ end
41
+
42
+ def perform_action
43
+ end
44
+ end
45
+
46
+ describe Oink::MemoryUsageLogger do
47
+ unless defined? WIN32OLE
48
+ describe "get_memory_usage" do
49
+ it "should work on linux with statm" do
50
+ pages = 6271
51
+ statm_file = "#{pages} 1157 411 1 0 763 0\n"
52
+
53
+ File.should_receive(:read).with("/proc/self/statm").and_return(statm_file)
54
+ controller = ApplicationController.new
55
+ controller.should_receive(:`).with('getconf PAGESIZE').and_return("4096\n")
56
+ controller.index
57
+ controller.logger.log.should == [[:info, "Memory usage: #{pages * 4} | PID: #{$$}"]]
58
+ end
59
+
60
+ it "should work on linux with smaps" do
61
+ proc_file = <<-STR
62
+ Header
63
+
64
+ Size: 25
65
+ Size: 13 trailing
66
+
67
+ leading Size: 4
68
+
69
+ Footer
70
+
71
+ STR
72
+
73
+ File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
74
+ File.should_receive(:new).with("/proc/#{$$}/smaps").and_return(proc_file)
75
+ controller = ApplicationController.new
76
+ controller.index
77
+ [[:info, "Memory usage: 42 | PID: #{$$}"]].should == controller.logger.log
78
+ end
79
+
80
+ it "should work on non-linux" do
81
+ File.stub!(:read).and_raise(Errno::ENOENT.new("No such file or directory"))
82
+ File.stub!(:new).and_raise(Errno::ENOENT.new("No such file or directory"))
83
+ controller = ApplicationController.new
84
+ controller.index
85
+ [["ps -o vsz= -p #{$$}"]].should == controller.backtick
86
+ [[:info, "Memory usage: 915 | PID: #{$$}"]].should == controller.logger.log
87
+ end
88
+ end
89
+ end
90
+ 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,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oink-transcode
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Noah Davis
14
+ - Shane Gibbons
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-08 00:00:00 -04:00
20
+ default_executable: oink
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: hodel_3000_compliant_logger
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Log parser to identify actions which significantly increase VM heap size
37
+ email: shane.r.gibbons@gmail.com
38
+ executables:
39
+ - oink
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rdoc
44
+ files:
45
+ - History.txt
46
+ - MIT-LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - bin/oink
50
+ - lib/oink.rb
51
+ - lib/oink/active_record_instantiation_reporter.rb
52
+ - lib/oink/base.rb
53
+ - lib/oink/cli.rb
54
+ - lib/oink/memory_usage_reporter.rb
55
+ - lib/oink/oinked_request/oinked_ar_request.rb
56
+ - lib/oink/oinked_request/oinked_memory_request.rb
57
+ - lib/oink/oinked_request/oinked_request.rb
58
+ - lib/oink/priority_queue.rb
59
+ - lib/oink/rails.rb
60
+ - lib/oink/rails/instance_type_counter.rb
61
+ - lib/oink/rails/memory_usage_logger.rb
62
+ - spec/oink/active_record_instantiation_reporter_spec.rb
63
+ - spec/oink/memory_usage_reporter_spec.rb
64
+ - spec/oinked_request/oinked_request_spec.rb
65
+ - spec/priority_queue/priority_queue_spec.rb
66
+ - spec/rails/instance_type_counter_spec.rb
67
+ - spec/rails/memory_usage_logger_spec.rb
68
+ - spec/spec_helper.rb
69
+ has_rdoc: true
70
+ homepage: http://github.com/noahd1/oink
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.7
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Log parser to identify actions which significantly increase VM heap size
103
+ test_files:
104
+ - spec/oink/active_record_instantiation_reporter_spec.rb
105
+ - spec/oink/memory_usage_reporter_spec.rb
106
+ - spec/oinked_request/oinked_request_spec.rb
107
+ - spec/priority_queue/priority_queue_spec.rb
108
+ - spec/rails/instance_type_counter_spec.rb
109
+ - spec/rails/memory_usage_logger_spec.rb
110
+ - spec/spec_helper.rb