tronprint 0.0.2
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/features/step_definitions/tronprint_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/features/tronprint.feature +9 -0
- data/lib/tronprint.rb +76 -0
- data/lib/tronprint/aggregator.rb +43 -0
- data/lib/tronprint/application.rb +24 -0
- data/lib/tronprint/cpu_monitor.rb +41 -0
- data/lib/tronprint/rails.rb +14 -0
- data/lib/tronprint/rails/generator.rb +7 -0
- data/lib/tronprint/rails/tronprint_helper.rb +12 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/tronprint/aggregator_spec.rb +18 -0
- data/spec/tronprint/application_spec.rb +10 -0
- data/spec/tronprint/computer_spec.rb +9 -0
- data/spec/tronprint/cpu_monitor_spec.rb +55 -0
- data/spec/tronprint/rails/tronprint_helper_spec.rb +18 -0
- data/spec/tronprint_spec.rb +93 -0
- data/tronprint.gemspec +123 -0
- metadata +327 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Derek Kastner
|
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,17 @@
|
|
1
|
+
= tronprint
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Derek Kastner. See LICENSE for details.
|
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 = 'tronprint'
|
8
|
+
gem.summary = 'Ruby process carbon footprinter'
|
9
|
+
gem.description = 'A gem for monitoring the carbon footprint of your ruby app'
|
10
|
+
gem.email = 'dkastner@gmail.com'
|
11
|
+
gem.homepage = 'http://github.com/dkastner/tronprint'
|
12
|
+
gem.authors = ['Derek Kastner']
|
13
|
+
gem.add_development_dependency 'cucumber'
|
14
|
+
gem.add_development_dependency 'jeweler', '~> 1.4.0'
|
15
|
+
gem.add_development_dependency 'rake'
|
16
|
+
gem.add_development_dependency 'rspec', '~>2.0'
|
17
|
+
gem.add_development_dependency 'sandbox'
|
18
|
+
gem.add_dependency 'carbon', '~> 1.0.3'
|
19
|
+
gem.add_dependency 'i18n'
|
20
|
+
gem.add_dependency 'moneta'
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:examples)
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
puts 'RSpec tasks unavailable'
|
36
|
+
end
|
37
|
+
|
38
|
+
task :test => :examples
|
39
|
+
task :default => :test
|
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 = "tronprint #{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.2
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { 'rspec2' }
|
File without changes
|
data/lib/tronprint.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'tronprint/aggregator'
|
3
|
+
require 'tronprint/application'
|
4
|
+
require 'tronprint/cpu_monitor'
|
5
|
+
|
6
|
+
if defined?(Rails)
|
7
|
+
require 'tronprint/rails'
|
8
|
+
end
|
9
|
+
|
10
|
+
module Tronprint
|
11
|
+
extend self
|
12
|
+
|
13
|
+
attr_accessor :aggregator_options, :zip_code, :application_name, :brighter_planet_key
|
14
|
+
|
15
|
+
def aggregator_options
|
16
|
+
@aggregator_options ||= config[:aggregator_options]
|
17
|
+
end
|
18
|
+
|
19
|
+
def zip_code
|
20
|
+
@zip_code ||= config[:zip_code]
|
21
|
+
end
|
22
|
+
|
23
|
+
def brighter_planet_key
|
24
|
+
@brighter_planet_key ||= config[:brighter_planet_key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
cpu_monitor
|
29
|
+
end
|
30
|
+
|
31
|
+
def running?
|
32
|
+
!@cpu_monitor.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
def aggregator
|
36
|
+
@aggregator ||= Aggregator.new aggregator_options
|
37
|
+
end
|
38
|
+
|
39
|
+
def cpu_monitor
|
40
|
+
@cpu_monitor ||= CPUMonitor.new aggregator, application_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def application_name
|
44
|
+
@application_name ||= config[:application_name]
|
45
|
+
end
|
46
|
+
|
47
|
+
def total_duration
|
48
|
+
aggregator[cpu_monitor.key]
|
49
|
+
end
|
50
|
+
|
51
|
+
def config
|
52
|
+
load_config || default_config
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_config
|
56
|
+
return @loaded_config unless @loaded_config.nil?
|
57
|
+
path = File.expand_path('config/tronprint.yml', Dir.pwd)
|
58
|
+
@loaded_config = YAML::load_file path if File.exist? path
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_config
|
62
|
+
@default_config ||= {
|
63
|
+
:aggregator_options => {
|
64
|
+
:adapter => :YAML,
|
65
|
+
:path => File.expand_path('tronprint_stats.yml', Dir.pwd)
|
66
|
+
},
|
67
|
+
:application_name => File.basename(Dir.pwd)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def emission_estimate
|
72
|
+
app = Application.new :zip_code => zip_code, :duration => total_duration,
|
73
|
+
:brighter_planet_key => brighter_planet_key
|
74
|
+
app.emission_estimate
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'moneta'
|
3
|
+
|
4
|
+
module Tronprint
|
5
|
+
class Aggregator < Delegator
|
6
|
+
def initialize(options = {})
|
7
|
+
adapter_underscored = options.delete :adapter
|
8
|
+
adapter_underscored ||= :pstore
|
9
|
+
begin
|
10
|
+
require "moneta/#{adapter_underscored.downcase}"
|
11
|
+
klass = Moneta.const_get adapter_constant(adapter_underscored)
|
12
|
+
rescue LoadError # Bundler hack
|
13
|
+
require "moneta/adapters/#{adapter_underscored.downcase}"
|
14
|
+
klass = Moneta::Adapters.const_get adapter_constant(adapter_underscored)
|
15
|
+
end
|
16
|
+
args = adapter_underscored == :memory ? [] : [options]
|
17
|
+
super klass.new(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def __getobj__
|
21
|
+
@delegate_sd_obj
|
22
|
+
end
|
23
|
+
def __setobj__(obj)
|
24
|
+
@delegate_sd_obj = obj
|
25
|
+
end
|
26
|
+
|
27
|
+
def adapter_constant(adapter_underscored)
|
28
|
+
if adapter_underscored == :pstore
|
29
|
+
'PStore'
|
30
|
+
elsif adapter_underscored == :yaml
|
31
|
+
'YAML'
|
32
|
+
else
|
33
|
+
adapter_underscored.to_s.split('_').map(&:capitalize).join('')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(key, value)
|
38
|
+
old_value = self[key]
|
39
|
+
new_value = old_value ? old_value + value : value
|
40
|
+
self[key] = new_value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'carbon'
|
2
|
+
|
3
|
+
module Tronprint
|
4
|
+
class Application
|
5
|
+
include Carbon
|
6
|
+
|
7
|
+
emit_as :computation do
|
8
|
+
provide :duration # hours
|
9
|
+
provide :zip_code
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :duration, :zip_code, :brighter_planet_key
|
13
|
+
|
14
|
+
def initialize(attrs = {})
|
15
|
+
attrs.each do |name, value|
|
16
|
+
self.send("#{name}=", value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def emission_estimate(options = {})
|
21
|
+
super options.merge(:key => brighter_planet_key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Tronprint
|
2
|
+
class CPUMonitor < Thread
|
3
|
+
attr_accessor :total_recorded_cpu_time, :aggregator, :application_name
|
4
|
+
|
5
|
+
def initialize(aggregator, application_name, options = {})
|
6
|
+
self.aggregator = aggregator
|
7
|
+
self.application_name = application_name
|
8
|
+
options[:run] ||= true
|
9
|
+
if options[:run]
|
10
|
+
super do
|
11
|
+
while(true) do
|
12
|
+
monitor
|
13
|
+
sleep(5)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def key
|
20
|
+
[application_name, 'application', 'cpu_time'].join('/')
|
21
|
+
end
|
22
|
+
|
23
|
+
def monitor
|
24
|
+
elapsed_time = elapsed_cpu_time
|
25
|
+
aggregator.update key, elapsed_time
|
26
|
+
self.total_recorded_cpu_time += elapsed_time
|
27
|
+
end
|
28
|
+
|
29
|
+
def total_cpu_time
|
30
|
+
Process.times.inject(0) { |sum, i| sum += i }
|
31
|
+
end
|
32
|
+
|
33
|
+
def total_recorded_cpu_time
|
34
|
+
@total_recorded_cpu_time ||= 0.0
|
35
|
+
end
|
36
|
+
|
37
|
+
def elapsed_cpu_time
|
38
|
+
total_cpu_time - total_recorded_cpu_time
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'tronprint/rails/tronprint_helper'
|
3
|
+
|
4
|
+
module Tronprint
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer 'tronprint.run' do
|
7
|
+
Tronprint.run # if Rails.env.production?
|
8
|
+
end
|
9
|
+
|
10
|
+
generators do
|
11
|
+
require 'tronprint/rails/generator'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sandbox'
|
3
|
+
|
4
|
+
describe Tronprint::Aggregator do
|
5
|
+
let(:aggregator) { Tronprint::Aggregator.new :adapter => :memory }
|
6
|
+
|
7
|
+
describe '#update' do
|
8
|
+
it 'should write statistics to an uninitailzed key' do
|
9
|
+
aggregator.update('foo/bar', 22.1)
|
10
|
+
aggregator['foo/bar'].should == 22.1
|
11
|
+
end
|
12
|
+
it 'should cumulatively update statistics' do
|
13
|
+
aggregator.update('foo/bar', 22.1)
|
14
|
+
aggregator.update('foo/bar', 44.2)
|
15
|
+
aggregator['foo/bar'].should be_within(0.01).of(66.3)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tronprint::Application do
|
4
|
+
it 'should report emission esimates for application-related activity' do
|
5
|
+
app = Tronprint::Application.new :duration => 72831, :zip_code => 48915
|
6
|
+
app.should respond_to(:emission_estimate)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tronprint::CPUMonitor do
|
4
|
+
let(:aggregator) { Tronprint::Aggregator.new :adapter => :memory }
|
5
|
+
let(:cpu_monitor) { Tronprint::CPUMonitor.new aggregator, 'my_app', :run => false }
|
6
|
+
|
7
|
+
describe '#monitor' do
|
8
|
+
before :each do
|
9
|
+
cpu_monitor.stub!(:elapsed_cpu_time).and_return 23.87
|
10
|
+
end
|
11
|
+
it 'should write the elapsed time to the aggregate statistics' do
|
12
|
+
cpu_monitor.monitor
|
13
|
+
aggregator['my_app/application/cpu_time'].should == 23.87
|
14
|
+
end
|
15
|
+
it 'should increment the toal recorded cpu time' do
|
16
|
+
cpu_monitor.stub!(:elapsed_cpu_time).and_return 9.0
|
17
|
+
cpu_monitor.monitor
|
18
|
+
cpu_monitor.total_recorded_cpu_time.should == 9.0
|
19
|
+
cpu_monitor.stub!(:elapsed_cpu_time).and_return 12.0
|
20
|
+
cpu_monitor.monitor
|
21
|
+
cpu_monitor.total_recorded_cpu_time.should == 21.0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#elapsed_cpu_time' do
|
26
|
+
it 'should return the total CPU time on the first run' do
|
27
|
+
cpu_monitor.stub!(:total_recorded_cpu_time).and_return 0
|
28
|
+
cpu_monitor.stub!(:total_cpu_time).and_return 9.0
|
29
|
+
cpu_monitor.elapsed_cpu_time.should == 9.0
|
30
|
+
end
|
31
|
+
it 'should return the amount of CPU time used since the last check' do
|
32
|
+
cpu_monitor.stub!(:total_recorded_cpu_time).and_return 23.0
|
33
|
+
cpu_monitor.stub!(:total_cpu_time).and_return 36.0
|
34
|
+
cpu_monitor.elapsed_cpu_time.should == 13.0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#total_cpu_time' do
|
39
|
+
it 'should return the total user and system time of the process' do
|
40
|
+
Process.stub!(:times).and_return [10.1, 12.3]
|
41
|
+
cpu_monitor.total_cpu_time.should == 22.4
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#total_recorded_cpu_time' do
|
46
|
+
it 'should return 0 by default' do
|
47
|
+
cpu_monitor.total_recorded_cpu_time.should == 0
|
48
|
+
end
|
49
|
+
it 'should return total recorded time' do
|
50
|
+
cpu_monitor.total_recorded_cpu_time = 3
|
51
|
+
cpu_monitor.total_recorded_cpu_time.should == 3
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tronprint/rails/tronprint_helper'
|
3
|
+
|
4
|
+
describe TronprintHelper do
|
5
|
+
let :helper do
|
6
|
+
c = Class.new
|
7
|
+
c.send :include, TronprintHelper
|
8
|
+
c.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#total_footprint' do
|
12
|
+
it 'should return the total footprint' do
|
13
|
+
Tronprint.stub!(:footprint_amount).and_return 89.4
|
14
|
+
helper.total_footprint.should == 89.4
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tronprint do
|
4
|
+
let(:mock_cpu) { mock Tronprint::CPUMonitor, :total_recorded_cpu_time => 27.2 }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Tronprint.aggregator_options[:adapter] = :memory
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.run' do
|
11
|
+
it 'should start up each monitor' do
|
12
|
+
Tronprint.should_receive :cpu_monitor
|
13
|
+
Tronprint.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.cpu_monitor' do
|
18
|
+
it 'should start the CPU monitor' do
|
19
|
+
Tronprint::CPUMonitor.should_receive(:new).and_return mock_cpu
|
20
|
+
Tronprint.cpu_monitor
|
21
|
+
end
|
22
|
+
it 'should return the CPU monitor instance' do
|
23
|
+
Tronprint.instance_variable_set :@cpu_monitor, nil
|
24
|
+
Tronprint::CPUMonitor.stub!(:new).and_return mock_cpu
|
25
|
+
Tronprint.cpu_monitor.should == mock_cpu
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.footprint_amount' do
|
30
|
+
let(:estimate) { mock Object, :to_f => 100.1 }
|
31
|
+
|
32
|
+
it 'should return the total footprint of the application' do
|
33
|
+
Tronprint.stub!(:emission_estimate).and_return estimate
|
34
|
+
Tronprint.footprint_amount.should == 100.1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.emission_estimate' do
|
39
|
+
it 'should send the zip code and total duration to the application' do
|
40
|
+
Tronprint.instance_variable_set(:@emission_estimate, nil)
|
41
|
+
Tronprint.zip_code = 48915
|
42
|
+
Tronprint.brighter_planet_key = 'ABC123'
|
43
|
+
Tronprint.stub!(:total_duration).and_return 28.7
|
44
|
+
Tronprint::Application.should_receive(:new).
|
45
|
+
with(:zip_code => 48915, :duration => 28.7, :brighter_planet_key => 'ABC123').
|
46
|
+
and_return mock(Object, :emission_estimate => nil)
|
47
|
+
Tronprint.emission_estimate
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.config' do
|
52
|
+
it 'should return a configuration loaded from disk' do
|
53
|
+
Tronprint.stub!(:load_config).and_return nil
|
54
|
+
Tronprint.stub!(:default_config).and_return :foo => :bar
|
55
|
+
Tronprint.config.should == { :foo => :bar }
|
56
|
+
end
|
57
|
+
it 'should return a default configuration if no config file exists' do
|
58
|
+
Tronprint.stub!(:load_config).and_return :foo => :bar
|
59
|
+
Tronprint.config.should == { :foo => :bar }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.load_config' do
|
64
|
+
it 'should load a config file from cwd/config/tronprint.yml if it exists' do
|
65
|
+
Dir.stub!(:pwd).and_return '/some/dir'
|
66
|
+
File.stub!(:exist?).and_return true
|
67
|
+
YAML.should_receive(:load_file).with('/some/dir/config/tronprint.yml').
|
68
|
+
and_return :my => :config
|
69
|
+
Tronprint.load_config.should == { :my => :config }
|
70
|
+
end
|
71
|
+
it 'should return nil if no config file exists' do
|
72
|
+
Tronprint.instance_variable_set :@loaded_config, nil
|
73
|
+
Dir.stub!(:pwd).and_return '/some/dir'
|
74
|
+
File.stub!(:exist?).and_return false
|
75
|
+
Tronprint.load_config.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '.default_config' do
|
80
|
+
it 'should return a default configuration' do
|
81
|
+
Tronprint.default_config.should be_an_instance_of(Hash)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '.total_duration' do
|
86
|
+
it 'should look up the total for the application' do
|
87
|
+
Tronprint.instance_variable_set :@cpu_monitor, nil
|
88
|
+
Tronprint.application_name = 'groove'
|
89
|
+
Tronprint.aggregator.update 'groove/application/cpu_time', 5.0
|
90
|
+
Tronprint.total_duration.should == 5.0
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/tronprint.gemspec
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tronprint}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Derek Kastner"]
|
12
|
+
s.date = %q{2011-01-12}
|
13
|
+
s.description = %q{A gem for monitoring the carbon footprint of your ruby app}
|
14
|
+
s.email = %q{dkastner@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"autotest/discover.rb",
|
28
|
+
"features/step_definitions/tronprint_steps.rb",
|
29
|
+
"features/support/env.rb",
|
30
|
+
"features/tronprint.feature",
|
31
|
+
"lib/tronprint.rb",
|
32
|
+
"lib/tronprint/aggregator.rb",
|
33
|
+
"lib/tronprint/application.rb",
|
34
|
+
"lib/tronprint/cpu_monitor.rb",
|
35
|
+
"lib/tronprint/rails.rb",
|
36
|
+
"lib/tronprint/rails/generator.rb",
|
37
|
+
"lib/tronprint/rails/tronprint_helper.rb",
|
38
|
+
"spec/spec.opts",
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/tronprint/aggregator_spec.rb",
|
41
|
+
"spec/tronprint/application_spec.rb",
|
42
|
+
"spec/tronprint/computer_spec.rb",
|
43
|
+
"spec/tronprint/cpu_monitor_spec.rb",
|
44
|
+
"spec/tronprint/rails/tronprint_helper_spec.rb",
|
45
|
+
"spec/tronprint_spec.rb",
|
46
|
+
"tronprint.gemspec"
|
47
|
+
]
|
48
|
+
s.homepage = %q{http://github.com/dkastner/tronprint}
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.7}
|
51
|
+
s.summary = %q{Ruby process carbon footprinter}
|
52
|
+
s.test_files = [
|
53
|
+
"spec/spec_helper.rb",
|
54
|
+
"spec/tronprint/aggregator_spec.rb",
|
55
|
+
"spec/tronprint/application_spec.rb",
|
56
|
+
"spec/tronprint/computer_spec.rb",
|
57
|
+
"spec/tronprint/cpu_monitor_spec.rb",
|
58
|
+
"spec/tronprint/rails/tronprint_helper_spec.rb",
|
59
|
+
"spec/tronprint_spec.rb"
|
60
|
+
]
|
61
|
+
|
62
|
+
if s.respond_to? :specification_version then
|
63
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
64
|
+
s.specification_version = 3
|
65
|
+
|
66
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
67
|
+
s.add_runtime_dependency(%q<tronprint>, [">= 0"])
|
68
|
+
s.add_runtime_dependency(%q<carbon>, ["~> 1.0.3"])
|
69
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
70
|
+
s.add_runtime_dependency(%q<moneta>, [">= 0"])
|
71
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
72
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
73
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
74
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
75
|
+
s.add_development_dependency(%q<sandbox>, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
|
78
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
80
|
+
s.add_development_dependency(%q<sandbox>, [">= 0"])
|
81
|
+
s.add_runtime_dependency(%q<carbon>, ["~> 1.0.3"])
|
82
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
83
|
+
s.add_runtime_dependency(%q<moneta>, [">= 0"])
|
84
|
+
else
|
85
|
+
s.add_dependency(%q<tronprint>, [">= 0"])
|
86
|
+
s.add_dependency(%q<carbon>, ["~> 1.0.3"])
|
87
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
88
|
+
s.add_dependency(%q<moneta>, [">= 0"])
|
89
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
91
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
92
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
93
|
+
s.add_dependency(%q<sandbox>, [">= 0"])
|
94
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
95
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
96
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
98
|
+
s.add_dependency(%q<sandbox>, [">= 0"])
|
99
|
+
s.add_dependency(%q<carbon>, ["~> 1.0.3"])
|
100
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
101
|
+
s.add_dependency(%q<moneta>, [">= 0"])
|
102
|
+
end
|
103
|
+
else
|
104
|
+
s.add_dependency(%q<tronprint>, [">= 0"])
|
105
|
+
s.add_dependency(%q<carbon>, ["~> 1.0.3"])
|
106
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
107
|
+
s.add_dependency(%q<moneta>, [">= 0"])
|
108
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
109
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
110
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
111
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
112
|
+
s.add_dependency(%q<sandbox>, [">= 0"])
|
113
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
114
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
|
115
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
116
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
117
|
+
s.add_dependency(%q<sandbox>, [">= 0"])
|
118
|
+
s.add_dependency(%q<carbon>, ["~> 1.0.3"])
|
119
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
120
|
+
s.add_dependency(%q<moneta>, [">= 0"])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
metadata
ADDED
@@ -0,0 +1,327 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tronprint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Derek Kastner
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-12 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: tronprint
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: carbon
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 3
|
44
|
+
version: 1.0.3
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: i18n
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
type: :runtime
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: moneta
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: *id004
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: cucumber
|
76
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: *id005
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: jeweler
|
89
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 4
|
97
|
+
- 0
|
98
|
+
version: 1.4.0
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *id006
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: rake
|
104
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id007
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rspec
|
117
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 2
|
124
|
+
- 0
|
125
|
+
version: "2.0"
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: *id008
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: sandbox
|
131
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: *id009
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: cucumber
|
144
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: *id010
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: jeweler
|
157
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ~>
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
segments:
|
163
|
+
- 1
|
164
|
+
- 4
|
165
|
+
- 0
|
166
|
+
version: 1.4.0
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: *id011
|
170
|
+
- !ruby/object:Gem::Dependency
|
171
|
+
name: rake
|
172
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
segments:
|
178
|
+
- 0
|
179
|
+
version: "0"
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: *id012
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
name: rspec
|
185
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - ~>
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
segments:
|
191
|
+
- 2
|
192
|
+
- 0
|
193
|
+
version: "2.0"
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: *id013
|
197
|
+
- !ruby/object:Gem::Dependency
|
198
|
+
name: sandbox
|
199
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
200
|
+
none: false
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
segments:
|
205
|
+
- 0
|
206
|
+
version: "0"
|
207
|
+
type: :development
|
208
|
+
prerelease: false
|
209
|
+
version_requirements: *id014
|
210
|
+
- !ruby/object:Gem::Dependency
|
211
|
+
name: carbon
|
212
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
213
|
+
none: false
|
214
|
+
requirements:
|
215
|
+
- - ~>
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
segments:
|
218
|
+
- 1
|
219
|
+
- 0
|
220
|
+
- 3
|
221
|
+
version: 1.0.3
|
222
|
+
type: :runtime
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: *id015
|
225
|
+
- !ruby/object:Gem::Dependency
|
226
|
+
name: i18n
|
227
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
segments:
|
233
|
+
- 0
|
234
|
+
version: "0"
|
235
|
+
type: :runtime
|
236
|
+
prerelease: false
|
237
|
+
version_requirements: *id016
|
238
|
+
- !ruby/object:Gem::Dependency
|
239
|
+
name: moneta
|
240
|
+
requirement: &id017 !ruby/object:Gem::Requirement
|
241
|
+
none: false
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
segments:
|
246
|
+
- 0
|
247
|
+
version: "0"
|
248
|
+
type: :runtime
|
249
|
+
prerelease: false
|
250
|
+
version_requirements: *id017
|
251
|
+
description: A gem for monitoring the carbon footprint of your ruby app
|
252
|
+
email: dkastner@gmail.com
|
253
|
+
executables: []
|
254
|
+
|
255
|
+
extensions: []
|
256
|
+
|
257
|
+
extra_rdoc_files:
|
258
|
+
- LICENSE
|
259
|
+
- README.rdoc
|
260
|
+
files:
|
261
|
+
- .document
|
262
|
+
- .rspec
|
263
|
+
- Gemfile
|
264
|
+
- LICENSE
|
265
|
+
- README.rdoc
|
266
|
+
- Rakefile
|
267
|
+
- VERSION
|
268
|
+
- autotest/discover.rb
|
269
|
+
- features/step_definitions/tronprint_steps.rb
|
270
|
+
- features/support/env.rb
|
271
|
+
- features/tronprint.feature
|
272
|
+
- lib/tronprint.rb
|
273
|
+
- lib/tronprint/aggregator.rb
|
274
|
+
- lib/tronprint/application.rb
|
275
|
+
- lib/tronprint/cpu_monitor.rb
|
276
|
+
- lib/tronprint/rails.rb
|
277
|
+
- lib/tronprint/rails/generator.rb
|
278
|
+
- lib/tronprint/rails/tronprint_helper.rb
|
279
|
+
- spec/spec.opts
|
280
|
+
- spec/spec_helper.rb
|
281
|
+
- spec/tronprint/aggregator_spec.rb
|
282
|
+
- spec/tronprint/application_spec.rb
|
283
|
+
- spec/tronprint/computer_spec.rb
|
284
|
+
- spec/tronprint/cpu_monitor_spec.rb
|
285
|
+
- spec/tronprint/rails/tronprint_helper_spec.rb
|
286
|
+
- spec/tronprint_spec.rb
|
287
|
+
- tronprint.gemspec
|
288
|
+
has_rdoc: true
|
289
|
+
homepage: http://github.com/dkastner/tronprint
|
290
|
+
licenses: []
|
291
|
+
|
292
|
+
post_install_message:
|
293
|
+
rdoc_options: []
|
294
|
+
|
295
|
+
require_paths:
|
296
|
+
- lib
|
297
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
298
|
+
none: false
|
299
|
+
requirements:
|
300
|
+
- - ">="
|
301
|
+
- !ruby/object:Gem::Version
|
302
|
+
segments:
|
303
|
+
- 0
|
304
|
+
version: "0"
|
305
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
306
|
+
none: false
|
307
|
+
requirements:
|
308
|
+
- - ">="
|
309
|
+
- !ruby/object:Gem::Version
|
310
|
+
segments:
|
311
|
+
- 0
|
312
|
+
version: "0"
|
313
|
+
requirements: []
|
314
|
+
|
315
|
+
rubyforge_project:
|
316
|
+
rubygems_version: 1.3.7
|
317
|
+
signing_key:
|
318
|
+
specification_version: 3
|
319
|
+
summary: Ruby process carbon footprinter
|
320
|
+
test_files:
|
321
|
+
- spec/spec_helper.rb
|
322
|
+
- spec/tronprint/aggregator_spec.rb
|
323
|
+
- spec/tronprint/application_spec.rb
|
324
|
+
- spec/tronprint/computer_spec.rb
|
325
|
+
- spec/tronprint/cpu_monitor_spec.rb
|
326
|
+
- spec/tronprint/rails/tronprint_helper_spec.rb
|
327
|
+
- spec/tronprint_spec.rb
|