sampling_prof 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67a32fb9840e432741396d9678bfdff29325ae6d
4
- data.tar.gz: f09d48a2ab060f0a21e3a72e65818ecde00f1e61
3
+ metadata.gz: a34b1b2f319695ae28caf643e852eb60f8fa77d2
4
+ data.tar.gz: 10eb087c4dbbf7fac115ae910119ef62ee922423
5
5
  SHA512:
6
- metadata.gz: 6a78021baf2b12e5ad9d88ac050814a02a15ba3987ee1b3f5988547f8e4b90ad04ff4cf8a74ce612c8c49ac3044b2c599296a713335ea47b159354f6468b104d
7
- data.tar.gz: 0efb16d632fca6470ea2dfc338857d47f3f69938aa68b40cf34db2fe2db9a1a7efe01130ea67d1ccd021cc681befc31c913f30488b55ca8cbc3a13c52b5da7c6
6
+ metadata.gz: 8b590f513f6055b87469484db2c9f1034d3b1c0b3ce0ebcada5110c1dcd613493cd36efa4af1f7d42487904f35e34e3b267f2b786bb17d57dfb609120c9d45a0
7
+ data.tar.gz: 8fecad2a160fe99ec0630720b1d330dddfbb5f24b733788a5b972b3b9f99078ca1246c29fa88256b60a5a0c4ab4be6383e4d35f4ea55a90dfdd4d3af0061c5ab
data/README.md CHANGED
@@ -35,6 +35,10 @@ The default value is 0.1 seconds.
35
35
 
36
36
  When running SamplingProf in multithreading environment (e.g. Rails multithreading production environment), you need turn on multithreading mode so that you can profile all requests processing at same time cross threads.
37
37
 
38
+ For performance concerns, multithreading mode will only take limit number of threads' sample while profiling. The default max samples of the threads is 4, you can change it by set max_sampling_threads.
39
+
40
+ Since we randomly find max_sampling_threads number of threads in profiling threads, the result is still a statistical approximation.
41
+
38
42
  ### output interval
39
43
 
40
44
  Output interval controls how frequent SamplingProf should call output handler to flush out cached data.
@@ -62,6 +66,9 @@ It should be only one line.
62
66
  The time unit is ms.
63
67
  Runtime can be used to compute an estimated runtime of a call element.
64
68
 
69
+ When it's multithreading mode, the runtime result is a little bit tricky.
70
+ But think about we queuing up all threads, and put them into single thread, the time doing sampling in this one single thread is the runtime we output here.
71
+
65
72
  ### call element id map
66
73
 
67
74
  For storage efficiency, we build this map for counts and call graph chunks to use id instead of a call element string.
Binary file
@@ -28,7 +28,7 @@ class SamplingProf
28
28
  end
29
29
 
30
30
  def process
31
- @threads.each do |thread|
31
+ @threads.sample_threads.each do |thread|
32
32
  locations = thread.backtrace_locations
33
33
  from = -1
34
34
  paths = []
@@ -64,22 +64,21 @@ class SamplingProf
64
64
  end
65
65
 
66
66
  class Threads
67
+ attr_accessor :max
68
+
67
69
  def initialize
68
70
  @hash = {}
69
71
  @mutex = Mutex.new
70
72
  @remain_sampling_time = 0
73
+ @max = 4
71
74
  end
72
75
 
73
- def each(&block)
74
- dup.each(&block)
75
- end
76
-
77
- def dup
78
- @mutex.synchronize { @hash.keys.dup }
76
+ def sample_threads
77
+ @mutex.synchronize { @hash.keys.dup.shuffle[0..@max] }
79
78
  end
80
79
 
81
- def add(obj)
82
- @mutex.synchronize { @hash[obj] = Time.now }
80
+ def add(obj, time=Time.now)
81
+ @mutex.synchronize { @hash[obj] = time }
83
82
  end
84
83
 
85
84
  def sampling_runtime
@@ -110,6 +109,10 @@ class SamplingProf
110
109
  @threads = Threads.new
111
110
  end
112
111
 
112
+ def max_sampling_threads=(max)
113
+ @threads.max = max
114
+ end
115
+
113
116
  def start
114
117
  if @multithreading || !@running
115
118
  @running = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sampling_prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-03-27 00:00:00 Z
12
+ date: 2014-03-28 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler