thread-dump 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thread-dump.rb +47 -22
- metadata +2 -2
data/lib/thread-dump.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'thread_dumper'
|
2
2
|
|
3
|
+
module ThreadDump
|
4
|
+
VERSION_MAJOR = 0
|
5
|
+
VERSION_MINOR = 0
|
6
|
+
VERSION_SUB = 3
|
7
|
+
|
8
|
+
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_SUB}"
|
9
|
+
end
|
10
|
+
|
3
11
|
module ThreadDump
|
4
12
|
class Config
|
5
13
|
class << self
|
@@ -22,35 +30,52 @@ module ThreadDump
|
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
out_arr << "Thread #{thread_info[0]}: #{thread_info[1]}"
|
33
|
+
module ThreadDump
|
34
|
+
class Monitor
|
35
|
+
def self.start(time_between_dumps = 60)
|
36
|
+
Thread.start(time_between_dumps) do |sleep_time|
|
37
|
+
loop do
|
38
|
+
ThreadDump::Monitor.write_threads
|
39
|
+
sleep sleep_time
|
40
|
+
end
|
34
41
|
end
|
35
42
|
end
|
36
43
|
|
37
|
-
|
38
|
-
|
44
|
+
def self.write_threads
|
45
|
+
out_arr = []
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
ThreadDump::Dumper.new.dump.each do |thread_info|
|
48
|
+
if ThreadDump::Config.output_format == :html
|
49
|
+
out_arr << "<dt>#{thread_info[1]}</dt><dd>#{thread_info[0]}</dd>"
|
50
|
+
else
|
51
|
+
out_arr << "Thread #{thread_info[0]}: #{thread_info[1]}"
|
52
|
+
end
|
53
|
+
end
|
43
54
|
|
44
|
-
|
45
|
-
fout
|
46
|
-
fout << out + "\n"
|
47
|
-
end
|
55
|
+
max_l_out_arr = out_arr.map { |out| out.size }.max
|
56
|
+
fout = STDERR
|
48
57
|
|
49
|
-
|
50
|
-
|
58
|
+
if ThreadDump::Config.dump_target == :file
|
59
|
+
fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
|
60
|
+
end
|
61
|
+
|
62
|
+
out_arr.each do |out|
|
63
|
+
fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
|
64
|
+
fout << out + "\n"
|
65
|
+
end
|
51
66
|
|
52
|
-
|
53
|
-
fout.
|
67
|
+
fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
|
68
|
+
fout.flush
|
69
|
+
|
70
|
+
if fout != STDERR
|
71
|
+
fout.close
|
72
|
+
end
|
54
73
|
end
|
55
74
|
end
|
56
75
|
end
|
76
|
+
|
77
|
+
trap("QUIT") do
|
78
|
+
Thread.start do
|
79
|
+
ThreadDump::Monitor.save_threads
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: thread-dump
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-08-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2007-08-09 00:00:00 -07:00
|
8
8
|
summary: Utility which will cause thread dumps during ctrl-break of Ruby process.
|
9
9
|
require_paths:
|
10
10
|
- lib
|