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.
Files changed (2) hide show
  1. data/lib/thread-dump.rb +47 -22
  2. 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
- trap("QUIT") do
26
- Thread.start do
27
- out_arr = []
28
-
29
- ThreadDump::Dumper.new.dump.each do |thread_info|
30
- if ThreadDump::Config.output_format == :html
31
- out_arr << "<dt>#{thread_info[0]}</dt><dd>#{thread_info[1]}</dd>"
32
- else
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
- max_l_out_arr = out_arr.map { |out| out.size }.max
38
- fout = STDERR
44
+ def self.write_threads
45
+ out_arr = []
39
46
 
40
- if ThreadDump::Config.dump_target == :file
41
- fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
42
- end
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
- out_arr.each do |out|
45
- fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
46
- fout << out + "\n"
47
- end
55
+ max_l_out_arr = out_arr.map { |out| out.size }.max
56
+ fout = STDERR
48
57
 
49
- fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
50
- fout.flush
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
- if fout != STDERR
53
- fout.close
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.2
7
- date: 2007-08-08 00:00:00 -07:00
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