staircase 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/lib/staircase.rb +37 -0
- data/lib/staircase/version.rb +3 -0
- data/staircase.gemspec +27 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Prins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Staircase
|
2
|
+
|
3
|
+
Staircase lets you write code inside a block and it automatically outputs the duration of the block. It also supports nesting blocks and outputting generic info.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'staircase'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install staircase
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Call `Staircase.run` with a block and it will automatically output runtime information:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Staircase.run 'Some elaborate process' do
|
25
|
+
sleep(5)
|
26
|
+
end
|
27
|
+
```
|
28
|
+
which will output
|
29
|
+
|
30
|
+
```
|
31
|
+
Some elaborate process (5002.34 ms)
|
32
|
+
```
|
33
|
+
|
34
|
+
Or for something a little more complex:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Staircase.run 'Find some objects' do
|
38
|
+
SomeObject.find_all(criteria).tap do |thing|
|
39
|
+
Staircase.run "Opening #{thing}" do
|
40
|
+
thing.open do |contents|
|
41
|
+
Staircase.info "Found #{contents}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
which could output something like:
|
49
|
+
|
50
|
+
```
|
51
|
+
Find some objects (123.45 ms)
|
52
|
+
Opening a square box... (14.0 ms)
|
53
|
+
Found an interesting object
|
54
|
+
Opening a puzzle box... (89.32 ms)
|
55
|
+
Found a glinting stone
|
56
|
+
Opening a satchel... (18.84 ms)
|
57
|
+
Found nothing in particular
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/staircase.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'staircase/version'
|
2
|
+
require 'tree'
|
3
|
+
|
4
|
+
module Staircase
|
5
|
+
def self.run(description = '')
|
6
|
+
$performance_tree ||= Tree::TreeNode.new 'Staircase'
|
7
|
+
|
8
|
+
local_node = Tree::TreeNode.new description
|
9
|
+
($performance_current_node || $performance_tree) << local_node
|
10
|
+
$performance_current_node = local_node
|
11
|
+
|
12
|
+
started_at = Time.now
|
13
|
+
yield
|
14
|
+
ended_at = Time.now
|
15
|
+
|
16
|
+
local_node.content = (ended_at - started_at) * 1000
|
17
|
+
$performance_current_node = $performance_current_node.parent unless $performance_current_node == $performance_tree
|
18
|
+
|
19
|
+
if $performance_current_node == $performance_tree
|
20
|
+
$performance_tree.each do |node|
|
21
|
+
unless node.is_root?
|
22
|
+
if node.content
|
23
|
+
puts "#{' ' * (node.level - 1)}#{node.name} (#{'%.2f' % node.content} ms)"
|
24
|
+
else
|
25
|
+
puts "#{' ' * (node.level - 1)}#{node.name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
$performance_tree = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.info(description)
|
34
|
+
$performance_tree ||= Tree::TreeNode.new 'Staircase'
|
35
|
+
($performance_current_node || $performance_tree) << Tree::TreeNode.new(description)
|
36
|
+
end
|
37
|
+
end
|
data/staircase.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'staircase/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'staircase'
|
8
|
+
spec.version = Staircase::VERSION
|
9
|
+
spec.authors = ['Michael Prins']
|
10
|
+
spec.email = ['michael.prins@me.com']
|
11
|
+
spec.description = %q{Block-driven duration reporting}
|
12
|
+
spec.summary = %q{Staircase lets you write code inside a block and it automatically outputs the duration of the block. It also supports nesting blocks and outputting generic info.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'rubytree', '~> 0.8.3'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staircase
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michael Prins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubytree
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Block-driven duration reporting
|
79
|
+
email:
|
80
|
+
- michael.prins@me.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/staircase.rb
|
91
|
+
- lib/staircase/version.rb
|
92
|
+
- staircase.gemspec
|
93
|
+
homepage: ''
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: 149558528855715135
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 149558528855715135
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.8.24
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Staircase lets you write code inside a block and it automatically outputs
|
124
|
+
the duration of the block. It also supports nesting blocks and outputting generic
|
125
|
+
info.
|
126
|
+
test_files: []
|