ruby-dtrace-consumer 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/LICENCE +20 -0
  2. data/README.md +51 -0
  3. data/ext/Makefile +187 -0
  4. data/ext/dtrace_aggdata.c +132 -0
  5. data/ext/dtrace_aggdata.c~ +141 -0
  6. data/ext/dtrace_aggdata.o +0 -0
  7. data/ext/dtrace_api.bundle +0 -0
  8. data/ext/dtrace_api.c +102 -0
  9. data/ext/dtrace_api.c~ +113 -0
  10. data/ext/dtrace_api.h +138 -0
  11. data/ext/dtrace_api.h~ +155 -0
  12. data/ext/dtrace_api.o +0 -0
  13. data/ext/dtrace_bufdata.c +130 -0
  14. data/ext/dtrace_bufdata.c~ +139 -0
  15. data/ext/dtrace_bufdata.o +0 -0
  16. data/ext/dtrace_dropdata.c +121 -0
  17. data/ext/dtrace_dropdata.c~ +131 -0
  18. data/ext/dtrace_dropdata.o +0 -0
  19. data/ext/dtrace_errdata.c +100 -0
  20. data/ext/dtrace_errdata.c~ +110 -0
  21. data/ext/dtrace_errdata.o +0 -0
  22. data/ext/dtrace_hdl.c +677 -0
  23. data/ext/dtrace_hdl.c~ +689 -0
  24. data/ext/dtrace_hdl.o +0 -0
  25. data/ext/dtrace_probedata.c +273 -0
  26. data/ext/dtrace_probedata.c~ +283 -0
  27. data/ext/dtrace_probedata.o +0 -0
  28. data/ext/dtrace_probedesc.c +93 -0
  29. data/ext/dtrace_probedesc.c~ +78 -0
  30. data/ext/dtrace_probedesc.o +0 -0
  31. data/ext/dtrace_process.c +44 -0
  32. data/ext/dtrace_process.c~ +56 -0
  33. data/ext/dtrace_process.o +0 -0
  34. data/ext/dtrace_program.c +52 -0
  35. data/ext/dtrace_program.c~ +62 -0
  36. data/ext/dtrace_program.o +0 -0
  37. data/ext/dtrace_programinfo.c +70 -0
  38. data/ext/dtrace_programinfo.c~ +60 -0
  39. data/ext/dtrace_programinfo.o +0 -0
  40. data/ext/dtrace_recdesc.c +37 -0
  41. data/ext/dtrace_recdesc.c~ +46 -0
  42. data/ext/dtrace_recdesc.o +0 -0
  43. data/ext/dtrace_util.c +92 -0
  44. data/ext/dtrace_util.o +0 -0
  45. data/ext/extconf.rb +7 -0
  46. data/lib/dtrace.rb +95 -0
  47. data/lib/dtrace/aggregate.rb +40 -0
  48. data/lib/dtrace/aggregateset.rb +19 -0
  49. data/lib/dtrace/consumer.rb +174 -0
  50. data/lib/dtrace/data.rb +85 -0
  51. data/lib/dtrace/dof.rb +8 -0
  52. data/lib/dtrace/printfrecord.rb +10 -0
  53. data/lib/dtrace/probedata.rb +23 -0
  54. data/lib/dtrace/probedesc.rb +15 -0
  55. data/lib/dtrace/record.rb +11 -0
  56. data/lib/dtrace/stackrecord.rb +31 -0
  57. data/lib/dtrace/tracer.rb +35 -0
  58. data/lib/dtrace/version.rb +8 -0
  59. data/lib/dtrace/version.rb~ +8 -0
  60. data/lib/dtraceconsumer.rb +9 -0
  61. data/test/test_aggregates.rb +45 -0
  62. data/test/test_drops_errors.rb +166 -0
  63. data/test/test_dtrace.rb +155 -0
  64. data/test/test_gc.rb +11 -0
  65. data/test/test_helper.rb +20 -0
  66. data/test/test_helper.rb~ +16 -0
  67. data/test/test_legacy_consumer.rb +47 -0
  68. data/test/test_probedata.rb +30 -0
  69. data/test/test_processes.rb +66 -0
  70. data/test/test_profile.rb +198 -0
  71. data/test/test_repeat.rb +50 -0
  72. data/test/test_rubyprobe.rb +52 -0
  73. data/test/test_rubyprobe.rb~ +52 -0
  74. data/test/test_typefilter.rb +94 -0
  75. metadata +121 -0
Binary file
@@ -0,0 +1,130 @@
1
+ /* Ruby-DTrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ RUBY_EXTERN VALUE eDTraceException;
8
+ RUBY_EXTERN VALUE cDTraceAggData;
9
+ RUBY_EXTERN VALUE cDTraceRecDesc;
10
+ RUBY_EXTERN VALUE cDTraceProbe;
11
+
12
+ /*
13
+ * Returns the enabled probe id which generated this data
14
+ */
15
+ VALUE dtracebufdata_epid(VALUE self)
16
+ {
17
+ dtrace_bufdata_t *bufdata;
18
+
19
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
20
+
21
+ if (bufdata->dtbda_probe) {
22
+ return INT2FIX(bufdata->dtbda_probe->dtpda_edesc->dtepd_epid);
23
+ }
24
+
25
+ return Qnil;
26
+ }
27
+
28
+
29
+ /*
30
+ * Returns the DTraceProbe for the probe which generated this data
31
+ */
32
+ VALUE dtracebufdata_probe(VALUE self)
33
+ {
34
+ dtrace_bufdata_t *bufdata;
35
+ VALUE dtraceprobe;
36
+
37
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
38
+
39
+ if (bufdata->dtbda_probe) {
40
+ dtraceprobe = Data_Wrap_Struct(cDTraceProbe, 0, NULL, (dtrace_probedesc_t *)bufdata->dtbda_probe->dtpda_pdesc);
41
+ return dtraceprobe;
42
+ }
43
+
44
+ return Qnil;
45
+ }
46
+
47
+ /*
48
+ * Returns the record in this DTraceBufdata. Records are returned as
49
+ * either DTraceRecords or DTraceStackRecords as appropriate for the
50
+ * type of action.
51
+ */
52
+ VALUE dtracebufdata_record(VALUE self)
53
+ {
54
+ dtrace_bufdata_t *bufdata;
55
+ const dtrace_recdesc_t *rec;
56
+ dtrace_actkind_t act = DTRACEACT_NONE;
57
+ const char *s;
58
+ VALUE v = Qnil;
59
+ VALUE dtracerecord;
60
+ VALUE dtraceaggdata;
61
+ VALUE dtracerecdesc;
62
+
63
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
64
+
65
+ if (bufdata->dtbda_aggdata) {
66
+ dtraceaggdata = Data_Wrap_Struct(cDTraceAggData, 0, NULL, (dtrace_bufdata_t *)bufdata);
67
+ return dtraceaggdata;
68
+ }
69
+
70
+ s = bufdata->dtbda_buffered;
71
+ if (s == NULL) {
72
+ return Qnil;
73
+ }
74
+
75
+ rec = bufdata->dtbda_recdesc;
76
+ if (rec) {
77
+ act = rec->dtrd_action;
78
+ }
79
+
80
+ switch (act) {
81
+ case DTRACEACT_DIFEXPR:
82
+ /* trace() action */
83
+ break;
84
+ case DTRACEACT_PRINTF:
85
+ /* printf action, not available in probedata */
86
+ v = rb_str_new2(s);
87
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::PrintfRecord"));
88
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
89
+ rb_iv_set(dtracerecord, "@value", v);
90
+ return (dtracerecord);
91
+ break;
92
+ case DTRACEACT_STACK:
93
+ case DTRACEACT_USTACK:
94
+ case DTRACEACT_JSTACK:
95
+ /* stand-alone stack(), ustack(), or jstack() action */
96
+ v = rb_str_new2(s);
97
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::StackRecord"));
98
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
99
+ rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
100
+ return (dtracerecord);
101
+ break;
102
+ case DTRACEACT_USYM:
103
+ case DTRACEACT_UADDR:
104
+ case DTRACEACT_UMOD:
105
+ case DTRACEACT_SYM:
106
+ case DTRACEACT_MOD:
107
+ v = rb_str_new2(s);
108
+ break;
109
+ case DTRACEACT_PRINTA:
110
+ v = rb_str_new2(s);
111
+ break;
112
+ default:
113
+ /*
114
+ * The record handle defers nothing else to this
115
+ * bufhandler.
116
+ */
117
+ break;
118
+ }
119
+
120
+ if (!NIL_P(v)) {
121
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::Record"));
122
+ rb_iv_set(dtracerecord, "@value", v);
123
+ rb_iv_set(dtracerecord, "@action", INT2FIX(act));
124
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
125
+ return (dtracerecord);
126
+ }
127
+ else {
128
+ return Qnil;
129
+ }
130
+ }
@@ -0,0 +1,139 @@
1
+ /* Ruby-DTrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ RUBY_EXTERN VALUE eDTraceException;
8
+ RUBY_EXTERN VALUE cDTraceAggData;
9
+ RUBY_EXTERN VALUE cDTraceRecDesc;
10
+ RUBY_EXTERN VALUE cDTraceProbe;
11
+
12
+ /* :nodoc: */
13
+ VALUE dtracebufdata_init(VALUE self)
14
+ {
15
+ dtrace_bufdata_t *data;
16
+
17
+ Data_Get_Struct(self, dtrace_bufdata_t, data);
18
+ return self;
19
+ }
20
+
21
+ /*
22
+ * Returns the enabled probe id which generated this data
23
+ */
24
+ VALUE dtracebufdata_epid(VALUE self)
25
+ {
26
+ dtrace_bufdata_t *bufdata;
27
+
28
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
29
+
30
+ if (bufdata->dtbda_probe) {
31
+ return INT2FIX(bufdata->dtbda_probe->dtpda_edesc->dtepd_epid);
32
+ }
33
+
34
+ return Qnil;
35
+ }
36
+
37
+
38
+ /*
39
+ * Returns the DTraceProbe for the probe which generated this data
40
+ */
41
+ VALUE dtracebufdata_probe(VALUE self)
42
+ {
43
+ dtrace_bufdata_t *bufdata;
44
+ VALUE dtraceprobe;
45
+
46
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
47
+
48
+ if (bufdata->dtbda_probe) {
49
+ dtraceprobe = Data_Wrap_Struct(cDTraceProbe, 0, NULL, (dtrace_probedesc_t *)bufdata->dtbda_probe->dtpda_pdesc);
50
+ return dtraceprobe;
51
+ }
52
+
53
+ return Qnil;
54
+ }
55
+
56
+ /*
57
+ * Returns the record in this DTraceBufdata. Records are returned as
58
+ * either DTraceRecords or DTraceStackRecords as appropriate for the
59
+ * type of action.
60
+ */
61
+ VALUE dtracebufdata_record(VALUE self)
62
+ {
63
+ dtrace_bufdata_t *bufdata;
64
+ const dtrace_recdesc_t *rec;
65
+ dtrace_actkind_t act = DTRACEACT_NONE;
66
+ const char *s;
67
+ VALUE v = Qnil;
68
+ VALUE dtracerecord;
69
+ VALUE dtraceaggdata;
70
+ VALUE dtracerecdesc;
71
+
72
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
73
+
74
+ if (bufdata->dtbda_aggdata) {
75
+ dtraceaggdata = Data_Wrap_Struct(cDTraceAggData, 0, NULL, (dtrace_bufdata_t *)bufdata);
76
+ return dtraceaggdata;
77
+ }
78
+
79
+ s = bufdata->dtbda_buffered;
80
+ if (s == NULL) {
81
+ return Qnil;
82
+ }
83
+
84
+ rec = bufdata->dtbda_recdesc;
85
+ if (rec) {
86
+ act = rec->dtrd_action;
87
+ }
88
+
89
+ switch (act) {
90
+ case DTRACEACT_DIFEXPR:
91
+ /* trace() action */
92
+ break;
93
+ case DTRACEACT_PRINTF:
94
+ /* printf action, not available in probedata */
95
+ v = rb_str_new2(s);
96
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::PrintfRecord"));
97
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
98
+ rb_iv_set(dtracerecord, "@value", v);
99
+ return (dtracerecord);
100
+ break;
101
+ case DTRACEACT_STACK:
102
+ case DTRACEACT_USTACK:
103
+ case DTRACEACT_JSTACK:
104
+ /* stand-alone stack(), ustack(), or jstack() action */
105
+ v = rb_str_new2(s);
106
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::StackRecord"));
107
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
108
+ rb_funcall(dtracerecord, rb_intern("parse"), 1, v);
109
+ return (dtracerecord);
110
+ break;
111
+ case DTRACEACT_USYM:
112
+ case DTRACEACT_UADDR:
113
+ case DTRACEACT_UMOD:
114
+ case DTRACEACT_SYM:
115
+ case DTRACEACT_MOD:
116
+ v = rb_str_new2(s);
117
+ break;
118
+ case DTRACEACT_PRINTA:
119
+ v = rb_str_new2(s);
120
+ break;
121
+ default:
122
+ /*
123
+ * The record handle defers nothing else to this
124
+ * bufhandler.
125
+ */
126
+ break;
127
+ }
128
+
129
+ if (!NIL_P(v)) {
130
+ dtracerecord = rb_class_new_instance(0, NULL, rb_path2class("DTrace::Record"));
131
+ rb_iv_set(dtracerecord, "@value", v);
132
+ rb_iv_set(dtracerecord, "@action", INT2FIX(act));
133
+ rb_iv_set(dtracerecord, "@from", rb_str_new2("bufdata"));
134
+ return (dtracerecord);
135
+ }
136
+ else {
137
+ return Qnil;
138
+ }
139
+ }
Binary file
@@ -0,0 +1,121 @@
1
+ /* Ruby-DTrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ RUBY_EXTERN VALUE eDTraceException;
8
+
9
+ /* Returns the CPU which generated this drop record */
10
+ VALUE dtracedropdata_cpu(VALUE self)
11
+ {
12
+ dtrace_dropdata_t *data;
13
+ processorid_t cpu;
14
+
15
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
16
+
17
+ if (data) {
18
+ cpu = data->dtdda_cpu;
19
+ return INT2FIX(cpu);
20
+ }
21
+ else {
22
+ return Qnil;
23
+ }
24
+ }
25
+
26
+ /* Returns the number of records dropped in this drop record */
27
+ VALUE dtracedropdata_drops(VALUE self)
28
+ {
29
+ dtrace_dropdata_t *data;
30
+
31
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
32
+
33
+ if (data) {
34
+ return INT2FIX(data->dtdda_drops);
35
+ }
36
+ else {
37
+ return Qnil;
38
+ }
39
+ }
40
+
41
+ /* Returns the number of records dropped in total */
42
+ VALUE dtracedropdata_total(VALUE self)
43
+ {
44
+ dtrace_dropdata_t *data;
45
+
46
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
47
+
48
+ if (data) {
49
+ return INT2FIX(data->dtdda_total);
50
+ }
51
+ else {
52
+ return Qnil;
53
+ }
54
+ }
55
+
56
+ /* Returns a message from the DTrace library describing this drop
57
+ record. */
58
+ VALUE dtracedropdata_msg(VALUE self)
59
+ {
60
+ dtrace_dropdata_t *data;
61
+
62
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
63
+
64
+ if (data) {
65
+ return rb_str_new2(data->dtdda_msg);
66
+ }
67
+ else {
68
+ return Qnil;
69
+ }
70
+ }
71
+
72
+ /* Returns the reason for the drop (the "drop kind") */
73
+ VALUE dtracedropdata_kind(VALUE self)
74
+ {
75
+ dtrace_dropdata_t *data;
76
+ VALUE kind;
77
+
78
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
79
+
80
+ if (data) {
81
+ switch (data->dtdda_kind) {
82
+ case DTRACEDROP_PRINCIPAL:
83
+ kind = rb_str_new2("drop to principal buffer");
84
+ break;
85
+ case DTRACEDROP_AGGREGATION:
86
+ kind = rb_str_new2("drop to aggregation buffer");
87
+ break;
88
+ case DTRACEDROP_DYNAMIC:
89
+ kind = rb_str_new2("dynamic drop");
90
+ break;
91
+ case DTRACEDROP_DYNRINSE:
92
+ kind = rb_str_new2("dyn drop due to rinsing");
93
+ break;
94
+ case DTRACEDROP_DYNDIRTY:
95
+ kind = rb_str_new2("dyn drop due to dirty");
96
+ break;
97
+ case DTRACEDROP_SPEC:
98
+ kind = rb_str_new2("speculative drop");
99
+ break;
100
+ case DTRACEDROP_SPECBUSY:
101
+ kind = rb_str_new2("spec drop due to busy");
102
+ break;
103
+ case DTRACEDROP_SPECUNAVAIL:
104
+ kind = rb_str_new2("spec drop due to unavail");
105
+ break;
106
+ case DTRACEDROP_STKSTROVERFLOW:
107
+ kind = rb_str_new2("stack string tab overflow");
108
+ break;
109
+ case DTRACEDROP_DBLERROR:
110
+ kind = rb_str_new2("error in ERROR probe");
111
+ break;
112
+ default:
113
+ kind = rb_str_new2("unknown");
114
+ break;
115
+ }
116
+ return kind;
117
+ }
118
+ else {
119
+ return Qnil;
120
+ }
121
+ }
@@ -0,0 +1,131 @@
1
+ /* Ruby-DTrace
2
+ * (c) 2007 Chris Andrews <chris@nodnol.org>
3
+ */
4
+
5
+ #include "dtrace_api.h"
6
+
7
+ RUBY_EXTERN VALUE eDTraceException;
8
+
9
+ /* :nodoc: */
10
+ VALUE dtracedropdata_init(VALUE self)
11
+ {
12
+ dtrace_dropdata_t *data;
13
+
14
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
15
+ return self;
16
+ }
17
+
18
+ /* Returns the CPU which generated this drop record */
19
+ VALUE dtracedropdata_cpu(VALUE self)
20
+ {
21
+ dtrace_dropdata_t *data;
22
+ processorid_t cpu;
23
+
24
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
25
+
26
+ if (data) {
27
+ cpu = data->dtdda_cpu;
28
+ return INT2FIX(cpu);
29
+ }
30
+ else {
31
+ return Qnil;
32
+ }
33
+ }
34
+
35
+ /* Returns the number of records dropped in this drop record */
36
+ VALUE dtracedropdata_drops(VALUE self)
37
+ {
38
+ dtrace_dropdata_t *data;
39
+
40
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
41
+
42
+ if (data) {
43
+ return INT2FIX(data->dtdda_drops);
44
+ }
45
+ else {
46
+ return Qnil;
47
+ }
48
+ }
49
+
50
+ /* Returns the number of records dropped in total */
51
+ VALUE dtracedropdata_total(VALUE self)
52
+ {
53
+ dtrace_dropdata_t *data;
54
+
55
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
56
+
57
+ if (data) {
58
+ return INT2FIX(data->dtdda_total);
59
+ }
60
+ else {
61
+ return Qnil;
62
+ }
63
+ }
64
+
65
+ /* Returns a message from the DTrace library describing this drop
66
+ record. */
67
+ VALUE dtracedropdata_msg(VALUE self)
68
+ {
69
+ dtrace_dropdata_t *data;
70
+
71
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
72
+
73
+ if (data) {
74
+ return rb_str_new2(data->dtdda_msg);
75
+ }
76
+ else {
77
+ return Qnil;
78
+ }
79
+ }
80
+
81
+ /* Returns the reason for the drop (the "drop kind") */
82
+ VALUE dtracedropdata_kind(VALUE self)
83
+ {
84
+ dtrace_dropdata_t *data;
85
+ VALUE kind;
86
+
87
+ Data_Get_Struct(self, dtrace_dropdata_t, data);
88
+
89
+ if (data) {
90
+ switch (data->dtdda_kind) {
91
+ case DTRACEDROP_PRINCIPAL:
92
+ kind = rb_str_new2("drop to principal buffer");
93
+ break;
94
+ case DTRACEDROP_AGGREGATION:
95
+ kind = rb_str_new2("drop to aggregation buffer");
96
+ break;
97
+ case DTRACEDROP_DYNAMIC:
98
+ kind = rb_str_new2("dynamic drop");
99
+ break;
100
+ case DTRACEDROP_DYNRINSE:
101
+ kind = rb_str_new2("dyn drop due to rinsing");
102
+ break;
103
+ case DTRACEDROP_DYNDIRTY:
104
+ kind = rb_str_new2("dyn drop due to dirty");
105
+ break;
106
+ case DTRACEDROP_SPEC:
107
+ kind = rb_str_new2("speculative drop");
108
+ break;
109
+ case DTRACEDROP_SPECBUSY:
110
+ kind = rb_str_new2("spec drop due to busy");
111
+ break;
112
+ case DTRACEDROP_SPECUNAVAIL:
113
+ kind = rb_str_new2("spec drop due to unavail");
114
+ break;
115
+ case DTRACEDROP_STKSTROVERFLOW:
116
+ kind = rb_str_new2("stack string tab overflow");
117
+ break;
118
+ case DTRACEDROP_DBLERROR:
119
+ kind = rb_str_new2("error in ERROR probe");
120
+ break;
121
+ default:
122
+ kind = rb_str_new2("unknown");
123
+ break;
124
+ }
125
+ return kind;
126
+ }
127
+ else {
128
+ return Qnil;
129
+ }
130
+ }
131
+