gestalt 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,39 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # jeweler generated
12
+ pkg
13
+
14
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
15
+ #
16
+ # * Create a file at ~/.gitignore
17
+ # * Include files you want ignored
18
+ # * Run: git config --global core.excludesfile ~/.gitignore
19
+ #
20
+ # After doing this, these files will be ignored in all your git projects,
21
+ # saving you from having to 'pollute' every project you touch with them
22
+ #
23
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
24
+ #
25
+ # For MacOS:
26
+ #
27
+ #.DS_Store
28
+ #
29
+ # For TextMate
30
+ #*.tmproj
31
+ #tmtags
32
+ #
33
+ # For emacs:
34
+ #*~
35
+ #\#*
36
+ #.\#*
37
+ #
38
+ # For vim:
39
+ #*.swp
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 geemus (Wesley Beary)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,74 @@
1
+ = gestalt
2
+
3
+ Simple Ruby profiling
4
+
5
+ == Getting started
6
+
7
+ Profiling with gestalt is easy to get started with and understand.
8
+ Say for instance that you have this class:
9
+
10
+ class Slow
11
+
12
+ def method
13
+ 3.times { sleep(0.1) }
14
+ 'slow'
15
+ end
16
+
17
+ end
18
+
19
+ You have a feeling that it could do better with single, so check to see what happens when you call it:
20
+
21
+ Gestalt.trace do
22
+
23
+ slow = Slow.new
24
+ slow.method
25
+
26
+ end
27
+
28
+ This will give you output in the following format:
29
+ duration method file
30
+ duration method file
31
+
32
+ The duration on the outermost call is the total for all nested calls, and the duration of the indented lines show how long the individual parts took.
33
+
34
+ You can also get a summary after the fact:
35
+
36
+ Gestalt.profile do
37
+
38
+ slow = Slow.new
39
+ slow.method
40
+
41
+ end
42
+
43
+ This will give you oßutput in the following format:
44
+
45
+ +---+--------+----------+
46
+ | # | action | duration |
47
+ +---+--------+----------+
48
+
49
+ The # column indicates how many times each occurredßß, action is the thing that occurred and duration is the total time taken for all occurrences.
50
+
51
+ == Copyright
52
+
53
+ (The MIT License)
54
+
55
+ Copyright (c) 2010 {geemus (Wesley Beary)}[http://github.com/geemus]
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ "Software"), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
71
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
72
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
73
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
74
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gestalt"
8
+ gem.summary = %Q{Simple Ruby profiling}
9
+ gem.description = %Q{Simple Ruby profiling}
10
+ gem.email = "wbeary@engineyard.com"
11
+ gem.homepage = "http://github.com/geemus/gestalt"
12
+ gem.authors = ["geemus (Wesley Beary)"]
13
+ gem.add_dependency "formatador", ">= 0.0.12"
14
+ gem.add_development_dependency "shindo", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'shindo/rake'
22
+ Shindo::Rake.new
23
+
24
+ begin
25
+ require 'rcov/rcovtask'
26
+ Rcov::RcovTask.new do |tests|
27
+ tests.libs << 'tests'
28
+ tests.pattern = 'tests/**/*_tests.rb'
29
+ tests.verbose = true
30
+ end
31
+ rescue LoadError
32
+ task :rcov do
33
+ abort "RCov is not available. In order to run rcov, you must: gem install spicycode-rcov"
34
+ end
35
+ end
36
+
37
+ task :tests => :check_dependencies
38
+
39
+ task :default => :tests
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gestalt #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/gestalt.rb ADDED
@@ -0,0 +1,136 @@
1
+ require File.join(File.dirname(__FILE__), 'gestalt', 'call')
2
+
3
+ require 'rubygems'
4
+ require 'formatador'
5
+
6
+ class Gestalt
7
+
8
+ attr_accessor :calls
9
+
10
+ def initialize
11
+ @calls = []
12
+ @stack = []
13
+ @totals = {}
14
+ end
15
+
16
+ def display_calls
17
+ Formatador.display_line
18
+ for call in @calls
19
+ call.display
20
+ end
21
+ Formatador.display_line
22
+ end
23
+
24
+ def display_profile
25
+ for call in calls
26
+ parse_call(call)
27
+ end
28
+
29
+ table = []
30
+ for key, value in @totals
31
+ table << {
32
+ '#' => value[:occurances],
33
+ :action => key,
34
+ :duration => format("%.6f", value[:duration])
35
+ }
36
+ end
37
+ table = table.sort {|x,y| y[:duration] <=> x[:duration]}
38
+
39
+ Formatador.display_line
40
+ Formatador.display_table(table)
41
+ Formatador.display_line
42
+ end
43
+
44
+ def run(&block)
45
+ start
46
+ yield
47
+ stop
48
+ end
49
+
50
+ def start
51
+ Kernel.set_trace_func(
52
+ lambda do |event, file, line, id, binding, classname|
53
+ case event
54
+ when 'call', 'c-call'
55
+ # p "call #{classname}##{id}"
56
+ call = Gestalt::Call.new(
57
+ :action => "#{classname}##{id}",
58
+ :location => "#{File.expand_path(file)}:#{line}",
59
+ :started_at => Time.now.to_f
60
+ )
61
+ unless @stack.empty?
62
+ @stack.last.children.push(call)
63
+ end
64
+ @stack.push(call)
65
+ when 'return', 'c-return'
66
+ # p "return #{classname}##{id}"
67
+ unless @stack.empty? # we get one of these when we set the trace_func
68
+ call = @stack.pop
69
+ call.finished_at = Time.now.to_f
70
+ if @stack.empty?
71
+ @calls << call
72
+ end
73
+ end
74
+ end
75
+ end
76
+ )
77
+ end
78
+
79
+ def stop
80
+ Kernel.set_trace_func(nil)
81
+ end
82
+
83
+ def self.profile(&block)
84
+ gestalt = new
85
+ gestalt.run(&block)
86
+ gestalt.display_profile
87
+ end
88
+
89
+ def self.trace(&block)
90
+ gestalt = new
91
+ gestalt.run(&block)
92
+ gestalt.display_calls
93
+ end
94
+
95
+ private
96
+ def parse_call(call)
97
+ @totals[call.action] ||= { :occurances => 0, :duration => 0 }
98
+ @totals[call.action][:occurances] += 1
99
+ @totals[call.action][:duration] += call.duration
100
+ for child in call.children
101
+ parse_call(child)
102
+ end
103
+ end
104
+
105
+ end
106
+
107
+ if __FILE__ == $0
108
+
109
+ class Slow
110
+
111
+ def single
112
+ 'slow' << 'er'
113
+ end
114
+
115
+ def double
116
+ single
117
+ single
118
+ end
119
+
120
+ end
121
+
122
+ Gestalt.trace do
123
+
124
+ slow = Slow.new
125
+ slow.single
126
+
127
+ end
128
+
129
+ Gestalt.profile do
130
+
131
+ slow = Slow.new
132
+ slow.double
133
+
134
+ end
135
+
136
+ end
@@ -0,0 +1,30 @@
1
+ class Gestalt
2
+
3
+ class Call
4
+
5
+ attr_accessor :children
6
+ attr_accessor :action, :finished_at, :location, :started_at
7
+
8
+ def initialize(attributes = {})
9
+ for key, value in attributes
10
+ send("#{key}=", value)
11
+ end
12
+ @children ||= []
13
+ end
14
+
15
+ def display(formatador = Formatador.new)
16
+ formatador.display_line("#{format("%.6f",duration)} [bold]#{action}[/] [light_black]#{location}[/]")
17
+ formatador.indent do
18
+ for child in children
19
+ child.display(formatador)
20
+ end
21
+ end
22
+ end
23
+
24
+ def duration
25
+ finished_at - started_at
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/tests_helper')
2
+
3
+ Shindo.tests("Gestalt") do
4
+ test("fails") do
5
+ "hey buddy, you should probably rename this file and start specing for real"
6
+ false
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'gestalt'
4
+ require 'rubygems'
5
+ require 'shindo'
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gestalt
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - geemus (Wesley Beary)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-11 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: formatador
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 12
31
+ version: 0.0.12
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: shindo
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Simple Ruby profiling
47
+ email: wbeary@engineyard.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - lib/gestalt.rb
63
+ - lib/gestalt/call.rb
64
+ - tests/gestalt_tests.rb
65
+ - tests/tests_helper.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/geemus/gestalt
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.6
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Simple Ruby profiling
96
+ test_files: []
97
+