Class: TypeFusion::Sampler
- Inherits:
-
Object
- Object
- TypeFusion::Sampler
- Includes:
- Singleton
- Defined in:
- lib/type_fusion/sampler.rb
Instance Attribute Summary collapse
-
#samples ⇒ Object
Returns the value of attribute samples.
Instance Method Summary collapse
-
#initialize ⇒ Sampler
constructor
A new instance of Sampler.
- #inspect ⇒ Object
- #reset! ⇒ Object
- #to_s ⇒ Object
- #trace ⇒ Object
- #with_sampling ⇒ Object
Constructor Details
#initialize ⇒ Sampler
Returns a new instance of Sampler.
11 12 13 |
# File 'lib/type_fusion/sampler.rb', line 11 def initialize @samples = [] end |
Instance Attribute Details
#samples ⇒ Object
Returns the value of attribute samples.
9 10 11 |
# File 'lib/type_fusion/sampler.rb', line 9 def samples @samples end |
Instance Method Details
#inspect ⇒ Object
69 70 71 |
# File 'lib/type_fusion/sampler.rb', line 69 def inspect "#<TypeFusion::Sampler sample_count=#{@samples.count}>" end |
#reset! ⇒ Object
73 74 75 76 |
# File 'lib/type_fusion/sampler.rb', line 73 def reset! @samples = [] @trace = nil end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/type_fusion/sampler.rb', line 65 def to_s inspect end |
#trace ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/type_fusion/sampler.rb', line 23 def trace @trace ||= TracePoint.trace(:return) do |tracepoint| if sample?(tracepoint.path) receiver = begin tracepoint.binding.receiver.name rescue StandardError tracepoint.binding.receiver.class.name end method_name = tracepoint.method_id location = tracepoint.binding.source_location.join(":") gem_and_version = location.gsub(gem_path, "").split("/").first gem, version = gem_and_version_from(gem_and_version) args = tracepoint.parameters.to_h(&:reverse) parameters = extract_parameters(args, tracepoint.binding) return_value = type_for_object(tracepoint.return_value) sample_values = { gem_name: gem, gem_version: version, receiver: receiver, method_name: method_name, application_name: TypeFusion.config.application_name, location: location, type_fusion_version: VERSION, parameters: parameters, return_value: return_value, } sample = SampleCall.new(*sample_values.values) samples << sample begin SampleJob.perform_async(sample) rescue StandardError => e puts "[TypeFusion] Couldn't enqueue sample: #{e.inspect}" end end end.tap(&:disable) end |
#with_sampling ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/type_fusion/sampler.rb', line 15 def with_sampling trace.enable yield if block_given? trace.disable end |