Skip to content

Commit

Permalink
Major overhaul: MRI C AST -> YAML function defs -> probes
Browse files Browse the repository at this point in the history
  • Loading branch information
methodmissing committed May 3, 2009
1 parent 8b3e59e commit e8138b2
Show file tree
Hide file tree
Showing 142 changed files with 8,425 additions and 203 deletions.
7 changes: 7 additions & 0 deletions bin/parse
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'instrumentation'

Mri::Instrumentation::Parser.probes!( ARGV.first || '/Users/lourens/projects/matzruby' )
20 changes: 20 additions & 0 deletions config/18/files.yml
@@ -0,0 +1,20 @@
---
- 'array.c'
- 'io.c'
- 'st.c'
- 'lex.c'
- 'util.c'
- 'process.c'
- 're.c'
- 'time.c'
- 'compar.c'
- 'random.c'
- 'bignum.c'
- 'dir.c'
- 'prec.c'
- 'struct.c'
- 'math.c'
- 'range.c'
- 'file.c'
- 'numeric.c'
- 'signal.c'
16 changes: 16 additions & 0 deletions config/18/ignores.yml
@@ -0,0 +1,16 @@
---
- rb_class_of
- rb_type
- rb_special_const_p
- memfill
- rb_ary_modify_check
- rb_ary_elt
- bigfixize
- bracket
- do_stat
- do_opendir
- has_magic
- find_dirsep
- remove_backslashes
- glob_make_pattern
- rb_glob2
Empty file added config/18/include/Aliases.h
Empty file.
Empty file.
Empty file added config/18/include/TextUtils.h
Empty file.
Empty file added config/18/include/_structs.h
Empty file.
Empty file added config/18/include/_types.h
Empty file.
Empty file added config/18/include/alloca.h
Empty file.
Empty file added config/18/include/ar.h
Empty file.
Empty file added config/18/include/available.h
Empty file.
Empty file added config/18/include/crt_externs.h
Empty file.
Empty file added config/18/include/ctype.h
Empty file.
Empty file added config/18/include/direct.h
Empty file.
Empty file added config/18/include/dirent.h
Empty file.
Empty file added config/18/include/dlfnc.h
Empty file.
Empty file added config/18/include/errno.h
Empty file.
Empty file added config/18/include/fcntl.h
Empty file.
Empty file added config/18/include/grp.h
Empty file.
Empty file added config/18/include/intrinsics.h
Empty file.
Empty file added config/18/include/limits.h
Empty file.
Empty file added config/18/include/link.h
Empty file.
Empty file.
Empty file.
Empty file added config/18/include/math.h
Empty file.
Empty file added config/18/include/ndir.h
Empty file.
Empty file added config/18/include/net/socket.h
Empty file.
Empty file added config/18/include/nlist.h
Empty file.
Empty file added config/18/include/process.h
Empty file.
Empty file added config/18/include/pwd.h
Empty file.
Empty file added config/18/include/ruby.h
Empty file.
Empty file added config/18/include/ruby/config.h
Empty file.
Empty file.
Empty file added config/18/include/ruby/dln.h
Empty file.
Empty file added config/18/include/ruby/env.h
Empty file.
Empty file added config/18/include/ruby/intern.h
Empty file.
Empty file.
Empty file added config/18/include/ruby/node.h
Empty file.
Empty file added config/18/include/ruby/re.h
Empty file.
Empty file added config/18/include/ruby/regex.h
Empty file.
Empty file added config/18/include/ruby/ruby.h
Empty file.
Empty file added config/18/include/ruby/rubyio.h
Empty file.
Empty file.
Empty file added config/18/include/ruby/st.h
Empty file.
Empty file added config/18/include/ruby/util.h
Empty file.
Empty file added config/18/include/setjmp.h
Empty file.
Empty file added config/18/include/signal.h
Empty file.
Empty file added config/18/include/st.h
Empty file.
Empty file added config/18/include/stdarg.h
Empty file.
Empty file added config/18/include/stddef.h
Empty file.
Empty file added config/18/include/stdio.h
Empty file.
Empty file added config/18/include/stdlib.h
Empty file.
Empty file added config/18/include/string.h
Empty file.
Empty file added config/18/include/strings.h
Empty file.
Empty file added config/18/include/sys/_select.h
Empty file.
Empty file.
Empty file added config/18/include/sys/_types.h
Empty file.
Empty file added config/18/include/sys/cdefs.h
Empty file.
Empty file added config/18/include/sys/cygwin.h
Empty file.
Empty file added config/18/include/sys/dir.h
Empty file.
Empty file added config/18/include/sys/file.h
Empty file.
Empty file added config/18/include/sys/ioctl.h
Empty file.
Empty file added config/18/include/sys/mkdev.h
Empty file.
Empty file added config/18/include/sys/ndir.h
Empty file.
Empty file added config/18/include/sys/param.h
Empty file.
Empty file.
Empty file added config/18/include/sys/select.h
Empty file.
Empty file added config/18/include/sys/stat.h
Empty file.
Empty file added config/18/include/sys/syscall.h
Empty file.
Empty file.
Empty file added config/18/include/sys/time.h
Empty file.
Empty file added config/18/include/sys/times.h
Empty file.
Empty file added config/18/include/sys/types.h
Empty file.
Empty file added config/18/include/sys/utime.h
Empty file.
Empty file added config/18/include/sys/wait.h
Empty file.
Empty file added config/18/include/syscall.h
Empty file.
Empty file added config/18/include/time.h
Empty file.
Empty file added config/18/include/unistd.h
Empty file.
Empty file added config/18/include/unix.h
Empty file.
Empty file added config/18/include/util.h
Empty file.
Empty file added config/18/include/utime.h
Empty file.
Empty file added config/18/include/varargs.h
Empty file.
1 change: 1 addition & 0 deletions config/18/macros.yml
@@ -0,0 +1 @@
--- {}
142 changes: 142 additions & 0 deletions config/18/types.yml
@@ -0,0 +1,142 @@
---
- 'FILE64'
- 'fd_set'
- 'st_table_entry'
- 'rb_atomic_t'
- 'pointer'
- 'hdr'
- 'C_block'
- 'sFILE'
- 'stack_node'
- 'U'
- 'Bigint'
- 'unsigned_time_t'
- 'VALUE'
- 'ID'
- 'RUBY_DATA_FUNC'
- 'ruby_glob_func'
- 'rb_nativethread_t'
- 'mbc_startpos_func_t'
- 'conftest_type'
- 'Regexp'
- 'pid_t'
- 'sigset_t'
- 'regex_t'
- 're_pattern_buffer'
- 'regoff_t'
- 'regmatch_t'
- 'Real'
- 'uint8_t'
- 'uint32_t'
- 'uint64_t'
- 'rb_digest_hash_init_func_t'
- 'rb_digest_hash_update_funct_t'
- 'rb_digest_hash_finish_funct_t'
- 'MD5_CTX'
- 'RMD160_CTX'
- 'CHAR64LONG16'
- 'SHA1_CTX'
- 'sha2_byte'
- 'sha2_word32'
- 'sha2_word64'
- 'SHA256_CTX'
- 'SHA512_CTX'
- 'SHA384_CTX'
- 's_voidp'
- 's_short'
- 's_int'
- 's_long'
- 's_float'
- 's_double'
- 'freefunc_t'
- 'ANY_TYPE'
- 'callback1_t'
- 'nkf_char'
- 'bfk_nfchar'
- 'conftest_type'
- 'd2i_of_void'
- 'ossl_asn1_info_t'
- 'DBM'
- 'FILE'
- 'datum'
- 'YYSTYPE'
- 'yysigned_char'
- 'bytestring_t'
- 'SyckNode'
- 'SyckParser'
- 'SyckIoFile'
- 'SyckIoStr'
- 'SyckLevel'
- 'SyckNodeHandler'
- 'SyckErrorHandler'
- 'SyckBadAnchorHandler'
- 'SyckIoFileRead'
- 'SyckIoStrRead'
- 'SyckEmitter'
- 'SyckEmitterNode'
- 'SyckOutputHandler'
- 'SyckEmitterHandler'
- 'bytestring_t'
- 'yamlbyte_utf8_t'
- 'yamlbyte_utf16_t'
- 'yamlbyte_char_t'
- 'yamlbyte_consumer_t'
- 'yamlbyte_producer_t'
- 'yamlbyte_result_t'
- 'yamlbyte_buff_t'
- 'yamlbyte_inst_t'
- 'yamlbyte_pull_t'
- 'yamlbyte_pushbuff_t'
- 'yamlbyte_pullbuff_t'
- 'Entry'
- 'List'
- 'Mutexv'
- 'ConditionVariable'
- 'legacy_wait_args'
- 'Queue'
- 'DL_HANDLE'
- 'CallFrame'
- 'DummyInterp'
- 'time_t'
- '_fsize_t'
- 'intptr_t'
- 'SIGHANDLER'
- 'sighandler_t'
- 'dev_t'
- 'ino_t'
- 'mode_t'
- 'clock_t'
- 'ptrdiff_t'
- 'off_t'
- 'u_char'
- 'u_short'
- 'caddr_t'
- 'transitionTime'
- 'va_list'
- 'mbc_startpos_func_t'
- 'DIR'
- 'sighandler_t'
- 'NODE'
- 'rb_event_t'
- 'rb_event_hook_func_t'
- 'rb_jmpbuf_t'
- 'rb_thread_t'
- 'event_hook'
- 'foobazzz'
- 'DWORD'
- 'size_t'
- 'USTR'
- 'RVALUE'
- '__uint16_t'
- '__int32_t'
- '__uint32_t'
- 'uid_t'
- 'gid_t'
- 'blkcnt_t'
- 'blksize_t'
- '__int64_t'
- 'nlink_t'
- 'stack_type'
- 'st_data_t'
- 'st_table'
- 'BDIGITv
10 changes: 9 additions & 1 deletion lib/instrumentation.rb
Expand Up @@ -9,12 +9,19 @@ module Instrumentation

MRI_VERSION = RUBY_VERSION.gsub('.','')[0..1]

PROBES = File.join( File.dirname( __FILE__ ), '..', 'probes', MRI_VERSION ).freeze
DIRECTORY = File.expand_path( File.join( File.dirname( __FILE__ ), '..' ) )

PROBES = File.join( DIRECTORY, 'probes', MRI_VERSION ).freeze

CONFIG = File.join( DIRECTORY, 'config', MRI_VERSION ).freeze

EXTENSIONS = File.join( DIRECTORY, 'lib', 'mri', 'instrumentation', 'extensions' ).freeze

autoload :Definition, 'mri/instrumentation/definition'
autoload :Probe, 'mri/instrumentation/probe'
autoload :Argument, 'mri/instrumentation/argument'
autoload :ProbeCollection, 'mri/instrumentation/probe_collection'
autoload :Parser, 'mri/instrumentation/parser'

module Strategy

Expand All @@ -26,6 +33,7 @@ module Strategy
autoload :Calls, 'mri/instrumentation/strategy/calls'
autoload :Speculate, 'mri/instrumentation/strategy/speculate'
autoload :Peek, 'mri/instrumentation/strategy/peek'
autoload :Stack, 'mri/instrumentation/strategy/stack'

end

Expand Down
88 changes: 79 additions & 9 deletions lib/mri/instrumentation/argument.rb
Expand Up @@ -2,6 +2,9 @@ module Mri
module Instrumentation
class Argument < Struct.new(:type, :description, :order)

class TypeNotDefined < StandardError
end

class << self

# Yields the default probe argument
Expand All @@ -16,22 +19,76 @@ def probe
# and integers.
#

TYPES = { :char => ['copyinstr( %s )', '%s'],
:pointer => ['%s', '%#p'],
:int => ['stringof( %s )', '%s'],
:probe => ['%s', '%s'] }
TYPES = { 'VALUE' => ['%s', 'stringof(%d)'],
'VALUE *' => ['%s', '%s'],
'long int' => ['%s', 'stringof(%d)'],
'void' => ['%s', '%s'],
'int' => ['%s', 'stringof(%d)'],
'struct inspect_arg *' => ['%s', '%s'],
'VALUE (*)()' => ['%s', '%s'],
'struct ary_sort_data *' => ['%s', '%s'],
'VALUE (*)(VALUE, long int)' => ['%s', '%s'],
'void *' => ['%s', '%s'],
'struct st_hash_type *' => ['%s', '%s'],
'st_table' => ['%s', '%s'],
'st_table *' => ['%s', '%s'],
'st_data_t' => ['%s', '%s'],
'st_data_t *' => ['%s', '%s'],
'int (*)()' => ['%s', 'stringof(%d)'],
'const char *' => ['%s', '%s'],
'unsigned long int' => ['%s', 'stringof(%d)'],
'char *' => ['%s', '%s'],
'unsigned long long int' => ['%s', 'stringof(%d)'],
'long long int' => ['%s', 'stringof(%d)'],
'double' => ['%s', 'stringof(%d)'],
'double *' => ['%s', 'stringof(%d)'],
'const char **' => ['%s', '%s'],
'struct dir_data *' => ['%s', '%s'],
'struct chdir_data *' => ['%s', '%s'],
'struct stat *' => ['%s', '%s'],
'DIR *' => ['%s', '%s'],
'struct glob_pattern *' => ['%s', '%s'],
'enum answer' => ['%s', '%s'],
'ruby_glob_func *' => ['%s', '%s'],
'void (*)(const char *, VALUE)' => ['%s', '%s'],
'gid_t' => ['%s', '%s'],
'OpenFile *' => ['%s', '%s'],
'FILE *' => ['%s', '%s'],
'ID' => ['%s', 'stringof(%d)'],
'struct foreach_arg *' => ['%s', '%s'],
'struct kwtable *' => ['%s', '%s'],
:probe => ['%s', '%s']
}

# Hash representation
#
def to_hash
{ self.type => self.description }
end

# YAML representation
#
def to_yaml( opts = {} )
to_hash.to_yaml
end

# Type lookup accessor
#
def lookup
TYPES[self.type] || raise( TypeNotDefined, "type not defined #{self.type.inspect}" )
end

# Format helper for D's printf
#
def to_format
@format ||= TYPES[self.type.to_sym].last
@format ||= lookup.last
end

# Massage into a format D can easily work with.
# Standardized on everything being a string, for the time being.
#
def massage
@massage ||= TYPES[self.type.to_sym].first % to_arg
@massage ||= lookup.first % to_var( '_copy' )
end

# String representation as description
Expand All @@ -42,14 +99,21 @@ def to_s

# Function variable
#
def to_var
@to_var ||= probe? ? "this->type" : "this->#{to_arg}"
def to_var( suffix = '' )
@to_var ||= {}
@to_var[suffix] ||= probe? ? "self->type#{suffix}" : "self->#{to_arg}#{suffix}"
end

# Function variable assignment
#
def to_assignment
@to_assignment ||= "#{to_var} = #{massage};"
@to_assignment ||= default_assignment #init_assignment
end

# Copy argument to a thread local ( pointers )
#
def to_copy
@to_copy ||= "#{to_var( '_copy' )} = #{to_arg};"
end

# Argument representation.
Expand All @@ -64,6 +128,12 @@ def probe?
self.order == -1
end

private

def default_assignment
"#{to_var} = #{massage};"
end

end
end
end
19 changes: 11 additions & 8 deletions lib/mri/instrumentation/definition.rb
Expand Up @@ -33,12 +33,15 @@ def setup_group
# Setup all probes
#
def setup_probes
read.each_pair do |probe, definition|
@probes << setup_probe( probe,
safe_definition( definition, "desc" ),
safe_definition( definition, "args" ),
safe_definition( definition, "return" ) )
end
read.each do |probe|
probe.each_pair do |probe, definition|
@probes << setup_probe( probe,
safe_definition( definition, "desc" ),
safe_definition( definition, "arguments" ),
safe_definition( definition, "return" ),
safe_definition( definition, "storage" ) )
end
end
end

# Don't assume all argument and return definitions is given
Expand All @@ -49,8 +52,8 @@ def safe_definition( definition, key )

# Setup a single probe
#
def setup_probe( probe, description, arguments, returns )
Mri::Instrumentation::Probe.new( group, probe, description, setup_arguments( arguments ), returns )
def setup_probe( probe, description, arguments, returns, storage )
Mri::Instrumentation::Probe.new( group, probe, description, setup_arguments( arguments ), returns, storage )
end

# Setup arguments for a single probe
Expand Down

0 comments on commit e8138b2

Please sign in to comment.