rake-timer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Peter Moran
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.
@@ -0,0 +1,35 @@
1
+ RakeTimer
2
+ ==============
3
+
4
+ Times how long each Rake task takes. If your Rake build starts to get too long, it can be useful to quickly see how long each task is taking. It can also be useful to track Tasks over time.
5
+
6
+ Usage
7
+ ------------
8
+ In your Rakefile, add:
9
+
10
+ require 'rake-timer'
11
+ time_tasks
12
+
13
+ Output
14
+ ------------
15
+ By default, time stats are written to the console. Optionally, you can write (append) to a CSV file (in reports/rake-timer.csv), which can easily be read by a charting library such as [Highcharts](http://highcharts.com/).
16
+
17
+ Even more optionally, you can output results to the very nice [statsd](https://github.com/etsy/statsd). Each task gets its own time-based set of graphs, so you can see how your build time is affected over, well time.
18
+
19
+ A full set of configuration options would be:
20
+
21
+ time_tasks :to => [:csv, :statsd], :unit => :milliseconds, :host => 'localhost', :port => 8125
22
+
23
+ Host and port are the statsd daemon you prepared earlier.
24
+
25
+ Installation
26
+ ------------
27
+
28
+ RakeTimer is packaged as a Gem. Install with:
29
+
30
+ gem install rake-timer
31
+
32
+ Copyright
33
+ ---------
34
+
35
+ Copyright (c) 2011 Peter Moran. See LICENSE for details.
@@ -0,0 +1,14 @@
1
+ module Rake
2
+
3
+ class Task
4
+
5
+ alias_method :old_execute, :execute
6
+
7
+ def execute(*args)
8
+ RakeTimer.time(self.name) { old_execute(*args) }
9
+ end
10
+
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,56 @@
1
+ require 'socket'
2
+ require File.expand_path(File.dirname(__FILE__) + '/rake/task')
3
+
4
+ # time_tasks :to => [:csv, :statsd], :unit => :milliseconds, :host => 'localhost', :port => 8125
5
+ def time_tasks(options = {})
6
+ Thread.current[:time_options] = options
7
+ end
8
+
9
+ class RakeTimer
10
+
11
+ class << self
12
+
13
+ def time(task_name)
14
+ start = Time.now
15
+ result = yield
16
+ record(task_name, Time.now - start)
17
+ result
18
+ end
19
+
20
+ def record(task_name, time)
21
+ unit = config[:unit] || :milliseconds
22
+ if unit == :seconds
23
+ output_time = time
24
+ puts "#{task_name} took #{sprintf("%.3f", output_time)} seconds"
25
+ else
26
+ output_time = time * 1000
27
+ puts "#{task_name} took #{output_time} milliseconds"
28
+ end
29
+ output_options = config[:to] || {}
30
+ as_csv(task_name, output_time) if output_options.include? :csv
31
+ as_statsd(task_name, time) if output_options.include? :statsd
32
+ end
33
+
34
+ def as_csv(task_name, time)
35
+ File.open("reports/rake-timer.csv", 'a') do |f|
36
+ f.write("#{task_name}, #{time * 1000}\n")
37
+ end
38
+ end
39
+
40
+ def as_statsd(task_name, time)
41
+ u = UDPSocket.new
42
+ u.connect(config[:host], config[:port])
43
+ task = task_name.gsub(/:/, '-')
44
+ msg = "build.#{task}:#{time}|ms"
45
+ u.send(msg, 0)
46
+ end
47
+
48
+ def config
49
+ Thread.current[:time_options]
50
+ end
51
+
52
+ end
53
+
54
+ private_class_method :config, :as_statsd, :as_csv, :record
55
+
56
+ end
@@ -0,0 +1,3 @@
1
+ module RakeTimer
2
+ VERSION = "0.0.1".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-timer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Peter Moran
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-20 00:00:00 +11:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: workingpeter@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/rake/task.rb
31
+ - lib/rake_timer.rb
32
+ - lib/version.rb
33
+ - README.markdown
34
+ - LICENSE
35
+ has_rdoc: true
36
+ homepage: http://github.com/pmoran/rake-timer
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Times how long each of your Rake tasks take
67
+ test_files: []
68
+