sigdump 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +4 -0
  3. data/README.md +7 -5
  4. data/lib/sigdump.rb +49 -32
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20e16e2f6471680f7163393c866dce385f1f1d3f
4
- data.tar.gz: 61638fe8baf560c431eb59751f072e1c992d0614
3
+ metadata.gz: 66f910121c29c40af36d02163e3a1dce1fb7ef0a
4
+ data.tar.gz: e74f81b26007404c52def1e63fc6af7446c792ce
5
5
  SHA512:
6
- metadata.gz: c49d03384c0dd3410e38abb7b08f621689419adee7c365e01ef683ff94cdede5bb6f2fa87b5810da811db4282a57b79c54a71c56adf71b2ad05284fb76ffd0d2
7
- data.tar.gz: d1eb8bd6df734dd9c24617ad01c192243c614c2b5cb9ed882eb64cf8363a1817962dee78420a23d6c0f98597891435db5eeee2f4236e1b2a447eb19bd1012f83
6
+ metadata.gz: 81e8d1684cf5a3540d6259ca484dde9358d22fdcc183b8ceaa02543d13b74946331afb29af807026905412f2d98dcd29da6ba07b99f62dad400c6f46aad0860d
7
+ data.tar.gz: 7bfe2a13f20411fab7ea75707f29ea0f68453e306fee3f5b9b41efce693f16a1efd916a4d06c59780be59db708f0365ff28952d0addfd00ef1ca6fb0f8e18052
data/ChangeLog CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ 2016-02-04 version 0.2.4:
3
+
4
+ * In JRuby, signal handler shows Java stacktrace in addition to Ruby stacktrace
5
+
2
6
  2015-05-21 version 0.2.3:
3
7
 
4
8
  * Signal handler shows GC.stat (by @sonots / Naotoshi Seo)
data/README.md CHANGED
@@ -4,9 +4,9 @@ In short: *SIGQUIT of Java VM for Ruby.*
4
4
 
5
5
  Server applications (like Rails app) cause performance problems, deadlock or memory swapping from time to time. But it's painful to reproduce such kind of problems. If we can get information from a running process without restarting it, it's really helpful.
6
6
 
7
- `sigdump` gem installs a signal handler which dumps backtrace of running threads, number of allocated objects per class, and GC statistics.
7
+ `sigdump` gem makes it possible. It installs a signal handler which dumps backtrace of running threads, number of allocated objects per class, and GC statistics.
8
8
 
9
- If GC profiler is enabled (`GC::Profiler.enable` is called), it also dumps GC profiler reports.
9
+ If GC profiler is enabled (`GC::Profiler.enable` is called), it also dumps GC profiler reports. If the runtime is JRuby, it dumpds Java stacktrace in addition to Ruby stacktrace.
10
10
 
11
11
  ## Install
12
12
 
@@ -18,10 +18,11 @@ gem 'sigdump', :require => 'sigdump/setup'
18
18
 
19
19
  ### Resque
20
20
 
21
- Because Resque traps `SIGCONT`, you need to change the signal to another signal such as TSTP.
22
- In environment.rb:
21
+ Because Resque traps `SIGCONT` and it conflicts with sigdump, you need to change the signal such as `SIGTSTP`.
22
+ To change the signal, set name of a signal to `SIGDUMP_SIGNAL` environment variable.
23
23
 
24
24
  ```ruby
25
+ # environment.rb:
25
26
  # setup sigdump: https://github.com/frsyuki/sigdump
26
27
  ENV['SIGDUMP_SIGNAL'] = 'TSTP'
27
28
  require 'sigdump/setup'
@@ -29,10 +30,11 @@ require 'sigdump/setup'
29
30
 
30
31
  ## Usage
31
32
 
32
- Send `SIGCONT` signal to dump backtrace and heap status to `/tmp/sigdump-<pid>.log`:
33
+ Send `SIGCONT` signal to dump backtrace and heap status to `/tmp/sigdump-<pid>.log` file:
33
34
 
34
35
  ```shell
35
36
  $ kill -CONT <pid>
37
+ $ cat /tmp/sigdump-<pid>.log
36
38
  ```
37
39
 
38
40
  Set `SIGDUMP_SIGNAL` environment variable to change the signal (default: SIGCONT).
@@ -1,5 +1,5 @@
1
1
  module Sigdump
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
 
4
4
  def self.setup(signal=ENV['SIGDUMP_SIGNAL'] || 'SIGCONT', path=ENV['SIGDUMP_PATH'])
5
5
  Kernel.trap(signal) do
@@ -21,8 +21,21 @@ module Sigdump
21
21
  end
22
22
 
23
23
  def self.dump_all_thread_backtrace(io)
24
+ use_java_bean = defined?(Thread.current.to_java.getNativeThread.getId)
25
+ if use_java_bean
26
+ begin
27
+ bean = java.lang.management.ManagementFactory.getThreadMXBean
28
+ java_stacktrace_map = Hash[bean.getThreadInfo(bean.getAllThreadIds, true, true).map {|t| [t.getThreadId, t.toString] }]
29
+ rescue
30
+ # security error may happen
31
+ end
32
+ end
24
33
  Thread.list.each do |thread|
25
34
  dump_backtrace(thread, io)
35
+ if java_stacktrace_map
36
+ io.write " In Java " + java_stacktrace_map[thread.to_java.getNativeThread.getId]
37
+ io.flush
38
+ end
26
39
  end
27
40
  nil
28
41
  end
@@ -45,37 +58,41 @@ module Sigdump
45
58
  end
46
59
 
47
60
  def self.dump_object_count(io)
48
- io.write " Built-in objects:\n"
49
- ObjectSpace.count_objects.sort_by {|k,v| -v }.each {|k,v|
50
- io.write "%10s: %s\n" % [_fn(v), k]
51
- }
52
-
53
- string_size = 0
54
- array_size = 0
55
- hash_size = 0
56
- cmap = {}
57
- ObjectSpace.each_object {|o|
58
- c = o.class
59
- cmap[c] = (cmap[c] || 0) + 1
60
- if c == String
61
- string_size += o.bytesize
62
- elsif c == Array
63
- array_size = o.size
64
- elsif c == Hash
65
- hash_size = o.size
66
- end
67
- }
68
-
69
- io.write " All objects:\n"
70
- cmap.sort_by {|k,v| -v }.each {|k,v|
71
- io.write "%10s: %s\n" % [_fn(v), k]
72
- }
73
-
74
- io.write " String #{_fn(string_size)} bytes\n"
75
- io.write " Array #{_fn(array_size)} elements\n"
76
- io.write " Hash #{_fn(hash_size)} pairs\n"
77
-
78
- io.flush
61
+ if defined?(ObjectSpace.count_objects)
62
+ # ObjectSpace doesn't work in JRuby
63
+
64
+ io.write " Built-in objects:\n"
65
+ ObjectSpace.count_objects.sort_by {|k,v| -v }.each {|k,v|
66
+ io.write "%10s: %s\n" % [_fn(v), k]
67
+ }
68
+
69
+ string_size = 0
70
+ array_size = 0
71
+ hash_size = 0
72
+ cmap = {}
73
+ ObjectSpace.each_object {|o|
74
+ c = o.class
75
+ cmap[c] = (cmap[c] || 0) + 1
76
+ if c == String
77
+ string_size += o.bytesize
78
+ elsif c == Array
79
+ array_size = o.size
80
+ elsif c == Hash
81
+ hash_size = o.size
82
+ end
83
+ }
84
+
85
+ io.write " All objects:\n"
86
+ cmap.sort_by {|k,v| -v }.each {|k,v|
87
+ io.write "%10s: %s\n" % [_fn(v), k]
88
+ }
89
+
90
+ io.write " String #{_fn(string_size)} bytes\n"
91
+ io.write " Array #{_fn(array_size)} elements\n"
92
+ io.write " Hash #{_fn(hash_size)} pairs\n"
93
+
94
+ io.flush
95
+ end
79
96
  nil
80
97
  end
81
98
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigdump
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -67,3 +67,4 @@ specification_version: 4
67
67
  summary: Setup signal handler which dumps backtrace of running threads and number
68
68
  of allocated objects per class. Require 'sigdump/setup', send SIGCONT, and see /tmp/sigdump-<pid>.log.
69
69
  test_files: []
70
+ has_rdoc: false