skylight 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f501ad269f116e66053195e765359bb141347b0d
4
- data.tar.gz: 933730962fe952b6928ce50af200825b60cc11fc
3
+ metadata.gz: 560f8a033762d7bf39d090b9aefed3b9c754c7dd
4
+ data.tar.gz: 5c1628596dcf13425d22c8a9a9ec4974f2179d00
5
5
  SHA512:
6
- metadata.gz: 9d40ae02fb550a5fc409079b97d4087006610868589e2254013995df7d0d05e02f125a342258ff2e62747b58c7cdc5f6e4db1485af7bdafebee7659e446968e4
7
- data.tar.gz: 6d31c629aee42b171e82c06bd5fa70cc3bc91ee09c346f9a0db91ad54df4c9ea67fe36f635f8f413789c45eee0714f95115ea08e4b0417f4d58c567257980577
6
+ metadata.gz: 9a2bac2b3dadfcc72088c27be115ba207f5b5e1da7b59d979c2f76b8ce1d35c978e2b1bbc457c557a93070d46d3b3d1e8a0777d94a5d621917a3fc4e006e587c
7
+ data.tar.gz: 5060b3d9efc2a6ea197eece768f5c28481eb6716d9f8a2230607c429d88ae8509bbb5dbcace6c183e79f227f0951a737722b331b8afdd1abe05197072b62e9fd
@@ -14,6 +14,9 @@ module Skylight
14
14
  unless daemon?
15
15
  require 'active_support/notifications'
16
16
  require 'skylight/compat' # Require after AS::N
17
+
18
+ # Require VM specific things
19
+ require 'skylight/vm/gc'
17
20
  end
18
21
 
19
22
  autoload :Api, 'skylight/api'
@@ -227,7 +227,7 @@ authentication: #{self[:authentication]}
227
227
  end
228
228
 
229
229
  def gc
230
- @gc ||= GC.new(self, get('gc.profiler', ::GC::Profiler))
230
+ @gc ||= GC.new(self, get('gc.profiler', VM::GC.new))
231
231
  end
232
232
 
233
233
  def logger
@@ -2,7 +2,7 @@ require 'thread'
2
2
 
3
3
  module Skylight
4
4
  class GC
5
- METHODS = [ :enable, :total_time, :clear ]
5
+ METHODS = [ :enable, :total_time ]
6
6
  TH_KEY = :SK_GC_CURR_WINDOW
7
7
 
8
8
  include Util::Logging
@@ -27,9 +27,11 @@ module Skylight
27
27
  @listeners = []
28
28
  @config = config
29
29
  @lock = Mutex.new
30
+ @time = 0.0
30
31
 
31
32
  if METHODS.all? { |m| profiler.respond_to?(m) }
32
33
  @profiler = profiler
34
+ @time = @profiler.total_time
33
35
  else
34
36
  debug "disabling GC profiling"
35
37
  end
@@ -48,6 +50,7 @@ module Skylight
48
50
  win = Window.new(self)
49
51
 
50
52
  @lock.synchronize do
53
+ __update
51
54
  @listeners << win
52
55
  end
53
56
  end
@@ -82,19 +85,26 @@ module Skylight
82
85
 
83
86
  def update
84
87
  @lock.synchronize do
85
- time = @profiler.total_time
86
-
87
- if time > 0
88
- @profiler.clear
89
- @listeners.each do |l|
90
- l.add(time)
91
- end
92
- end
88
+ __update
93
89
  end
94
90
 
95
91
  nil
96
92
  end
97
93
 
94
+ private
95
+
96
+ def __update
97
+ time = @profiler.total_time
98
+ diff = time - @time
99
+ @time = time
100
+
101
+ if diff > 0.0
102
+ @listeners.each do |l|
103
+ l.add(diff)
104
+ end
105
+ end
106
+ end
107
+
98
108
  class Window
99
109
  attr_reader :time
100
110
 
@@ -95,7 +95,13 @@ module Skylight
95
95
  if built && built.valid?
96
96
  process(built)
97
97
  else
98
- debug "trace invalid -- dropping"
98
+ if built && built.spans.empty?
99
+ debug "trace invalid -- dropping; spans=0"
100
+ elsif built
101
+ debug "trace invalid -- dropping; spans=%d; started_at=%d", built.spans, built.spans[-1].started_at
102
+ else
103
+ debug "trace invalid -- dropping; trace=nil"
104
+ end
99
105
  end
100
106
  rescue Exception => e
101
107
  error e
@@ -121,7 +121,9 @@ module Skylight
121
121
 
122
122
  if sp.started_at < 0
123
123
  @busted = true
124
- raise TraceError, "[BUG] span started_at negative; event=#{cat}"
124
+ raise TraceError, "[BUG] span started_at negative; event=#{cat};" \
125
+ " started_at=#{sp.started_at};" \
126
+ " duration=#{sp.duration}"
125
127
  end
126
128
 
127
129
  sp
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
4
4
 
@@ -0,0 +1,68 @@
1
+
2
+ module Skylight
3
+ module VM
4
+ if defined?(JRUBY_VERSION)
5
+
6
+ # This doesn't quite work as we would like it. I believe that the GC
7
+ # statistics includes time that is not stop-the-world, this does not
8
+ # necessarily take time away from the application.
9
+ #
10
+ # require 'java'
11
+ # class GC
12
+ # def initialize
13
+ # @factory = Java::JavaLangManagement::ManagementFactory
14
+ # end
15
+ #
16
+ # def enable
17
+ # end
18
+ #
19
+ # def total_time
20
+ # res = 0.0
21
+ #
22
+ # @factory.garbage_collector_mx_beans.each do |mx|
23
+ # res += (mx.collection_time.to_f / 1_000.0)
24
+ # end
25
+ #
26
+ # res
27
+ # end
28
+ # end
29
+
30
+ elsif defined?(::GC::Profiler)
31
+
32
+ class GC
33
+ def initialize
34
+ @total = 0.0
35
+ end
36
+
37
+ def enable
38
+ ::GC::Profiler.enable
39
+ end
40
+
41
+ def total_time
42
+ run = ::GC::Profiler.total_time
43
+
44
+ if run > 0
45
+ ::GC::Profiler.clear
46
+ end
47
+
48
+ @total += run
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ # Fallback
55
+ unless defined?(VM::GC)
56
+
57
+ class GC
58
+ def enable
59
+ end
60
+
61
+ def total_time
62
+ 0.0
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
@@ -131,6 +131,7 @@ files:
131
131
  - lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb
132
132
  - lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb
133
133
  - lib/skylight/version.rb
134
+ - lib/skylight/vm/gc.rb
134
135
  - lib/skylight/worker.rb
135
136
  - lib/skylight/worker/builder.rb
136
137
  - lib/skylight/worker/collector.rb