sampling_prof 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +2 -10
- data/lib/sampling_prof.jar +0 -0
- data/lib/sampling_prof.rb +28 -9
- data/lib/sampling_prof/internal.rb +37 -12
- metadata +52 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 63a43eb1a925cf63bf8fdac46684dec8aa383dd9
|
4
|
+
data.tar.gz: 594f3bef449906f6070b6d7340cd3b84ea508871
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2cd2222cbd8d514eb7fe44105b049ace04900b2f5e693e9d4b9f093b359e2436efd27866f27868de0bac322c3d9985af20894630786444f76aa8d1fdcdfefef
|
7
|
+
data.tar.gz: 48e70656def151a0edf1d598aec45ba83da147fbd04b6c0b9cb893f6ddaa141763c6e3ab03e68c23b6420e8fbef74cdc8595dea2348482f65f0190e1fc4dd7be
|
data/README.md
CHANGED
@@ -25,24 +25,16 @@ SamplingProf class initializer takes 1 argument:
|
|
25
25
|
|
26
26
|
SamplingProf class also takes block as another option to overwite default output handler, the default output handler will write output data to a local file defined by output_file attribute, which is default to SamplingProf::DEFAULT_OUTPUT_FILE
|
27
27
|
|
28
|
-
Notice, the output handler
|
28
|
+
Notice, for the performance and thread-safe concerns, the output handler will not be called in the context of the thread start profiling.
|
29
29
|
|
30
30
|
When a SamplingProf is initialized, a thread will be started to handle sampling process.
|
31
|
-
|
31
|
+
You need call SamplingProf#terminate to shutdown the sampling thread after everything is done.
|
32
32
|
|
33
33
|
### Sampling interval
|
34
34
|
|
35
35
|
This is an interval to control how frequent SamplingProf should take sample of target thread stacktrace.
|
36
36
|
The default value is 0.1 seconds.
|
37
37
|
|
38
|
-
### Multithreading
|
39
|
-
|
40
|
-
When running SamplingProf in multithreading environment (e.g. Rails multithreading production environment), it can profile all requests processing at same time cross threads.
|
41
|
-
|
42
|
-
For performance concerns, you should controll how many number of threads' sample while profiling.
|
43
|
-
|
44
|
-
Randomly select some threads for profiling, the result is still a statistical approximation.
|
45
|
-
|
46
38
|
Output data format
|
47
39
|
---------------
|
48
40
|
|
data/lib/sampling_prof.jar
CHANGED
Binary file
|
data/lib/sampling_prof.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
if RUBY_PLATFORM =~ /java/
|
2
2
|
require 'sampling_prof.jar'
|
3
|
+
require 'sampling_profiler'
|
3
4
|
else
|
4
5
|
require 'sampling_prof/internal'
|
5
6
|
end
|
@@ -11,23 +12,41 @@ class SamplingProf
|
|
11
12
|
|
12
13
|
# options:
|
13
14
|
# sampling_interval: default to 0.1 second
|
14
|
-
# max: max sampling threads, default to 8 threads
|
15
15
|
# &output_handler: default to write into output_file
|
16
|
-
def initialize(
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def initialize(sampling_interval=0.1, &output_handler)
|
17
|
+
@profiler = SamplingProfiler.new(sampling_interval)
|
18
|
+
@output_handler = block_given? ? output_handler : default_output_handler
|
19
|
+
end
|
20
|
+
|
21
|
+
def start(handler=nil)
|
22
|
+
@profiler.start(handler || @output_handler)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stop
|
26
|
+
@profiler.stop
|
27
|
+
end
|
28
|
+
|
29
|
+
def profiling?
|
30
|
+
@profiler.profiling?
|
31
|
+
end
|
32
|
+
|
33
|
+
def sampling_interval
|
34
|
+
@profiler.sampling_interval
|
35
|
+
end
|
36
|
+
|
37
|
+
def terminate
|
38
|
+
@profiler.terminate
|
20
39
|
end
|
21
40
|
|
22
41
|
def output_file
|
23
42
|
@output_file ||= DEFAULT_OUTPUT_FILE
|
24
43
|
end
|
25
44
|
|
26
|
-
def profile(&block)
|
27
|
-
start
|
28
|
-
yield
|
45
|
+
def profile(handler=nil, &block)
|
46
|
+
start(handler)
|
47
|
+
yield
|
29
48
|
ensure
|
30
|
-
stop
|
49
|
+
stop
|
31
50
|
end
|
32
51
|
|
33
52
|
def default_output_handler
|
@@ -1,13 +1,22 @@
|
|
1
|
-
require 'set'
|
2
1
|
require 'thread'
|
3
2
|
|
4
|
-
class
|
3
|
+
class SamplingProfiler
|
5
4
|
class Sampling
|
6
|
-
def initialize
|
5
|
+
def initialize(output_handler)
|
7
6
|
@samples = Hash.new{|h,k| h[k] = [0, 0] }
|
8
7
|
@call_graph = Hash.new{|h,k| h[k] = 0}
|
9
8
|
@nodes = {}
|
10
9
|
@start_at = Time.now
|
10
|
+
@output_handler = output_handler
|
11
|
+
@stop = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
@stop = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def stopped?
|
19
|
+
@stop
|
11
20
|
end
|
12
21
|
|
13
22
|
def runtime
|
@@ -18,6 +27,12 @@ class SamplingProf
|
|
18
27
|
!@nodes.empty?
|
19
28
|
end
|
20
29
|
|
30
|
+
def output
|
31
|
+
if sampling_data?
|
32
|
+
@output_handler.call(result)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
21
36
|
def result
|
22
37
|
ret = [runtime * 1000]
|
23
38
|
ret << @nodes.map {|node| node.join(',')}.join("\n")
|
@@ -60,27 +75,29 @@ class SamplingProf
|
|
60
75
|
end
|
61
76
|
end
|
62
77
|
|
63
|
-
attr_accessor :sampling_interval
|
78
|
+
attr_accessor :sampling_interval
|
64
79
|
|
65
|
-
def
|
80
|
+
def initialize(sampling_interval)
|
81
|
+
@sampling_interval = sampling_interval
|
66
82
|
@samplings = {}
|
83
|
+
@running = false
|
67
84
|
start_sampling_thread
|
68
85
|
end
|
69
86
|
|
70
|
-
def start
|
87
|
+
def start(output_handler)
|
71
88
|
unless @samplings.has_key?(Thread.current)
|
72
|
-
@samplings[Thread.current] = Sampling.new
|
89
|
+
@samplings[Thread.current] = Sampling.new(output_handler)
|
73
90
|
true
|
74
91
|
end
|
75
92
|
end
|
76
93
|
|
77
94
|
def stop
|
78
95
|
if @running
|
79
|
-
if sampling = @samplings
|
80
|
-
|
81
|
-
|
96
|
+
if sampling = @samplings[Thread.current]
|
97
|
+
unless sampling.stopped?
|
98
|
+
sampling.stop
|
99
|
+
true
|
82
100
|
end
|
83
|
-
true
|
84
101
|
end
|
85
102
|
end
|
86
103
|
end
|
@@ -105,11 +122,19 @@ class SamplingProf
|
|
105
122
|
@sampling_thread ||= Thread.start do
|
106
123
|
loop do
|
107
124
|
@samplings.dup.each do |t, s|
|
108
|
-
s.
|
125
|
+
if s.stopped?
|
126
|
+
s.output
|
127
|
+
@samplings.delete(t)
|
128
|
+
else
|
129
|
+
s.process(t)
|
130
|
+
end
|
109
131
|
end
|
110
132
|
sleep @sampling_interval
|
111
133
|
break unless @running
|
112
134
|
end
|
135
|
+
@samplings.each do |t, s|
|
136
|
+
s.output
|
137
|
+
end
|
113
138
|
end
|
114
139
|
end
|
115
140
|
end
|
metadata
CHANGED
@@ -1,70 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sampling_prof
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
|
8
|
-
autorequire:
|
6
|
+
authors:
|
7
|
+
- Xiao Li
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake-compiler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.9'
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.9.2
|
31
|
+
prerelease: false
|
32
|
+
type: :development
|
27
33
|
description: |
|
28
34
|
SamplingProf is a profiling tool that operates by sampling your running thread stacktrace. The result is statistical approximation, but it allows your code to run near full speed
|
29
|
-
|
30
|
-
|
31
|
-
- swing1979@gmail.com
|
35
|
+
email:
|
36
|
+
- swing1979@gmail.com
|
32
37
|
executables: []
|
33
|
-
|
34
38
|
extensions: []
|
35
|
-
|
36
39
|
extra_rdoc_files: []
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
- lib/sampling_prof/internal.rb
|
40
|
+
files:
|
41
|
+
- README.md
|
42
|
+
- lib/sampling_prof.jar
|
43
|
+
- lib/sampling_prof.rb
|
44
|
+
- lib/sampling_prof/internal.rb
|
43
45
|
homepage: https://github.com/xli/sampling_prof
|
44
|
-
licenses:
|
45
|
-
|
46
|
+
licenses:
|
47
|
+
- MIT
|
46
48
|
metadata: {}
|
47
|
-
|
48
|
-
post_install_message:
|
49
|
+
post_install_message:
|
49
50
|
rdoc_options: []
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
62
63
|
requirements: []
|
63
|
-
|
64
|
-
rubyforge_project:
|
64
|
+
rubyforge_project:
|
65
65
|
rubygems_version: 2.1.9
|
66
|
-
signing_key:
|
66
|
+
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Simple sampling profiler for ruby
|
69
69
|
test_files: []
|
70
|
-
|