focal_point 0.0.4 → 0.0.5
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.
- data/README.rdoc +86 -0
- data/Rakefile +10 -8
- data/VERSION +1 -1
- data/examples/main.rb +5 -5
- data/lib/focal_point.rb +16 -17
- metadata +1 -12
- data/.document +0 -5
data/README.rdoc
CHANGED
@@ -1,7 +1,93 @@
|
|
1
1
|
= focal_point
|
2
2
|
|
3
|
+
An unobtrusive profiling utility, for ruby, based on {hitimes}[http://github.com/copiousfreetime/hitimes].
|
3
4
|
|
5
|
+
- hitimes provides excellent timers (low overhead, high resolution)
|
6
|
+
- focal_point lets you use them, without polluting the code you're interested in.
|
4
7
|
|
8
|
+
== Usage
|
9
|
+
|
10
|
+
1. Tell FocalPoint to watch one or more methods
|
11
|
+
2. Execute the methods you're interested in
|
12
|
+
3. Ask FocalPoint for a report
|
13
|
+
4. Enjoy
|
14
|
+
|
15
|
+
== Usage Example
|
16
|
+
|
17
|
+
Given a contrived implementation:
|
18
|
+
|
19
|
+
class Foo
|
20
|
+
def self.bar
|
21
|
+
rand(10).times { sleep(1) }
|
22
|
+
end
|
23
|
+
def bin
|
24
|
+
Foo.bar
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
You're wondering how much time you spend executing Foo.bar?
|
29
|
+
|
30
|
+
# 1. Tell FocalPoint to watch one or more methods
|
31
|
+
require 'foo'
|
32
|
+
require 'focal_point'
|
33
|
+
FocalPoint.watch('Foo.bar') # eg: class method
|
34
|
+
FocalPoint.watch('Foo#bin') # eg: instance method
|
35
|
+
|
36
|
+
# 2. Execute the methods you're interested in
|
37
|
+
rand(10).times { Foo.bar }
|
38
|
+
rand(10).times { Foo.new.bin }
|
39
|
+
|
40
|
+
# 3. Ask FocalPoint to report what happened
|
41
|
+
FocalPoint.report ## report accepts an IO object, if you want to send it somewhere else.
|
42
|
+
|
43
|
+
# 4. Enjoy.
|
44
|
+
#
|
45
|
+
# You should see something like this in your stdout.
|
46
|
+
#
|
47
|
+
# --------------------------------------------------------------------------------
|
48
|
+
# sum: 7.003960149
|
49
|
+
# name: Foo.bar
|
50
|
+
# sampling_stop_time: 1.26255541894458e+15
|
51
|
+
# sumsq: 25.03019390208
|
52
|
+
# sampling_start_time: 1.26255541194084e+15
|
53
|
+
# rate: 0.285552738372669
|
54
|
+
# max: 4.003211068
|
55
|
+
# mean: 3.5019800745
|
56
|
+
# count: 2
|
57
|
+
# stddev: 0.708847668889441
|
58
|
+
# min: 3.000749081
|
59
|
+
#
|
60
|
+
# --------------------------------------------------------------------------------
|
61
|
+
# sum: 25.003881843
|
62
|
+
# name: Foo#bin
|
63
|
+
# sampling_stop_time: 1.26255621470907e+15
|
64
|
+
# sumsq: 151.046337138512
|
65
|
+
# sampling_start_time: 1.26255618970493e+15
|
66
|
+
# rate: 0.199968950077237
|
67
|
+
# max: 7.001084262
|
68
|
+
# mean: 5.0007763686
|
69
|
+
# count: 5
|
70
|
+
# stddev: 2.54987821742389
|
71
|
+
# min: 1.000180239
|
72
|
+
# additional_data:
|
73
|
+
|
74
|
+
|
75
|
+
== Motivation
|
76
|
+
|
77
|
+
This, or variations of it were happening way to often:
|
78
|
+
|
79
|
+
Foo.class_eval do
|
80
|
+
def self.bar_timer
|
81
|
+
@bar_timer ||= Hitimes::TimedMetric.new("Foo#bar")
|
82
|
+
end
|
83
|
+
alias_method :real_bar, :bar
|
84
|
+
def bar *args
|
85
|
+
self.class.bar_timer.start
|
86
|
+
result = real_bar(*args)
|
87
|
+
self.class.bar_timer.stop
|
88
|
+
result
|
89
|
+
end
|
90
|
+
end
|
5
91
|
|
6
92
|
== Note on Patches/Pull Requests
|
7
93
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["levicook@gmail.com"]
|
13
13
|
gem.add_dependency "hitimes", ">= 1.0.0"
|
14
14
|
gem.add_development_dependency "riot", ">= 0"
|
15
|
-
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
# gem.add_development_dependency "yard", ">= 0"
|
16
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
17
|
end
|
18
18
|
Jeweler::GemcutterTasks.new
|
@@ -44,11 +44,13 @@ task :test => :check_dependencies
|
|
44
44
|
|
45
45
|
task :default => :test
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "foo #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
55
|
end
|
56
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/examples/main.rb
CHANGED
@@ -19,11 +19,11 @@ module Quux
|
|
19
19
|
end
|
20
20
|
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
FocalPoint.watch('Quux::Foo.bar')
|
23
|
+
FocalPoint.watch('Quux::Foo.bar')
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
FocalPoint.watch('Quux::Foo#bar')
|
26
|
+
FocalPoint.watch('Quux::Foo#bin', 'Quux::Foo#bin=')
|
27
27
|
|
28
28
|
|
29
29
|
fail unless Quux::Foo.bar == :bar
|
@@ -43,5 +43,5 @@ end == :bar
|
|
43
43
|
end
|
44
44
|
|
45
45
|
at_exit do
|
46
|
-
FocalPoint.
|
46
|
+
FocalPoint.report
|
47
47
|
end
|
data/lib/focal_point.rb
CHANGED
@@ -35,24 +35,23 @@ class FocalPoint
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
io.puts
|
38
|
+
class << self
|
39
|
+
|
40
|
+
# FocalPoint.watch("ClassName#instance_method")
|
41
|
+
# FocalPoint.watch("ClassName.class_method")
|
42
|
+
def watch(*targets)
|
43
|
+
targets.each { |t| FocalPoint.new(t) }
|
45
44
|
end
|
46
|
-
end
|
47
45
|
|
48
|
-
|
46
|
+
def report(io=$stdout)
|
47
|
+
timers = []
|
48
|
+
ObjectSpace.each_object(FocalPoint) { |fp| timers << fp.timer }
|
49
|
+
timers.compact.sort_by(&:sum).each do |timer|
|
50
|
+
io.puts '-'*80
|
51
|
+
timer.to_hash.each { |k,v| io.puts "#{k}: #{v}" }
|
52
|
+
io.puts
|
53
|
+
end
|
54
|
+
end
|
49
55
|
|
50
|
-
|
51
|
-
#
|
52
|
-
# focal_point("ClassName#instance_method", ...)
|
53
|
-
# focal_point("ClassName.class_method", ...)
|
54
|
-
#
|
55
|
-
def focal_point(*targets)
|
56
|
-
targets.each { |t| FocalPoint.new(t) }
|
56
|
+
end
|
57
57
|
end
|
58
|
-
alias :focal_points :focal_point
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: focal_point
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- levicook@gmail.com
|
@@ -32,16 +32,6 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: yard
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: "0"
|
44
|
-
version:
|
45
35
|
description: instruments methods with hitimes
|
46
36
|
email: levicook@gmail.com
|
47
37
|
executables: []
|
@@ -52,7 +42,6 @@ extra_rdoc_files:
|
|
52
42
|
- LICENSE
|
53
43
|
- README.rdoc
|
54
44
|
files:
|
55
|
-
- .document
|
56
45
|
- .gitignore
|
57
46
|
- LICENSE
|
58
47
|
- README.rdoc
|