Skip to content

Hi! I cleaned up your code for you! #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

== 0.2.8 / 2009-07-23

* Replace string-eval provider class creation
* Replace string-eval provider class creation
* Fix GC bug with DOF data on Mac OSX (reported by [email protected])
* Add each_probe_prog method to list probes enabled by a program
* Fix conversion of 64 bit values in probe data (reported by [email protected])
Expand All @@ -22,7 +22,7 @@

== 0.2.5 / 2008-06-14

* Rework Dtrace::Provider to directly create USDT providers by
* Rework Dtrace::Provider to directly create USDT providers by
generating DOF and stub functions.

== 0.0.6 / 2008-02-17
Expand All @@ -32,7 +32,7 @@

== 0.0.5 / 2008-01-24

* Add DtraceErrData and DtraceDropData for access to error
* Add DtraceErrData and DtraceDropData for access to error
and drop information
* Fix interaction with Ruby's GC

Expand All @@ -43,8 +43,8 @@
== 0.0.3 / 2008-01-06

* Add a DtraceData class which consumers return, containing
the data returned from each probe firing, rather than
returning the raw records directly from DTrace.
the data returned from each probe firing, rather than
returning the raw records directly from DTrace.
* Provide access to probe, CPU and flow information.
* Allow creation and grabbing of processes.
* Add an example script: a port of scsi.d.
Expand Down
12 changes: 6 additions & 6 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fork the repository on Github: http://github.com/chrisa/ruby-dtrace
Rubyforge mailing list: http://rubyforge.org/mailman/listinfo/ruby-dtrace-users

== FEATURES

Consumer:

* Access to the D API
Expand All @@ -29,15 +29,15 @@ Consumer: see Dtrace

require 'Dtrace'

t = Dtrace.new
t = Dtrace.new
progtext = 'ruby$1:::function-entry{ @a[strjoin(strjoin(copyinstr(arg0),"."),copyinstr(arg1))] = count(); } END { printa(@a); }'
prog = t.compile progtext
prog.execute

t.go

[...]

c = DtraceConsumer.new(t)
c.consume_once do |rec|
# handle records
Expand All @@ -54,11 +54,11 @@ Probes: see Dtrace::Provider

Dtrace::Probe::Rubyprog.foo do |p|
p.fire('fired!', 'again')
end
end

Dtrace::Probe::Rubyprog.bar do |p|
p.fire(42, 27)
end
end

== REQUIREMENTS

Expand All @@ -68,7 +68,7 @@ Probes: see Dtrace::Provider
* For the probe API, a platform with DTrace support (as for the
consumer API), with a 32 bit or 64 bit Ruby build - i386/x86_64,
PowerPC (for OS X) and SPARC (for Solaris) are all supported.

* root, or some/all of the dtrace privileges on Solaris: dtrace_user,
dtrace_proc and dtrace_kernel.

Expand Down
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task :extensions do
system("make")
Dir.chdir('dof')
system("ruby extconf.rb")
system("make")
system("make")
Dir.chdir('../..')
end

Expand All @@ -26,42 +26,42 @@ task :clean_extensions do
Dir.chdir('ext')
system("make clean")
Dir.chdir('dof')
system("make clean")
system("make clean")
Dir.chdir('../..')
end

PKG_NAME = "ruby-dtrace"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_VERSION = Dtrace::VERSION + PKG_BUILD
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"

desc "Default task"
task :default => [ :test ]

desc "Build documentation"
task :doc => [ :rdoc ]

Rake::TestTask.new do |t|
t.libs << "ext:lib"
t.test_files = Dir["test/*.rb"]
t.verbose = true
end

desc "Run code-coverage analysis using rcov"
task :coverage do
rm_rf "coverage"
files = Dir["test/*.rb"]
system "rcov --sort coverage -Iext:lib #{files.join(' ')}"
end

GEM_SPEC = eval(File.read("#{File.dirname(__FILE__)}/#{PKG_NAME}.gemspec"))

Rake::GemPackageTask.new(GEM_SPEC) do |p|
p.gem_spec = GEM_SPEC
p.need_tar = true
p.need_zip = true
end

desc "Build the RDoc API documentation"
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = "doc"
Expand Down
4 changes: 2 additions & 2 deletions ext/dof/constants.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/

#include "dof.h"

void
void
_init_constants(VALUE dtrace_dof)
{
VALUE c = rb_define_module_under(dtrace_dof, "Constants");
Expand Down
2 changes: 1 addition & 1 deletion ext/dof/dof.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down
4 changes: 2 additions & 2 deletions ext/dof/dof_api.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand All @@ -17,7 +17,7 @@ void Init_dof_api() {
VALUE dof = rb_define_class_under(dtrace, "Dof", rb_cObject);

rb_define_singleton_method(dof, "loaddof", dof_loaddof, 2); // in dof_helper.c

eDtraceDofException = rb_define_class_under(dof, "Exception", rb_eStandardError);

cDtraceDofParser = rb_define_class_under(dof, "Parser", rb_cObject);
Expand Down
6 changes: 3 additions & 3 deletions ext/dof/dof_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int _loaddof(int fd, dof_helper_t *dh)

user_addr_t val = (user_addr_t)(unsigned long)ioctlData;
ret = ioctl(fd, DTRACEHIOC_ADDDOF, &val);

return ret;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ VALUE dof_loaddof(VALUE self, VALUE dof_file, VALUE module_name)
(void) snprintf(dh.dofhp_mod, sizeof (dh.dofhp_mod), RSTRING(module_name)->ptr);

if ((fd = open(helper, O_RDWR)) < 0) {
rb_raise(eDtraceDofException, "failed to open helper device %s: %s",
rb_raise(eDtraceDofException, "failed to open helper device %s: %s",
helper, strerror(errno));
return Qnil;
}
Expand All @@ -79,4 +79,4 @@ VALUE dof_loaddof(VALUE self, VALUE dof_file, VALUE module_name)

return Qnil;
}

8 changes: 4 additions & 4 deletions ext/dof/file.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down Expand Up @@ -31,7 +31,7 @@ VALUE dof_file_alloc(VALUE klass)
file->dof = NULL;
file->len = 0;
file->offset = 0;

obj = Data_Wrap_Struct(klass, NULL, dof_file_free, file);
return obj;
}
Expand Down Expand Up @@ -63,7 +63,7 @@ VALUE dof_file_append(VALUE self, VALUE data)
(file->offset + RSTRING(data)->len), file->len);
return Qnil;
}

memcpy((file->dof + file->offset), RSTRING(data)->ptr, RSTRING(data)->len);
file->offset += RSTRING(data)->len;
}
Expand All @@ -86,5 +86,5 @@ VALUE dof_file_data(VALUE self)
dof_file_t *file;
Data_Get_Struct(self, dof_file_t, file);
return rb_str_new(file->dof, file->offset);
}
}

2 changes: 1 addition & 1 deletion ext/dof/generator.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down
14 changes: 7 additions & 7 deletions ext/dof/header.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down Expand Up @@ -35,9 +35,9 @@ VALUE dof_generate_header(VALUE self) {
dof_version = DOF_VERSION;
}
#endif

memset(&hdr, 0, sizeof(hdr));

hdr.dofh_ident[DOF_ID_MAG0] = DOF_MAG_MAG0;
hdr.dofh_ident[DOF_ID_MAG1] = DOF_MAG_MAG1;
hdr.dofh_ident[DOF_ID_MAG2] = DOF_MAG_MAG2;
Expand All @@ -49,16 +49,16 @@ VALUE dof_generate_header(VALUE self) {
hdr.dofh_ident[DOF_ID_DIFVERS] = DIF_VERSION;
hdr.dofh_ident[DOF_ID_DIFIREG] = DIF_DIR_NREGS;
hdr.dofh_ident[DOF_ID_DIFTREG] = DIF_DTR_NREGS;

hdr.dofh_hdrsize = sizeof(dof_hdr_t);
hdr.dofh_secsize = sizeof(dof_sec_t);

secnum = FIX2INT(rb_iv_get(self, "@secnum"));
hdr.dofh_secnum = secnum;

hdr.dofh_loadsz = FIX2INT(rb_iv_get(self, "@loadsz"));
hdr.dofh_filesz = FIX2INT(rb_iv_get(self, "@filesz"));

hdrlen = (sizeof(dof_hdr_t) + secnum * sizeof(dof_sec_t));
rb_iv_set(self, "@hdrlen", INT2FIX(hdrlen));
hdr.dofh_secoff = sizeof(dof_hdr_t);
Expand All @@ -74,6 +74,6 @@ VALUE dof_header_len(VALUE self) {

secnum = FIX2INT(rb_iv_get(self, "@secnum"));
hdrlen = (sizeof(dof_hdr_t) + secnum * sizeof(dof_sec_t));

return INT2FIX(hdrlen);
}
22 changes: 11 additions & 11 deletions ext/dof/parser.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down Expand Up @@ -104,13 +104,13 @@ _dof_parse_string_table(VALUE self, char *dof, dof_sec_t *sec)
VALUE strtab = rb_hash_new();
VALUE ctx = rb_cv_get(self, "@@ctx");
int i, bool = 0;

for (i = 0; i < sec->dofs_size - 1; ++i) {
if (*data) {
if (bool)
rb_hash_aset(strtab, INT2FIX(i), rb_str_new2(data));
bool = 0;
}
}
else if (!bool) {
bool = 1;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ _dof_parse_dof_relodesc_t_array(VALUE self, char *dof, dof_sec_t *sec)

relodesc_data = rb_hash_new();
rb_hash_aset(relodesc_data, ID2SYM(rb_intern("name")), rb_hash_aref(strtab, INT2FIX(relodesc.dofr_name)));

switch(relodesc.dofr_type) {
case DOF_RELO_NONE:
rb_hash_aset(relodesc_data, ID2SYM(rb_intern("type")), rb_str_new2("none"));
Expand All @@ -197,7 +197,7 @@ _dof_parse_dof_relodesc_t_array(VALUE self, char *dof, dof_sec_t *sec)
rb_hash_aset(relodesc_data, ID2SYM(rb_intern("type")), rb_str_new2("unknown"));
break;
}

rb_hash_aset(relodesc_data, ID2SYM(rb_intern("offset")), INT2FIX(relodesc.dofr_offset));
rb_hash_aset(relodesc_data, ID2SYM(rb_intern("data")), INT2FIX(relodesc.dofr_data));

Expand Down Expand Up @@ -231,7 +231,7 @@ _dof_parse_dof_attr_t(dof_attr_t attr)
rb_hash_aset(attr_data, ID2SYM(rb_intern("name")), INT2FIX(DOF_ATTR_NAME(attr)));
rb_hash_aset(attr_data, ID2SYM(rb_intern("data")), INT2FIX(DOF_ATTR_DATA(attr)));
rb_hash_aset(attr_data, ID2SYM(rb_intern("class")), INT2FIX(DOF_ATTR_CLASS(attr)));

return attr_data;
}

Expand Down Expand Up @@ -312,7 +312,7 @@ _dof_parse_utsname(VALUE self, char *dof, dof_sec_t *sec)
char *data = (char *)(dof + sec->dofs_offset);

memcpy(&uts, data, sizeof(uts));

rb_hash_aset(uts_data, ID2SYM(rb_intern("sysname")), rb_str_new2(uts.sysname));
rb_hash_aset(uts_data, ID2SYM(rb_intern("nodename")), rb_str_new2(uts.nodename));
rb_hash_aset(uts_data, ID2SYM(rb_intern("release")), rb_str_new2(uts.release));
Expand Down Expand Up @@ -358,9 +358,9 @@ VALUE dof_parse(VALUE self, VALUE rdof)
return Qnil;
}
pos += dof_hdr.dofh_hdrsize;

dof_data = rb_ary_new();

/* Walk section headers, parsing sections */
for (i = 0; i < dof_hdr.dofh_secnum; i++) {
memcpy(&dof_sec, pos, sizeof(struct dof_sec));
Expand Down Expand Up @@ -396,10 +396,10 @@ VALUE dof_parse(VALUE self, VALUE rdof)
break;
case DOF_SECT_UTSNAME:
sec = _dof_parse_utsname(self, dof, &dof_sec);
break;
break;
case DOF_SECT_COMMENTS:
sec = _dof_parse_comments(self, dof, &dof_sec);
break;
break;
default:
sec = _dof_parse_unknown(self, dof, &dof_sec);
break;
Expand Down
2 changes: 1 addition & 1 deletion ext/dof/parser.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Ruby-Dtrace
* (c) 2008 Chris Andrews <[email protected]>
*/
Expand Down
Loading