Class: SidekiqProfilingMiddleware::StackProf
- Inherits:
-
Object
- Object
- SidekiqProfilingMiddleware::StackProf
- Defined in:
- lib/sidekiq_profiling_middleware/stack_prof.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(worker, msg, queue) ⇒ Object
-
#initialize(output_prefix: nil, only: nil, s3_bucket: nil, stack_prof_options: {}) ⇒ StackProf
constructor
A new instance of StackProf.
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: {}) [:mode] ||= :cpu [:interval] ||= 1000 @options = @output_prefix = output_prefix || self.class.default_output_prefix @only = only @s3_bucket = s3_bucket end |
Class Method Details
.default_output_prefix ⇒ Object
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(.merge(out: out)) { yield } return end require "sidekiq_profiling_middleware/s3" out = S3::Object.new(bucket: s3_bucket, key: out) rep = ::StackProf.run() { yield } Marshal.dump(rep, out) ensure out.upload if out && s3_bucket end |