sidekiq_profiling_middleware 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cced27e9d23e332d1ae2792c52f0036f41ba475
|
4
|
+
data.tar.gz: 2addbd37f60439e347ea24a064e27af85b942f3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92ad7bbef7b4abda7e41746a9f3db2beed1493205f33427a6ecfc1ba8d67fbcdf3894346e99132a0a3022e350d2b806a5c19c5d71e48430647722372cc42cc87
|
7
|
+
data.tar.gz: 2198a20a36102a6465c905c955200b6b8758a0d86c79a63e967928dc0ebf8a30dc6e23347ca7b73f457156b13b9f5d5c5f8760135c80274c374f346f74676ccc
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "sidekiq_profiling_middleware/util"
|
3
|
+
require "memory_profiler"
|
4
|
+
|
5
|
+
module SidekiqProfilingMiddleware
|
6
|
+
class MemoryProfiler
|
7
|
+
def initialize(output_prefix: nil, only: nil, s3_bucket: nil, memory_profiler_options: {})
|
8
|
+
@options = memory_profiler_options
|
9
|
+
|
10
|
+
@output_prefix = output_prefix || self.class.default_output_prefix
|
11
|
+
@only = only
|
12
|
+
@s3_bucket = s3_bucket
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(worker, msg, queue)
|
16
|
+
# bail out if whitelist doesn't match
|
17
|
+
if only && !only.include?(worker.class)
|
18
|
+
return yield
|
19
|
+
end
|
20
|
+
|
21
|
+
report = ::MemoryProfiler.report(options) do
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
|
25
|
+
out = "#{output_prefix}#{Util.worker_names[worker.class]}_#{Util.current_epoch_ms}.txt"
|
26
|
+
|
27
|
+
unless s3_bucket
|
28
|
+
report.pretty_print(to_file: out)
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
require "sidekiq_profiling_middleware/s3"
|
33
|
+
|
34
|
+
out = S3::Object.new(bucket: s3_bucket, key: out)
|
35
|
+
report.pretty_print(out)
|
36
|
+
ensure
|
37
|
+
out.upload if out && s3_bucket
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default_output_prefix
|
41
|
+
@default_output_prefix ||= Util.default_output_prefix("memory_profiler")
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader(
|
47
|
+
:only,
|
48
|
+
:options,
|
49
|
+
:output_prefix,
|
50
|
+
:s3_bucket,
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "stringio"
|
3
|
+
require "aws-sdk"
|
4
|
+
|
5
|
+
module SidekiqProfilingMiddleware
|
6
|
+
class S3
|
7
|
+
class Object < StringIO
|
8
|
+
def initialize(bucket:, key:)
|
9
|
+
@bucket = bucket
|
10
|
+
@key = key
|
11
|
+
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload
|
16
|
+
rewind
|
17
|
+
|
18
|
+
S3.client.put_object(bucket: bucket, key: key, body: self)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :bucket, :key
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.client=(client)
|
27
|
+
@client = client
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.client
|
31
|
+
@client ||= Aws::S3::Client.new
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "sidekiq_profiling_middleware/util"
|
3
|
+
require "stackprof"
|
4
|
+
|
5
|
+
module SidekiqProfilingMiddleware
|
6
|
+
class StackProf
|
7
|
+
def initialize(output_prefix: nil, only: nil, s3_bucket: nil, stack_prof_options: {})
|
8
|
+
stack_prof_options[:mode] ||= :cpu
|
9
|
+
stack_prof_options[:interval] ||= 1000
|
10
|
+
@options = stack_prof_options
|
11
|
+
|
12
|
+
@output_prefix = output_prefix || self.class.default_output_prefix
|
13
|
+
@only = only
|
14
|
+
@s3_bucket = s3_bucket
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(worker, msg, queue)
|
18
|
+
# bail out if whitelist doesn't match
|
19
|
+
if only && !only.include?(worker.class)
|
20
|
+
return yield
|
21
|
+
end
|
22
|
+
|
23
|
+
out = "#{output_prefix}#{Util.worker_names[worker.class]}_#{Util.current_epoch_ms}.dump"
|
24
|
+
|
25
|
+
unless s3_bucket
|
26
|
+
::StackProf.run(options.merge(out: out)) { yield }
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
require "sidekiq_profiling_middleware/s3"
|
31
|
+
|
32
|
+
out = S3::Object.new(bucket: s3_bucket, key: out)
|
33
|
+
rep = ::StackProf.run(options) { yield }
|
34
|
+
Marshal.dump(rep, out)
|
35
|
+
ensure
|
36
|
+
out.upload if out && s3_bucket
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.default_output_prefix
|
40
|
+
@default_output_prefix ||= Util.default_output_prefix("stackprof")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader(
|
46
|
+
:only,
|
47
|
+
:options,
|
48
|
+
:output_prefix,
|
49
|
+
:s3_bucket,
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SidekiqProfilingMiddleware
|
3
|
+
class Util
|
4
|
+
BOOTED_AT_FORMAT = "%m-%d-%H-%M-%S"
|
5
|
+
|
6
|
+
def self.default_output_prefix(name)
|
7
|
+
"tmp/#{name}_bootedat#{Time.now.strftime(BOOTED_AT_FORMAT)}_"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.worker_names
|
11
|
+
# allocate hash for quickly converting class names to
|
12
|
+
# nice names a file system would like
|
13
|
+
@worker_names ||= Hash.new do |hash, worker_name|
|
14
|
+
hash[worker_name] = worker_name.to_s.gsub(/\W+/, "_").gsub(/(^_|_$)/, "")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.current_epoch_ms
|
19
|
+
(Time.now.utc.to_f * 1000).to_i
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq_profiling_middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Callum Jones
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2010-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.54.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.54.0
|
27
|
+
description:
|
28
|
+
email: contact@callumj.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/sidekiq_profiling_middleware/memory_profiler.rb
|
34
|
+
- lib/sidekiq_profiling_middleware/s3.rb
|
35
|
+
- lib/sidekiq_profiling_middleware/stack_prof.rb
|
36
|
+
- lib/sidekiq_profiling_middleware/util.rb
|
37
|
+
homepage: https://github.com/callumj/sidekiq_profiling_middleware
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.6.14.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: StackProf and MemoryProfiler middleware for Sidekiq
|
61
|
+
test_files: []
|