thread-dump 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/thread_dumper.c +13 -21
- data/ext/thread_dumper.h +1 -71
- data/lib/thread-dump.rb +5 -6
- metadata +5 -5
data/ext/thread_dumper.c
CHANGED
@@ -6,6 +6,8 @@ static VALUE rb_cDumper;
|
|
6
6
|
static VALUE backtrace(rb_thread_t th)
|
7
7
|
{
|
8
8
|
char buf[BUFSIZ];
|
9
|
+
char buf2[BUFSIZ];
|
10
|
+
char otherbuf[BUFSIZ];
|
9
11
|
VALUE ary;
|
10
12
|
NODE *n;
|
11
13
|
struct FRAME *frame;
|
@@ -14,41 +16,29 @@ static VALUE backtrace(rb_thread_t th)
|
|
14
16
|
frame = th->frame;
|
15
17
|
ary = rb_ary_new();
|
16
18
|
|
17
|
-
rb_ary_push(ary, rb_obj_id(th->thread));
|
18
|
-
|
19
19
|
if (n) {
|
20
|
-
|
21
|
-
rb_ary_push(ary, rb_str_new2(buf));
|
22
|
-
}
|
23
|
-
|
24
|
-
/*for (; frame && (n = frame->node); frame = frame->prev) {
|
25
|
-
if (frame->prev && frame->prev->last_func) {
|
26
|
-
if (frame->prev->node == n) continue;
|
27
|
-
snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
|
28
|
-
n->nd_file, nd_line(n),
|
29
|
-
rb_id2name(frame->prev->last_func));
|
30
|
-
}
|
31
|
-
else {
|
20
|
+
if(nd_line(n) && n->nd_file){
|
32
21
|
snprintf(buf, BUFSIZ, "%s:%d", n->nd_file, nd_line(n));
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
rb_ary_push(ary, rb_str_new2(buf));
|
23
|
+
}
|
24
|
+
}
|
36
25
|
|
37
26
|
return ary;
|
38
27
|
}
|
39
28
|
|
29
|
+
|
40
30
|
static VALUE
|
41
31
|
dump()
|
42
32
|
{
|
43
33
|
VALUE ary_dump;
|
44
34
|
VALUE curr_rb_thread;
|
45
|
-
struct
|
46
|
-
struct
|
35
|
+
struct rb_thread* curr_thread;
|
36
|
+
struct rb_thread* th;
|
47
37
|
|
48
38
|
ary_dump = rb_ary_new();
|
49
39
|
|
50
40
|
curr_rb_thread = rb_thread_current();
|
51
|
-
Data_Get_Struct(curr_rb_thread, struct
|
41
|
+
Data_Get_Struct(curr_rb_thread, struct rb_thread, curr_thread);
|
52
42
|
|
53
43
|
if (curr_thread) {
|
54
44
|
FOREACH_THREAD_FROM(curr_thread, th) {
|
@@ -66,5 +56,7 @@ Init_thread_dumper()
|
|
66
56
|
{
|
67
57
|
rb_mThreadDump = rb_define_module("ThreadDump");
|
68
58
|
rb_cDumper = rb_define_class_under(rb_mThreadDump, "Dumper", rb_cObject);
|
69
|
-
|
59
|
+
rb_define_singleton_method(rb_cDumper, "dump", dump, 0);
|
70
60
|
}
|
61
|
+
|
62
|
+
|
data/ext/thread_dumper.h
CHANGED
@@ -7,75 +7,5 @@
|
|
7
7
|
#define FOREACH_THREAD_FROM(f,x) x = f; do { x = x->next;
|
8
8
|
#define END_FOREACH_FROM(f,x) } while (x != f)
|
9
9
|
|
10
|
-
typedef jmp_buf rb_jmpbuf_t;
|
11
|
-
|
12
|
-
enum thread_status {
|
13
|
-
THREAD_TO_KILL,
|
14
|
-
THREAD_RUNNABLE,
|
15
|
-
THREAD_STOPPED,
|
16
|
-
THREAD_KILLED,
|
17
|
-
};
|
18
|
-
|
19
|
-
typedef struct thread * rb_thread_t;
|
20
|
-
|
21
|
-
struct thread {
|
22
|
-
struct thread *next, *prev;
|
23
|
-
rb_jmpbuf_t context;
|
24
|
-
#ifdef SAVE_WIN32_EXCEPTION_LIST
|
25
|
-
DWORD win32_exception_list;
|
26
|
-
#endif
|
27
|
-
|
28
|
-
VALUE result;
|
29
|
-
|
30
|
-
long stk_len;
|
31
|
-
long stk_max;
|
32
|
-
VALUE *stk_ptr;
|
33
|
-
VALUE *stk_pos;
|
34
|
-
#ifdef __ia64__
|
35
|
-
VALUE *bstr_ptr;
|
36
|
-
long bstr_len;
|
37
|
-
#endif
|
38
|
-
|
39
|
-
struct FRAME *frame;
|
40
|
-
struct SCOPE *scope;
|
41
|
-
struct RVarmap *dyna_vars;
|
42
|
-
struct BLOCK *block;
|
43
|
-
struct iter *iter;
|
44
|
-
struct tag *tag;
|
45
|
-
VALUE klass;
|
46
|
-
VALUE wrapper;
|
47
|
-
NODE *cref;
|
48
|
-
|
49
|
-
int flags; /* misc. states (vmode/rb_trap_immediate/raised) */
|
50
|
-
|
51
|
-
NODE *node;
|
52
|
-
|
53
|
-
int tracing;
|
54
|
-
VALUE errinfo;
|
55
|
-
VALUE last_status;
|
56
|
-
VALUE last_line;
|
57
|
-
VALUE last_match;
|
58
|
-
|
59
|
-
int safe;
|
60
|
-
|
61
|
-
enum thread_status status;
|
62
|
-
int wait_for;
|
63
|
-
int fd;
|
64
|
-
fd_set readfds;
|
65
|
-
fd_set writefds;
|
66
|
-
fd_set exceptfds;
|
67
|
-
int select_value;
|
68
|
-
double delay;
|
69
|
-
rb_thread_t join;
|
70
|
-
|
71
|
-
int abort;
|
72
|
-
int priority;
|
73
|
-
VALUE thgroup;
|
74
|
-
|
75
|
-
st_table *locals;
|
76
|
-
|
77
|
-
VALUE thread;
|
78
|
-
};
|
79
|
-
|
80
|
-
static rb_thread_t curr_thread = 0;
|
81
10
|
static VALUE backtrace(rb_thread_t);
|
11
|
+
// static VALUE backtrace(rb_thread_t th, int lev);
|
data/lib/thread-dump.rb
CHANGED
@@ -3,7 +3,7 @@ require 'thread_dumper'
|
|
3
3
|
module ThreadDump
|
4
4
|
VERSION_MAJOR = 0
|
5
5
|
VERSION_MINOR = 0
|
6
|
-
VERSION_SUB =
|
6
|
+
VERSION_SUB = 5
|
7
7
|
|
8
8
|
VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_SUB}"
|
9
9
|
end
|
@@ -18,7 +18,7 @@ module ThreadDump
|
|
18
18
|
def dump_target=(dump_target)
|
19
19
|
@@dump_target = dump_target
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def output_format
|
23
23
|
@@output_format ||= :text
|
24
24
|
end
|
@@ -44,19 +44,18 @@ module ThreadDump
|
|
44
44
|
def self.write_threads
|
45
45
|
out_arr = []
|
46
46
|
|
47
|
-
ThreadDump::Dumper.
|
47
|
+
ThreadDump::Dumper.dump.each do |thread_info|
|
48
48
|
if ThreadDump::Config.output_format == :html
|
49
49
|
out_arr << "<dt>#{thread_info[1]}</dt><dd>#{thread_info[0]}</dd>"
|
50
50
|
else
|
51
51
|
out_arr << "Thread #{thread_info[0]}: #{thread_info[1]}"
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
54
|
max_l_out_arr = out_arr.map { |out| out.size }.max
|
56
55
|
fout = STDERR
|
57
56
|
|
58
57
|
if ThreadDump::Config.dump_target == :file
|
59
|
-
fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
|
58
|
+
fout = File.open("/tmp/#{$$}.ruby_threads.html", "w")
|
60
59
|
end
|
61
60
|
|
62
61
|
out_arr.each do |out|
|
@@ -76,6 +75,6 @@ end
|
|
76
75
|
|
77
76
|
trap("QUIT") do
|
78
77
|
Thread.start do
|
79
|
-
ThreadDump::Monitor.
|
78
|
+
ThreadDump::Monitor.write_threads
|
80
79
|
end
|
81
80
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: thread-dump
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.5
|
7
|
+
date: 2007-10-30 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
|
11
11
|
email:
|
12
12
|
homepage:
|
13
|
-
rubyforge_project:
|
13
|
+
rubyforge_project:
|
14
14
|
description:
|
15
15
|
autorequire: lib
|
16
16
|
default_executable:
|
@@ -27,7 +27,7 @@ signing_key:
|
|
27
27
|
cert_chain:
|
28
28
|
post_install_message:
|
29
29
|
authors:
|
30
|
-
- Greg Fodor
|
30
|
+
- Greg Fodor and Bryan Duxbury
|
31
31
|
files:
|
32
32
|
- ext/thread_dumper.c
|
33
33
|
- ext/thread_dumper.h
|