oboe 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,118 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module Oboe_metal
5
+ include_package 'com.tracelytics.joboe'
6
+ import 'com.tracelytics.joboe'
7
+ include_package 'com.tracelytics.joboe.Context'
8
+ import 'com.tracelytics.joboe.Context'
9
+ include_package 'com.tracelytics.joboe.Event'
10
+ import 'com.tracelytics.joboe.Event'
11
+
12
+ class Context
13
+ def self.log(layer, label, options = {}, with_backtrace = true)
14
+ evt = Oboe::Context.createEvent()
15
+ evt.addInfo("Layer", layer.to_s)
16
+ evt.addInfo("Label", label.to_s)
17
+
18
+ options.each_pair do |k, v|
19
+ evt.addInfo(k.to_s, v.to_s)
20
+ end
21
+
22
+ evt.addInfo("Backtrace", Oboe::API.backtrace) if with_backtrace
23
+
24
+ Oboe::Reporter.sendReport(evt)
25
+ end
26
+
27
+ def self.layer_op=(op)
28
+ @layer_op = op
29
+ end
30
+
31
+ def self.layer_op
32
+ @layer_op
33
+ end
34
+
35
+ def self.tracing_layer_op?(operation)
36
+ if operation.is_a?(Array)
37
+ return operation.include?(@layer_op)
38
+ else
39
+ return @layer_op == operation
40
+ end
41
+ end
42
+
43
+ def self.toString
44
+ md = getMetadata.toString
45
+ end
46
+
47
+ def self.clear
48
+ clearMetadata
49
+ end
50
+
51
+ def self.get
52
+ getMetadata
53
+ end
54
+ end
55
+
56
+ class Event
57
+ def self.metadataString(evt)
58
+ evt.getMetadata.toHexString
59
+ end
60
+ end
61
+
62
+ def UdpReporter
63
+ Java::ComTracelyticsJoboe
64
+ end
65
+
66
+ module Metadata
67
+ Java::ComTracelyticsJoboeMetaData
68
+ end
69
+
70
+ module Reporter
71
+ def self.sendReport(evt)
72
+ evt.report
73
+ end
74
+ end
75
+ end
76
+
77
+ module Oboe
78
+ include Oboe_metal
79
+
80
+ # TODO: Ensure that the :tracing_mode is set to "always", "through", or "never"
81
+ Config = {
82
+ :tracing_mode => "through",
83
+ :reporter_host => "127.0.0.1",
84
+ :sample_rate => 1000000
85
+ }
86
+
87
+ def self.passthrough?
88
+ ["always", "through"].include?(Oboe::Config[:tracing_mode])
89
+ end
90
+
91
+ def self.always?
92
+ Oboe::Config[:tracing_mode] == "always"
93
+ end
94
+
95
+ def self.through?
96
+ Oboe::Config[:tracing_mode] == "through"
97
+ end
98
+
99
+ def self.never?
100
+ Oboe::Config[:tracing_mode] == "never"
101
+ end
102
+
103
+ def self.now?
104
+ Oboe::Context.isValid and not Oboe.never?
105
+ end
106
+
107
+ def self.start?
108
+ not Oboe::Context.isValid and Oboe.always?
109
+ end
110
+
111
+ def self.continue?
112
+ Oboe::Context.isValid and not Oboe.never?
113
+ end
114
+
115
+ def self.log(layer, label, options = {})
116
+ Context.log(layer, label, options = options)
117
+ end
118
+ end
@@ -0,0 +1,79 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module OboeMethodProfiling
5
+ def self.included klass
6
+ klass.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def profile_method(method_name, profile_name, store_args=false, store_return=false, profile=false)
11
+ #this only gets file and line where profiling is turned on, presumably
12
+ #right after the function definition. ruby 1.9 has nice introspection (Method.source_location)
13
+ #but its appears no such luck for ruby 1.8
14
+ version = RbConfig::CONFIG['ruby_version']
15
+ file = nil
16
+ line = nil
17
+ if version and version.match(/^1.9/)
18
+ info = self.method(method_name).source_location
19
+ if !info.nil?
20
+ file = info[0]
21
+ line = info[1]
22
+ end
23
+ else
24
+ info = Kernel.caller[0].split(':')
25
+ file = info.first
26
+ line = info.last
27
+ end
28
+
29
+ #profiling via ruby-prof, is it possible to get return value of profiled code?
30
+ code = "def _oboe_profiled_#{method_name}(*args, &block)
31
+ def pps(*args)
32
+ old_out = $stdout
33
+ begin
34
+ s = StringIO.new
35
+ $stdout = s
36
+ pp(*args)
37
+ ensure
38
+ $stdout = old_out
39
+ end
40
+ s.string
41
+ end
42
+
43
+ # file and line number are fetched in Context.log
44
+ # because we have access to the correct backtrace there
45
+ entry_kvs = {'Language' => 'ruby',
46
+ 'ProfileName' => '#{profile_name}',
47
+ 'FunctionName' => '#{method_name}',
48
+ 'Class' => self.class.to_s.rpartition('::').last,
49
+ 'Module' => self.class.to_s.rpartition('::').first,
50
+ 'File' => '#{file}',
51
+ 'LineNumber' => '#{line}'
52
+ }
53
+
54
+ if #{store_args}
55
+ entry_kvs['Args'] = pps *args
56
+ end
57
+
58
+ Oboe::Context.log(nil, 'profile_entry', entry_kvs)
59
+
60
+ ret = _oboe_orig_#{method_name}(*args, &block)
61
+
62
+ exit_kvs = {'Language' => 'ruby',
63
+ 'ProfileName' => '#{profile_name}'
64
+ }
65
+
66
+ if #{store_return}
67
+ exit_kvs['ReturnValue'] = pps ret
68
+ end
69
+
70
+ Oboe::Context.log(nil, 'profile_exit', exit_kvs)
71
+
72
+ ret
73
+ end"
74
+ class_eval code, __FILE__, __LINE__
75
+ alias_method "_oboe_orig_#{method_name}", method_name
76
+ alias_method method_name, "_oboe_profiled_#{method_name}"
77
+ end
78
+ end
79
+ end
data/lib/oboe.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  # Copyright (c) 2012 by Tracelytics, Inc.
2
2
  # All rights reserved.
3
-
3
+
4
4
  begin
5
- require 'oboe_metal.so'
6
5
  require 'rbconfig'
7
- require 'oboe_metal'
6
+ if RUBY_PLATFORM == 'java'
7
+ require '/usr/local/tracelytics/tracelyticsagent.jar'
8
+ require 'joboe_metal'
9
+ else
10
+ require 'oboe_metal.so'
11
+ require 'oboe_metal'
12
+ end
13
+ require 'rbconfig'
14
+ require 'method_profiling'
8
15
  require 'oboe/config'
9
16
  require 'oboe/loading'
10
17
 
data/lib/oboe/api.rb CHANGED
@@ -8,13 +8,6 @@ module Oboe
8
8
  extend Oboe::API::Tracing
9
9
  extend Oboe::API::LayerInit
10
10
  end
11
-
12
- def self.extend_with_noop
13
- extend Oboe::API::LoggingNoop
14
- extend Oboe::API::TracingNoop
15
- extend Oboe::API::LayerInitNoop
16
- end
17
-
18
11
  extend Oboe::API::Util
19
12
  end
20
13
  end
@@ -7,9 +7,10 @@ module Oboe
7
7
  #
8
8
  def report_init(layer)
9
9
  platform_info = { '__Init' => 1 }
10
- platform_info['RubyVersion'] = RUBY_VERSION
11
- platform_info['RailsVersion'] = ::Rails.version if defined?(Rails)
12
- platform_info['OboeVersion'] = Gem.loaded_specs['oboe'].try(:version).to_s
10
+ platform_info['RubyPlatform'] = RUBY_PLATFORM
11
+ platform_info['RubyVersion'] = RUBY_VERSION
12
+ platform_info['RailsVersion'] = ::Rails.version if defined?(Rails)
13
+ platform_info['OboeVersion'] = Gem.loaded_specs['oboe'].try(:version).to_s
13
14
 
14
15
  force_trace do
15
16
  start_trace(layer, nil, platform_info) { }
@@ -24,14 +25,5 @@ module Oboe
24
25
  Oboe::Config[:tracing_mode] = saved_mode
25
26
  end
26
27
  end
27
-
28
- module LayerInitNoop
29
- def report_init(layer)
30
- end
31
-
32
- def force_trace
33
- yield
34
- end
35
- end
36
28
  end
37
29
  end
@@ -116,31 +116,8 @@ module Oboe
116
116
  opts.each do |k, v|
117
117
  event.addInfo(k.to_s, v.to_s) if valid_key? k
118
118
  end if !opts.nil? and opts.any?
119
-
120
- Oboe.reporter.sendReport(event)
121
- end
122
- end
123
-
124
- module LoggingNoop
125
- def log(layer, label, opts={})
126
- end
127
-
128
- def log_exception(layer, exn)
129
- end
130
-
131
- def log_start(layer, xtrace, opts={})
132
- end
133
-
134
- def log_end(layer, opts={})
135
- end
136
-
137
- def log_entry(layer, opts={})
138
- end
139
-
140
- def log_exit(layer, opts={})
141
- end
142
-
143
- def log_event(layer, label, event, opts={})
119
+
120
+ Oboe::Reporter.sendReport(event)
144
121
  end
145
122
  end
146
123
  end
@@ -118,7 +118,7 @@ module Oboe
118
118
  log_start(layer, xtrace, opts)
119
119
  exit_evt = Oboe::Context.createEvent
120
120
  begin
121
- target['X-Trace'] = exit_evt.metadataString() if Oboe::Config.tracing?
121
+ target['X-Trace'] = Oboe::Event.metadataString(exit_evt) if Oboe::Config.tracing?
122
122
  yield
123
123
  rescue Exception => e
124
124
  log_exception(layer, e)
@@ -130,19 +130,5 @@ module Oboe
130
130
  end
131
131
  end
132
132
  end
133
-
134
- module TracingNoop
135
- def trace(layer, opts={})
136
- yield
137
- end
138
-
139
- def start_trace(layer, xtrace, opts={})
140
- [yield, xtrace]
141
- end
142
-
143
- def start_trace_with_target(layer, xtrace, target, opts={})
144
- yield
145
- end
146
- end
147
133
  end
148
134
  end
data/lib/oboe/api/util.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  module Oboe
5
5
  module API
6
6
  module Util
7
- BACKTRACE_CUTOFF = 100
7
+ BACKTRACE_CUTOFF = 200
8
8
 
9
9
  # Internal: Check whether the provided key is reserved or not. Reserved
10
10
  # keys are either keys that are handled by liboboe calls or the oboe gem.
@@ -24,13 +24,20 @@ module Oboe
24
24
  #
25
25
  # Returns a string with each frame of the backtrace separated by '\r\n'.
26
26
  def backtrace(ignore=1)
27
- frames = Kernel.caller
28
- frames_len = frames.size
29
- if frames_len - ignore > BACKTRACE_CUTOFF
30
- frames[ignore, BACKTRACE_CUTOFF + ignore].unshift("...")
27
+ trim_backtrace(Kernel.caller).join("\r\n");
28
+ end
29
+
30
+ def trim_backtrace(backtrace)
31
+ return backtrace unless backtrace.is_a?(Array)
32
+
33
+ length = backtrace.size
34
+ if length > BACKTRACE_CUTOFF
35
+ # Trim backtraces by getting the first 180 and last 20 lines
36
+ trimmed = backtrace[0, 180] + ['...[snip]...'] + backtrace[length - 20, 20]
31
37
  else
32
- frames.drop(ignore)
33
- end.join("\r\n")
38
+ trimmed = backtrace
39
+ end
40
+ trimmed
34
41
  end
35
42
  end
36
43
  end
data/lib/oboe/loading.rb CHANGED
@@ -57,7 +57,7 @@ module Oboe
57
57
  begin
58
58
  Oboe::API.extend_with_tracing
59
59
  rescue LoadError => e
60
- Oboe::API.extend_with_noop
60
+ puts "[oboe/error] Couldn't load oboe api."
61
61
  end
62
62
 
63
63
  require 'oboe/config'
data/lib/oboe/version.rb CHANGED
@@ -2,7 +2,7 @@ module Oboe
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- PATCH = 7
5
+ PATCH = 8
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
data/lib/oboe_metal.rb CHANGED
@@ -2,6 +2,12 @@
2
2
  # All rights reserved.
3
3
 
4
4
  module Oboe_metal
5
+ class Event
6
+ def self.metadataString(evt)
7
+ evt.metadataString()
8
+ end
9
+ end
10
+
5
11
  class Context
6
12
  def self.log(layer, label, options = {}, with_backtrace = true)
7
13
  evt = Oboe::Context.createEvent()
@@ -12,9 +18,9 @@ module Oboe_metal
12
18
  evt.addInfo(k.to_s, v.to_s)
13
19
  end
14
20
 
15
- evt.addInfo("Backtrace", Kernel.caller.join("\r\n")) if with_backtrace
21
+ evt.addInfo("Backtrace", Oboe::API.backtrace) if with_backtrace
16
22
 
17
- Oboe.reporter.sendReport(evt)
23
+ Oboe::Reporter.sendReport(evt)
18
24
  end
19
25
 
20
26
  def self.layer_op=(op)
@@ -33,86 +39,14 @@ module Oboe_metal
33
39
  end
34
40
  end
35
41
  end
36
- end
37
-
38
-
39
- module OboeMethodProfiling
40
- def self.included klass
41
- klass.extend ClassMethods
42
- end
43
-
44
- module ClassMethods
45
- def profile_method(method_name, profile_name, store_args=false, store_return=false, profile=false)
46
- #this only gets file and line where profiling is turned on, presumably
47
- #right after the function definition. ruby 1.9 has nice introspection (Method.source_location)
48
- #but its appears no such luck for ruby 1.8
49
- version = RbConfig::CONFIG['ruby_version']
50
- file = nil
51
- line = nil
52
- if version and version.match(/^1.9/)
53
- info = self.method(method_name).source_location
54
- if !info.nil?
55
- file = info[0]
56
- line = info[1]
57
- end
58
- else
59
- info = Kernel.caller[0].split(':')
60
- file = info.first
61
- line = info.last
62
- end
63
-
64
- #profiling via ruby-prof, is it possible to get return value of profiled code?
65
- code = "def _oboe_profiled_#{method_name}(*args, &block)
66
- def pps(*args)
67
- old_out = $stdout
68
- begin
69
- s = StringIO.new
70
- $stdout = s
71
- pp(*args)
72
- ensure
73
- $stdout = old_out
74
- end
75
- s.string
76
- end
77
-
78
- # file and line number are fetched in Context.log
79
- # because we have access to the correct backtrace there
80
- entry_kvs = {'Language' => 'ruby',
81
- 'ProfileName' => '#{profile_name}',
82
- 'FunctionName' => '#{method_name}',
83
- 'Class' => self.class.to_s.rpartition('::').last,
84
- 'Module' => self.class.to_s.rpartition('::').first,
85
- 'File' => '#{file}',
86
- 'LineNumber' => '#{line}'
87
- }
88
-
89
- if #{store_args}
90
- entry_kvs['Args'] = pps *args
91
- end
92
-
93
- Oboe::Context.log(nil, 'profile_entry', entry_kvs)
94
-
95
- ret = _oboe_orig_#{method_name}(*args, &block)
96
-
97
- exit_kvs = {'Language' => 'ruby',
98
- 'ProfileName' => '#{profile_name}'
99
- }
100
-
101
- if #{store_return}
102
- exit_kvs['ReturnValue'] = pps ret
103
- end
104
-
105
- Oboe::Context.log(nil, 'profile_exit', exit_kvs)
106
-
107
- ret
108
- end"
109
- class_eval code, __FILE__, __LINE__
110
- alias_method "_oboe_orig_#{method_name}", method_name
111
- alias_method method_name, "_oboe_profiled_#{method_name}"
112
- end
42
+
43
+ module Reporter
44
+ def self.sendReport(evt)
45
+ Oboe.reporter.sendReport(evt)
113
46
  end
47
+ end
114
48
  end
115
-
49
+
116
50
  module Oboe
117
51
  include Oboe_metal
118
52
 
@@ -159,9 +93,9 @@ module Oboe
159
93
  if !@reporter
160
94
  @reporter = Oboe::UdpReporter.new(Oboe::Config[:reporter_host])
161
95
  end
162
-
163
96
  return @reporter
164
97
  end
165
98
  end
166
99
 
167
- Oboe_metal::Context.init()
100
+ Oboe_metal::Context.init()
101
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oboe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,9 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-12 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: The oboe gem provides Tracelytics instrumentation for Ruby and Ruby frameworkes.
14
+ description: The oboe gem provides AppNeta instrumentation for Ruby and Ruby frameworks.
15
15
  email: contact@tracelytics.com
16
16
  executables: []
17
17
  extensions:
@@ -20,6 +20,7 @@ extra_rdoc_files:
20
20
  - LICENSE
21
21
  files:
22
22
  - lib/oboe_metal.rb
23
+ - lib/joboe_metal.rb
23
24
  - lib/oboe.rb
24
25
  - lib/oboe/loading.rb
25
26
  - lib/oboe/api.rb
@@ -42,6 +43,7 @@ files:
42
43
  - lib/oboe/frameworks/rails/inst/cassandra.rb
43
44
  - lib/oboe/frameworks/rails/inst/memcached.rb
44
45
  - lib/oboe/frameworks/rails/rails.rb
46
+ - lib/method_profiling.rb
45
47
  - lib/oboe_fu.rb
46
48
  - lib/rails/generators/oboe/install_generator.rb
47
49
  - lib/rails/generators/oboe/templates/oboe_initializer.rb