Class: SidekiqProfilingMiddleware::StackProf

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_profiling_middleware/stack_prof.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_prefix: nil, only: nil, s3_bucket: nil, stack_prof_options: {}) ⇒ StackProf

Returns a new instance of StackProf.



7
8
9
10
11
12
13
14
15
# File 'lib/sidekiq_profiling_middleware/stack_prof.rb', line 7

def initialize(output_prefix: nil, only: nil, s3_bucket: nil, stack_prof_options: {})
  stack_prof_options[:mode] ||= :cpu
  stack_prof_options[:interval] ||= 1000
  @options = stack_prof_options

  @output_prefix = output_prefix || self.class.default_output_prefix
  @only = only
  @s3_bucket = s3_bucket
end

Class Method Details

.default_output_prefixObject



39
40
41
# File 'lib/sidekiq_profiling_middleware/stack_prof.rb', line 39

def self.default_output_prefix
  @default_output_prefix ||= Util.default_output_prefix("stackprof")
end

Instance Method Details

#call(worker, msg, queue) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sidekiq_profiling_middleware/stack_prof.rb', line 17

def call(worker, msg, queue)
  # bail out if whitelist doesn't match
  if only && !only.include?(worker.class)
    return yield
  end

  out = "#{output_prefix}#{Util.worker_names[worker.class]}_#{Util.current_epoch_ms}.dump"

  unless s3_bucket
    ::StackProf.run(options.merge(out: out)) { yield }
    return
  end

  require "sidekiq_profiling_middleware/s3"

  out = S3::Object.new(bucket: s3_bucket, key: out)
  rep = ::StackProf.run(options) { yield }
  Marshal.dump(rep, out)
ensure
  out.upload if out && s3_bucket
end