simple_performer 0.0.7 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/simple_performer.rb +58 -15
  2. metadata +5 -18
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rest_client'
3
- require 'eventmachine'
3
+ #require 'eventmachine'
4
4
  require 'benchmark'
5
5
  require 'pp'
6
6
  require 'json'
@@ -23,6 +23,7 @@ module SimplePerformer
23
23
  SimplePerformer.config ||= SimplePerformer::Config.new
24
24
  yield(config)
25
25
  # SimplePerformer.service = Performr.new(config.access_key, config.secret_key, :config=>config)
26
+ # todo: should delay start until used?
26
27
  Performr.start
27
28
  end
28
29
  end
@@ -33,7 +34,7 @@ module SimplePerformer
33
34
  end
34
35
 
35
36
  def self.shutdown
36
- EventMachine.stop
37
+ # EventMachine.stop
37
38
  end
38
39
 
39
40
  def self.base_url=(url)
@@ -53,6 +54,48 @@ module SimplePerformer
53
54
  puts "#{name} duration: #{(end_time-start_time)} seconds."
54
55
  end
55
56
 
57
+ class Aggregator
58
+ def initialize
59
+ @aggs = {}
60
+ end
61
+
62
+ def benchmark(name, &block)
63
+ start_time = Time.now
64
+ yield
65
+ end_time = Time.now
66
+ agg = @aggs[name]
67
+ agg = Agger.new(name) if agg.nil?
68
+ agg.add(end_time-start_time)
69
+ @aggs[name] = agg
70
+
71
+ end
72
+
73
+ # Prints current info
74
+ def puts(name)
75
+ agg = @aggs[name]
76
+ agg.puts
77
+ end
78
+ end
79
+
80
+ class Agger
81
+ attr_accessor :name, :sum, :count
82
+
83
+ def initialize(name)
84
+ @name = name
85
+ @sum = 0.0
86
+ @count = 0
87
+ end
88
+
89
+ def add(duration)
90
+ @sum += duration
91
+ @count += 1
92
+ end
93
+
94
+ def puts
95
+ Kernel.puts "Aggregator #{name}: count=#{count} avg=#{avg}"
96
+ end
97
+ end
98
+
56
99
  class Performr
57
100
  #< ApiAuth
58
101
 
@@ -124,19 +167,19 @@ module SimplePerformer
124
167
 
125
168
  def periodic_update
126
169
 
127
- EventMachine.run do
128
- @timer = EventMachine::PeriodicTimer.new(60) do
129
- # puts "the time is #{Time.now}"
130
- begin
131
- send_update
132
- rescue => ex
133
- puts 'Failed to send data to SimplePerformr!'
134
- puts ex.message
135
- puts ex.backtrace
136
- end
137
-
138
- end
139
- end
170
+ # EventMachine.run do
171
+ # @timer = EventMachine::PeriodicTimer.new(60) do
172
+ ## puts "the time is #{Time.now}"
173
+ # begin
174
+ # send_update
175
+ # rescue => ex
176
+ # puts 'Failed to send data to SimplePerformr!'
177
+ # puts ex.message
178
+ # puts ex.backtrace
179
+ # end
180
+ #
181
+ # end
182
+ # end
140
183
  end
141
184
 
142
185
  def cancel_update
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 11
9
+ version: 0.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Reeder
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-30 00:00:00 -07:00
17
+ date: 2011-01-02 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,19 +30,6 @@ dependencies:
30
30
  version: "0"
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: eventmachine
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
44
- type: :runtime
45
- version_requirements: *id002
46
33
  description: Appoxy SimplePerformer Client Gem ...
47
34
  email: travis@appoxy.com
48
35
  executables: []
@@ -65,8 +52,8 @@ homepage: http://www.appoxy.com
65
52
  licenses: []
66
53
 
67
54
  post_install_message:
68
- rdoc_options:
69
- - --charset=UTF-8
55
+ rdoc_options: []
56
+
70
57
  require_paths:
71
58
  - lib
72
59
  required_ruby_version: !ruby/object:Gem::Requirement