-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate & concatenate dtrace hooks.
This removes the need to manually escape every newline when defining hook macros for DTrace/Systemtap. This in turn makes them quite a bit easier to read. Using this setup is quite simple: dump a header file in vm/dtrace/hooks (using .h as the extension) and it will be concatenated into vm/dtrace/hooks.h. That header is in turn included into vm/dtrace/dtrace.h. This commit also moves the dummy METHOD_HOOK macro into probes_dummy.h. There's no particular reason to keep it in dtrace.h.
Yorick Peterse
committed
Nov 6, 2014
1 parent
b92254d
commit 436005a
Showing
7 changed files
with
109 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# C header file generated that automatically escaped newlines. This is meant to | ||
# process header files containing DTrace related macros, removing the need to | ||
# manually escape every newline in said files. | ||
class DtraceHeaderGenerator | ||
def initialize(target) | ||
@target = target | ||
end | ||
|
||
# Processes the given header files and saves the resulting header as the file | ||
# specified in @target. | ||
def generate(headers) | ||
contents = '' | ||
|
||
headers.each do |header_file| | ||
File.open(header_file, 'r') do |handle| | ||
handle.each_line do |line| | ||
contents << "#{line.chomp} \\\n" | ||
end | ||
end | ||
|
||
contents << "\n" | ||
end | ||
|
||
File.open(@target, 'w') do |handle| | ||
handle.write <<-EOF.strip | ||
#ifndef RUBINIUS_DTRACE_HOOKS_H | ||
#define RUBINIUS_DTRACE_HOOKS_H | ||
#{contents} | ||
#endif | ||
EOF | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#define RUBINIUS_METHOD_HOOK(probe, state, mod, method, previous) | ||
{ | ||
if(RUBINIUS_METHOD_##probe##_ENABLED()) { | ||
RBX_DTRACE_CONST char* module_name = | ||
const_cast<RBX_DTRACE_CONST char*>(mod->debug_str(state).c_str()); | ||
|
||
RBX_DTRACE_CONST char* code_name = | ||
const_cast<RBX_DTRACE_CONST char*>(method->debug_str(state).c_str()); | ||
|
||
RBX_DTRACE_CONST char* file_name = | ||
const_cast<RBX_DTRACE_CONST char*>("<unknown>"); | ||
|
||
int line = 0; | ||
|
||
if(previous) { | ||
Symbol* file = previous->file(state); | ||
|
||
if(!file->nil_p()) { | ||
file_name = const_cast<RBX_DTRACE_CONST char*>(file->debug_str(state).c_str()); | ||
} | ||
|
||
line = previous->line(state); | ||
} | ||
|
||
RUBINIUS_METHOD_##probe(module_name, code_name, file_name, line); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#define RUBINIUS_OBJECT_ALLOCATE_HOOK(state, obj, frame) | ||
{ | ||
if(RUBINIUS_OBJECT_ALLOCATE_ENABLED()) { | ||
Class* mod = obj->direct_class(state); | ||
|
||
RBX_DTRACE_CONST char* module_name = | ||
const_cast<RBX_DTRACE_CONST char*>(mod->debug_str(state).c_str()); | ||
|
||
RBX_DTRACE_CONST char* file_name = | ||
const_cast<RBX_DTRACE_CONST char *>("<unknown>"); | ||
|
||
int line = 0; | ||
|
||
if(frame) { | ||
Symbol* file = frame->file(state); | ||
|
||
if(!file->nil_p()) { | ||
file_name = const_cast<RBX_DTRACE_CONST char*>(file->debug_str(state).c_str()); | ||
} | ||
|
||
line = frame->line(state); | ||
} | ||
|
||
RUBINIUS_OBJECT_ALLOCATE(module_name, file_name, line); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters