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
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008, 2009, 2011, 2012 Chris Andrews <chris@nodnol.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ ruby-dtrace-consumer is Ruby bindings for libdtrace, which allows you
2
+ to write D-based programs with Ruby, accessing traced data in Ruby.
3
+
4
+ The corresponding provider library, allowing you to create probes
5
+ meaningful to your Ruby programs, may be found as "ruby-usdt".
6
+
7
+ "ruby-dtrace", the predecessor to both these gems, is now deprecated
8
+ and will not be updated.
9
+
10
+ == FEEDBACK
11
+
12
+ Fork the repository on Github: http://github.com/chrisa/ruby-dtrace
13
+
14
+ == FEATURES
15
+
16
+ * Access to the D API
17
+ * Probe metadata
18
+ * Run D programs
19
+ * Access aggregates
20
+ * Consume output from D programs
21
+
22
+ == SYNOPSIS
23
+
24
+ require 'dtrace'
25
+
26
+ t = DTrace.new
27
+ progtext = 'ruby$1:::function-entry{ @a[strjoin(strjoin(copyinstr(arg0),"."),copyinstr(arg1))] = count(); } END { printa(@a); }'
28
+ prog = t.compile progtext
29
+ prog.execute
30
+
31
+ t.go
32
+
33
+ [...]
34
+
35
+ c = DTraceConsumer.new(t)
36
+ c.consume_once do |rec|
37
+ # handle records
38
+ end
39
+
40
+ == REQUIREMENTS
41
+
42
+ * For the consumer API, platform with DTrace support (Solaris and
43
+ Illumos-derived systems, Mac OS X 10.5+, FreeBSD).
44
+
45
+ * root, or some/all of the dtrace privileges on Solaris: dtrace_user,
46
+ dtrace_proc and dtrace_kernel.
47
+
48
+ == INSTALL
49
+
50
+ $ sudo gem install ruby-dtrace-consumer
51
+
@@ -0,0 +1,187 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /Users/chris/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1
8
+ hdrdir = /Users/chris/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1
9
+ arch_hdrdir = /Users/chris/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/$(arch)
10
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
11
+ prefix = $(DESTDIR)/Users/chris/.rvm/rubies/ruby-1.9.2-p320
12
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
13
+ exec_prefix = $(prefix)
14
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
15
+ sitehdrdir = $(rubyhdrdir)/site_ruby
16
+ rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
17
+ vendordir = $(rubylibprefix)/vendor_ruby
18
+ sitedir = $(rubylibprefix)/site_ruby
19
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
20
+ mandir = $(datarootdir)/man
21
+ localedir = $(datarootdir)/locale
22
+ libdir = $(exec_prefix)/lib
23
+ psdir = $(docdir)
24
+ pdfdir = $(docdir)
25
+ dvidir = $(docdir)
26
+ htmldir = $(docdir)
27
+ infodir = $(datarootdir)/info
28
+ docdir = $(datarootdir)/doc/$(PACKAGE)
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ includedir = $(prefix)/include
31
+ localstatedir = $(prefix)/var
32
+ sharedstatedir = $(prefix)/com
33
+ sysconfdir = $(prefix)/etc
34
+ datadir = $(datarootdir)
35
+ datarootdir = $(prefix)/share
36
+ libexecdir = $(exec_prefix)/libexec
37
+ sbindir = $(exec_prefix)/sbin
38
+ bindir = $(exec_prefix)/bin
39
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
40
+ archdir = $(rubylibdir)/$(arch)
41
+ sitelibdir = $(sitedir)/$(ruby_version)
42
+ sitearchdir = $(sitelibdir)/$(sitearch)
43
+ vendorlibdir = $(vendordir)/$(ruby_version)
44
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
45
+
46
+ CC = gcc-apple-4.2
47
+ CXX = g++
48
+ LIBRUBY = $(LIBRUBY_SO)
49
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
50
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
51
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
52
+ OUTFLAG = -o
53
+ COUTFLAG = -o
54
+
55
+ RUBY_EXTCONF_H =
56
+ cflags = $(optflags) $(debugflags) $(warnflags)
57
+ optflags = -O3
58
+ debugflags = -ggdb
59
+ warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
60
+ CFLAGS = -fno-common -I/Users/chris/.rvm/usr/include -fno-common -pipe
61
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
62
+ DEFS =
63
+ CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags)
64
+ CXXFLAGS = $(CFLAGS) $(cxxflags)
65
+ ldflags = -L. -L/Users/chris/.rvm/usr/lib -L/usr/local/lib
66
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
67
+ ARCH_FLAG =
68
+ DLDFLAGS = $(ldflags) $(dldflags)
69
+ LDSHARED = $(CC) -dynamic -bundle
70
+ LDSHAREDXX = $(CXX) -dynamic -bundle
71
+ AR = ar
72
+ EXEEXT =
73
+
74
+ RUBY_BASE_NAME = ruby
75
+ RUBY_INSTALL_NAME = ruby
76
+ RUBY_SO_NAME = ruby.1.9.1
77
+ arch = x86_64-darwin12.2.0
78
+ sitearch = $(arch)
79
+ ruby_version = 1.9.1
80
+ ruby = /Users/chris/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
81
+ RUBY = $(ruby)
82
+ RM = rm -f
83
+ RM_RF = $(RUBY) -run -e rm -- -rf
84
+ RMDIRS = $(RUBY) -run -e rmdir -- -p
85
+ MAKEDIRS = mkdir -p
86
+ INSTALL = /usr/bin/install -c
87
+ INSTALL_PROG = $(INSTALL) -m 0755
88
+ INSTALL_DATA = $(INSTALL) -m 644
89
+ COPY = cp
90
+
91
+ #### End of system configuration section. ####
92
+
93
+ preload =
94
+
95
+ libpath = . $(libdir)
96
+ LIBPATH = -L. -L$(libdir)
97
+ DEFFILE =
98
+
99
+ CLEANFILES = mkmf.log
100
+ DISTCLEANFILES =
101
+ DISTCLEANDIRS =
102
+
103
+ extout =
104
+ extout_prefix =
105
+ target_prefix =
106
+ LOCAL_LIBS =
107
+ LIBS = $(LIBRUBYARG_SHARED) -ldtrace -lpthread -ldl -lobjc
108
+ SRCS = dtrace_aggdata.c dtrace_api.c dtrace_bufdata.c dtrace_dropdata.c dtrace_errdata.c dtrace_hdl.c dtrace_probedata.c dtrace_probedesc.c dtrace_process.c dtrace_program.c dtrace_programinfo.c dtrace_recdesc.c dtrace_util.c
109
+ OBJS = dtrace_aggdata.o dtrace_api.o dtrace_bufdata.o dtrace_dropdata.o dtrace_errdata.o dtrace_hdl.o dtrace_probedata.o dtrace_probedesc.o dtrace_process.o dtrace_program.o dtrace_programinfo.o dtrace_recdesc.o dtrace_util.o
110
+ TARGET = dtrace_api
111
+ DLLIB = $(TARGET).bundle
112
+ EXTSTATIC =
113
+ STATIC_LIB =
114
+
115
+ BINDIR = $(bindir)
116
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
117
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
118
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
119
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
120
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
121
+
122
+ TARGET_SO = $(DLLIB)
123
+ CLEANLIBS = $(TARGET).bundle
124
+ CLEANOBJS = *.o *.bak
125
+
126
+ all: $(DLLIB)
127
+ static: $(STATIC_LIB)
128
+ .PHONY: all install static install-so install-rb
129
+ .PHONY: clean clean-so clean-rb
130
+
131
+ clean-rb-default::
132
+ clean-rb::
133
+ clean-so::
134
+ clean: clean-so clean-rb-default clean-rb
135
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
136
+
137
+ distclean-rb-default::
138
+ distclean-rb::
139
+ distclean-so::
140
+ distclean: clean distclean-so distclean-rb-default distclean-rb
141
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
142
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
143
+ @-$(RMDIRS) $(DISTCLEANDIRS)
144
+
145
+ realclean: distclean
146
+ install: install-so install-rb
147
+
148
+ install-so: $(RUBYARCHDIR)
149
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
150
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
151
+ @-$(MAKEDIRS) $(@D)
152
+ $(INSTALL_PROG) $(DLLIB) $(@D)
153
+ install-rb: pre-install-rb install-rb-default
154
+ install-rb-default: pre-install-rb-default
155
+ pre-install-rb: Makefile
156
+ pre-install-rb-default: Makefile
157
+ $(RUBYARCHDIR):
158
+ $(MAKEDIRS) $@
159
+
160
+ site-install: site-install-so site-install-rb
161
+ site-install-so: install-so
162
+ site-install-rb: install-rb
163
+
164
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
165
+
166
+ .cc.o:
167
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
168
+
169
+ .cxx.o:
170
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
171
+
172
+ .cpp.o:
173
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
174
+
175
+ .C.o:
176
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
177
+
178
+ .c.o:
179
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
180
+
181
+ $(DLLIB): $(OBJS) Makefile
182
+ @-$(RM) $(@)
183
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
184
+
185
+
186
+
187
+ $(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
@@ -0,0 +1,132 @@
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 value of this aggregate, be it the aggregation value,
10
+ or a member of an aggregation key tuple. */
11
+ VALUE dtraceaggdata_value(VALUE self)
12
+ {
13
+ dtrace_bufdata_t *bufdata;
14
+ const dtrace_aggdata_t *aggdata;
15
+ const dtrace_aggdesc_t *aggdesc;
16
+ const dtrace_recdesc_t *rec;
17
+ const char *s;
18
+ dtrace_actkind_t act = DTRACEACT_NONE;
19
+ int64_t aggid;
20
+ uint64_t normal;
21
+ caddr_t addr;
22
+ int64_t value;
23
+ VALUE v = Qnil;
24
+
25
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
26
+ aggdata = bufdata->dtbda_aggdata;
27
+ s = bufdata->dtbda_buffered;
28
+ rec = bufdata->dtbda_recdesc;
29
+
30
+ if (aggdata == NULL) {
31
+ rb_raise(eDTraceException, "null aggdata");
32
+ return Qnil;
33
+ }
34
+
35
+ aggdesc = aggdata->dtada_desc;
36
+
37
+ if (aggdesc == NULL) {
38
+ rb_raise(eDTraceException, "null aggdesc");
39
+ return Qnil;
40
+ }
41
+
42
+ aggid = *((int64_t *)(aggdata->dtada_data +
43
+ aggdesc->dtagd_rec[0].dtrd_offset));
44
+ if (aggid < 0) {
45
+ rb_raise(eDTraceException, "negative aggregation ID");
46
+ return Qnil;
47
+ }
48
+
49
+ act = rec->dtrd_action;
50
+
51
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY) {
52
+
53
+ switch (act) {
54
+ case DTRACEACT_STACK:
55
+ case DTRACEACT_USTACK:
56
+ case DTRACEACT_JSTACK:
57
+ /* todo */
58
+ break;
59
+ case DTRACEACT_USYM:
60
+ case DTRACEACT_UADDR:
61
+ case DTRACEACT_UMOD:
62
+ case DTRACEACT_SYM:
63
+ case DTRACEACT_MOD:
64
+ /* todo */
65
+ break;
66
+ default:
67
+ v = handle_bytedata((aggdata->dtada_data + rec->dtrd_offset), rec->dtrd_size);
68
+ }
69
+
70
+
71
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
72
+
73
+ normal = aggdata->dtada_normal;
74
+ addr = aggdata->dtada_data + rec->dtrd_offset;
75
+
76
+ if (act == DTRACEAGG_AVG) {
77
+ uint64_t *data = (uint64_t *)addr;
78
+ value = (data[0] ? (long long)(data[1] / normal / data[0]) : 0);
79
+ } else {
80
+ value = (*((int64_t *)addr)) / normal;
81
+ }
82
+
83
+ if (act == DTRACEAGG_QUANTIZE || act == DTRACEAGG_LQUANTIZE) {
84
+ v = Qnil; // dtj_new_distribution(data, rec, jc);
85
+ } else {
86
+ switch (act) {
87
+ case DTRACEAGG_COUNT:
88
+ if (value < 0)
89
+ rb_raise(eDTraceException, "count value is negative");
90
+ v = LL2NUM(value);
91
+ break;
92
+ case DTRACEAGG_AVG:
93
+ case DTRACEAGG_MIN:
94
+ case DTRACEAGG_MAX:
95
+ case DTRACEAGG_SUM:
96
+ v = LL2NUM(value);
97
+ break;
98
+ default:
99
+ v = Qnil;
100
+ rb_raise(eDTraceException, "unexpected aggregation action: %d", act);
101
+ }
102
+ }
103
+
104
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
105
+
106
+ v = Qnil;
107
+
108
+ }
109
+
110
+ return v;
111
+ }
112
+
113
+ /* Return the type of this DTraceAggData: tuple, value or last. Used
114
+ to form tuples and values into DTraceAggregate objects. */
115
+ VALUE dtraceaggdata_aggtype(VALUE self)
116
+ {
117
+ dtrace_bufdata_t *bufdata;
118
+ VALUE v;
119
+
120
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
121
+
122
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY)
123
+ v = rb_str_new2("tuple");
124
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL)
125
+ v = rb_str_new2("value");
126
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGLAST)
127
+ v = rb_str_new2("last");
128
+ else
129
+ v = rb_str_new2("unknown");
130
+
131
+ return v;
132
+ }
@@ -0,0 +1,141 @@
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 dtraceaggdata_init(VALUE self)
11
+ {
12
+ dtrace_bufdata_t *data;
13
+
14
+ Data_Get_Struct(self, dtrace_bufdata_t, data);
15
+ return self;
16
+ }
17
+
18
+ /* Returns the value of this aggregate, be it the aggregation value,
19
+ or a member of an aggregation key tuple. */
20
+ VALUE dtraceaggdata_value(VALUE self)
21
+ {
22
+ dtrace_bufdata_t *bufdata;
23
+ const dtrace_aggdata_t *aggdata;
24
+ const dtrace_aggdesc_t *aggdesc;
25
+ const dtrace_recdesc_t *rec;
26
+ const char *s;
27
+ dtrace_actkind_t act = DTRACEACT_NONE;
28
+ int64_t aggid;
29
+ uint64_t normal;
30
+ caddr_t addr;
31
+ int64_t value;
32
+ VALUE v = Qnil;
33
+
34
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
35
+ aggdata = bufdata->dtbda_aggdata;
36
+ s = bufdata->dtbda_buffered;
37
+ rec = bufdata->dtbda_recdesc;
38
+
39
+ if (aggdata == NULL) {
40
+ rb_raise(eDTraceException, "null aggdata");
41
+ return Qnil;
42
+ }
43
+
44
+ aggdesc = aggdata->dtada_desc;
45
+
46
+ if (aggdesc == NULL) {
47
+ rb_raise(eDTraceException, "null aggdesc");
48
+ return Qnil;
49
+ }
50
+
51
+ aggid = *((int64_t *)(aggdata->dtada_data +
52
+ aggdesc->dtagd_rec[0].dtrd_offset));
53
+ if (aggid < 0) {
54
+ rb_raise(eDTraceException, "negative aggregation ID");
55
+ return Qnil;
56
+ }
57
+
58
+ act = rec->dtrd_action;
59
+
60
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY) {
61
+
62
+ switch (act) {
63
+ case DTRACEACT_STACK:
64
+ case DTRACEACT_USTACK:
65
+ case DTRACEACT_JSTACK:
66
+ /* todo */
67
+ break;
68
+ case DTRACEACT_USYM:
69
+ case DTRACEACT_UADDR:
70
+ case DTRACEACT_UMOD:
71
+ case DTRACEACT_SYM:
72
+ case DTRACEACT_MOD:
73
+ /* todo */
74
+ break;
75
+ default:
76
+ v = handle_bytedata((aggdata->dtada_data + rec->dtrd_offset), rec->dtrd_size);
77
+ }
78
+
79
+
80
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
81
+
82
+ normal = aggdata->dtada_normal;
83
+ addr = aggdata->dtada_data + rec->dtrd_offset;
84
+
85
+ if (act == DTRACEAGG_AVG) {
86
+ uint64_t *data = (uint64_t *)addr;
87
+ value = (data[0] ? (long long)(data[1] / normal / data[0]) : 0);
88
+ } else {
89
+ value = (*((int64_t *)addr)) / normal;
90
+ }
91
+
92
+ if (act == DTRACEAGG_QUANTIZE || act == DTRACEAGG_LQUANTIZE) {
93
+ v = Qnil; // dtj_new_distribution(data, rec, jc);
94
+ } else {
95
+ switch (act) {
96
+ case DTRACEAGG_COUNT:
97
+ if (value < 0)
98
+ rb_raise(eDTraceException, "count value is negative");
99
+ v = LL2NUM(value);
100
+ break;
101
+ case DTRACEAGG_AVG:
102
+ case DTRACEAGG_MIN:
103
+ case DTRACEAGG_MAX:
104
+ case DTRACEAGG_SUM:
105
+ v = LL2NUM(value);
106
+ break;
107
+ default:
108
+ v = Qnil;
109
+ rb_raise(eDTraceException, "unexpected aggregation action: %d", act);
110
+ }
111
+ }
112
+
113
+ } else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL) {
114
+
115
+ v = Qnil;
116
+
117
+ }
118
+
119
+ return v;
120
+ }
121
+
122
+ /* Return the type of this DTraceAggData: tuple, value or last. Used
123
+ to form tuples and values into DTraceAggregate objects. */
124
+ VALUE dtraceaggdata_aggtype(VALUE self)
125
+ {
126
+ dtrace_bufdata_t *bufdata;
127
+ VALUE v;
128
+
129
+ Data_Get_Struct(self, dtrace_bufdata_t, bufdata);
130
+
131
+ if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGKEY)
132
+ v = rb_str_new2("tuple");
133
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGVAL)
134
+ v = rb_str_new2("value");
135
+ else if (bufdata->dtbda_flags & DTRACE_BUFDATA_AGGLAST)
136
+ v = rb_str_new2("last");
137
+ else
138
+ v = rb_str_new2("unknown");
139
+
140
+ return v;
141
+ }