thread-dump 0.0.1 → 0.0.2

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 +40 -5
  2. metadata +2 -2
data/lib/thread-dump.rb CHANGED
@@ -1,21 +1,56 @@
1
1
  require 'thread_dumper'
2
2
 
3
+ module ThreadDump
4
+ class Config
5
+ class << self
6
+ def dump_target
7
+ @@dump_target ||= :stderr
8
+ end
9
+
10
+ def dump_target=(dump_target)
11
+ @@dump_target = dump_target
12
+ end
13
+
14
+ def output_format
15
+ @@output_format ||= :text
16
+ end
17
+
18
+ def output_format=(output_format)
19
+ @@output_format = output_format
20
+ end
21
+ end
22
+ end
23
+ end
24
+
3
25
  trap("QUIT") do
4
26
  Thread.start do
5
27
  out_arr = []
6
28
 
7
29
  ThreadDump::Dumper.new.dump.each do |thread_info|
8
- out_arr << "Thread #{thread_info[0]}: #{thread_info[1]}"
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]}"
34
+ end
9
35
  end
10
36
 
11
37
  max_l_out_arr = out_arr.map { |out| out.size }.max
38
+ fout = STDERR
39
+
40
+ if ThreadDump::Config.dump_target == :file
41
+ fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
42
+ end
12
43
 
13
44
  out_arr.each do |out|
14
- STDERR << "-" * max_l_out_arr + "\n"
15
- STDERR << out + "\n"
45
+ fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
46
+ fout << out + "\n"
16
47
  end
17
48
 
18
- STDERR << "-" * max_l_out_arr + "\n"
19
- STDERR.flush
49
+ fout << "-" * max_l_out_arr + "\n" if ThreadDump::Config.output_format == :text
50
+ fout.flush
51
+
52
+ if fout != STDERR
53
+ fout.close
54
+ end
20
55
  end
21
56
  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.1
7
- date: 2007-07-23 00:00:00 -07:00
6
+ version: 0.0.2
7
+ date: 2007-08-08 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