diff options
author | Björn Gustavsson <[email protected]> | 2012-03-21 14:26:47 +0100 |
---|---|---|
committer | Patrik Nyblom <[email protected]> | 2012-03-22 18:16:16 +0100 |
commit | 1e653c3539423e4cfdeab1d232483bcac0e8b073 (patch) | |
tree | 72526f18a3bee00399972b09912e11322023d48c | |
parent | 848f6e541f779e13f7d99bbd0c99ac37a9bd56e8 (diff) | |
download | otp-1e653c3539423e4cfdeab1d232483bcac0e8b073.tar.gz otp-1e653c3539423e4cfdeab1d232483bcac0e8b073.tar.bz2 otp-1e653c3539423e4cfdeab1d232483bcac0e8b073.zip |
Use distinct function-entry probes for local and global calls
It seems useful to be able to filter out (for example) just
the global calls.
-rw-r--r-- | erts/emulator/beam/beam_emu.c | 71 | ||||
-rw-r--r-- | erts/emulator/beam/erlang_dtrace.d | 14 | ||||
-rw-r--r-- | lib/runtime_tools/examples/function-calls.d | 10 | ||||
-rw-r--r-- | lib/runtime_tools/examples/function-calls.systemtap | 10 |
4 files changed, 69 insertions, 36 deletions
diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c index 69a3d7e81a..8b4f067b98 100644 --- a/erts/emulator/beam/beam_emu.c +++ b/erts/emulator/beam/beam_emu.c @@ -1057,14 +1057,24 @@ init_emulator(void) #ifdef USE_VM_CALL_PROBES -#define DTRACE_CALL(p, m, f, a) \ - if (DTRACE_ENABLED(function_entry)) { \ - DTRACE_CHARBUF(process_name, DTRACE_TERM_BUF_SIZE); \ - DTRACE_CHARBUF(mfa, DTRACE_TERM_BUF_SIZE); \ - int depth = STACK_START(p) - STACK_TOP(p); \ - dtrace_fun_decode(p, m, f, a, \ - process_name, mfa); \ - DTRACE3(function_entry, process_name, mfa, depth); \ +#define DTRACE_LOCAL_CALL(p, m, f, a) \ + if (DTRACE_ENABLED(local_function_entry)) { \ + DTRACE_CHARBUF(process_name, DTRACE_TERM_BUF_SIZE); \ + DTRACE_CHARBUF(mfa, DTRACE_TERM_BUF_SIZE); \ + int depth = STACK_START(p) - STACK_TOP(p); \ + dtrace_fun_decode(p, m, f, a, \ + process_name, mfa); \ + DTRACE3(local_function_entry, process_name, mfa, depth); \ + } + +#define DTRACE_GLOBAL_CALL(p, m, f, a) \ + if (DTRACE_ENABLED(global_function_entry)) { \ + DTRACE_CHARBUF(process_name, DTRACE_TERM_BUF_SIZE); \ + DTRACE_CHARBUF(mfa, DTRACE_TERM_BUF_SIZE); \ + int depth = STACK_START(p) - STACK_TOP(p); \ + dtrace_fun_decode(p, m, f, a, \ + process_name, mfa); \ + DTRACE3(global_function_entry, process_name, mfa, depth); \ } #define DTRACE_RETURN(p, m, f, a) \ @@ -1115,12 +1125,13 @@ init_emulator(void) #else /* USE_VM_PROBES */ -#define DTRACE_CALL(p, m, f, a) do {} while (0) -#define DTRACE_RETURN(p, m, f, a) do {} while (0) -#define DTRACE_BIF_ENTRY(p, m, f, a) do {} while (0) -#define DTRACE_BIF_RETURN(p, m, f, a) do {} while (0) -#define DTRACE_NIF_ENTRY(p, m, f, a) do {} while (0) -#define DTRACE_NIF_RETURN(p, m, f, a) do {} while (0) +#define DTRACE_LOCAL_CALL(p, m, f, a) do {} while (0) +#define DTRACE_GLOBAL_CALL(p, m, f, a) do {} while (0) +#define DTRACE_RETURN(p, m, f, a) do {} while (0) +#define DTRACE_BIF_ENTRY(p, m, f, a) do {} while (0) +#define DTRACE_BIF_RETURN(p, m, f, a) do {} while (0) +#define DTRACE_NIF_ENTRY(p, m, f, a) do {} while (0) +#define DTRACE_NIF_RETURN(p, m, f, a) do {} while (0) #endif /* USE_VM_PROBES */ @@ -1506,7 +1517,7 @@ void process_main(void) /* FALL THROUGH */ OpCase(i_call_only_f): { SET_I((BeamInstr *) Arg(0)); - DTRACE_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); + DTRACE_LOCAL_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); Dispatch(); } @@ -1518,7 +1529,7 @@ void process_main(void) RESTORE_CP(E); E = ADD_BYTE_OFFSET(E, Arg(1)); SET_I((BeamInstr *) Arg(0)); - DTRACE_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); + DTRACE_LOCAL_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); Dispatch(); } @@ -1530,7 +1541,7 @@ void process_main(void) OpCase(i_call_f): { SET_CP(c_p, I+2); SET_I((BeamInstr *) Arg(0)); - DTRACE_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); + DTRACE_LOCAL_CALL(c_p, (Eterm)I[-3], (Eterm)I[-2], I[-1]); Dispatch(); } @@ -1548,9 +1559,9 @@ void process_main(void) * (see lb_call_error_handler below). */ #ifdef USE_VM_CALL_PROBES - if (DTRACE_ENABLED(function_entry)) { + if (DTRACE_ENABLED(global_function_entry)) { BeamInstr* fp = (BeamInstr *) (((Export *) Arg(0))->address); - DTRACE_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); + DTRACE_GLOBAL_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); } #endif Dispatchx(); @@ -1563,9 +1574,9 @@ void process_main(void) OpCase(i_call_ext_e): SET_CP(c_p, I+2); #ifdef USE_VM_CALL_PROBES - if (DTRACE_ENABLED(function_entry)) { + if (DTRACE_ENABLED(global_function_entry)) { BeamInstr* fp = (BeamInstr *) (((Export *) Arg(0))->address); - DTRACE_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); + DTRACE_GLOBAL_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); } #endif Dispatchx(); @@ -1576,9 +1587,9 @@ void process_main(void) /* FALL THROUGH */ OpCase(i_call_ext_only_e): #ifdef USE_VM_CALL_PROBES - if (DTRACE_ENABLED(function_entry)) { + if (DTRACE_ENABLED(global_function_entry)) { BeamInstr* fp = (BeamInstr *) (((Export *) Arg(0))->address); - DTRACE_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); + DTRACE_GLOBAL_CALL(c_p, (Eterm)fp[-3], (Eterm)fp[-2], fp[-1]); } #endif Dispatchx(); @@ -6111,9 +6122,9 @@ apply(Process* p, Eterm module, Eterm function, Eterm args, Eterm* reg) } #ifdef USE_VM_CALL_PROBES - if (DTRACE_ENABLED(function_entry)) { + if (DTRACE_ENABLED(global_function_entry)) { BeamInstr *fptr = (BeamInstr *) ep->address; - DTRACE_CALL(p, (Eterm)fptr[-3], (Eterm)fptr[-2], (Uint)fptr[-1]); + DTRACE_GLOBAL_CALL(p, (Eterm)fptr[-3], (Eterm)fptr[-2], (Uint)fptr[-1]); } #endif return ep->address; @@ -6166,9 +6177,9 @@ fixed_apply(Process* p, Eterm* reg, Uint arity) } #ifdef USE_VM_CALL_PROBES - if (DTRACE_ENABLED(function_entry)) { + if (DTRACE_ENABLED(global_function_entry)) { BeamInstr *fptr = (BeamInstr *) ep->address; - DTRACE_CALL(p, (Eterm)fptr[-3], (Eterm)fptr[-2], (Uint)fptr[-1]); + DTRACE_GLOBAL_CALL(p, (Eterm)fptr[-3], (Eterm)fptr[-2], (Uint)fptr[-1]); } #endif return ep->address; @@ -6304,7 +6315,7 @@ call_fun(Process* p, /* Current process. */ actual_arity = (int) code_ptr[-1]; if (actual_arity == arity+num_free) { - DTRACE_CALL(p, (Eterm)code_ptr[-3], + DTRACE_LOCAL_CALL(p, (Eterm)code_ptr[-3], (Eterm)code_ptr[-2], code_ptr[-1]); if (num_free == 0) { @@ -6399,7 +6410,7 @@ call_fun(Process* p, /* Current process. */ actual_arity = (int) ep->code[2]; if (arity == actual_arity) { - DTRACE_CALL(p, ep->code[0], ep->code[1], (Uint)ep->code[2]); + DTRACE_GLOBAL_CALL(p, ep->code[0], ep->code[1], (Uint)ep->code[2]); return ep->address; } else { /* @@ -6475,7 +6486,7 @@ call_fun(Process* p, /* Current process. */ reg[1] = function; reg[2] = args; } - DTRACE_CALL(p, module, function, arity); + DTRACE_GLOBAL_CALL(p, module, function, arity); return ep->address; } else { badfun: diff --git a/erts/emulator/beam/erlang_dtrace.d b/erts/emulator/beam/erlang_dtrace.d index d8508426f4..587e51cb67 100644 --- a/erts/emulator/beam/erlang_dtrace.d +++ b/erts/emulator/beam/erlang_dtrace.d @@ -149,13 +149,23 @@ provider erlang { /* PID, Module, Function, Arity */ /** - * Fired whenever a user function is being called. + * Fired whenever a user function is being called locally. * * @param p the PID (string form) of the process * @param mfa the m:f/a of the function * @param depth the stack depth */ - probe function__entry(char *p, char *mfa, int depth); + probe local__function__entry(char *p, char *mfa, int depth); + + /** + * Fired whenever a user function is called externally + * (through an export entry). + * + * @param p the PID (string form) of the process + * @param mfa the m:f/a of the function + * @param depth the stack depth + */ + probe global__function__entry(char *p, char *mfa, int depth); /** * Fired whenever a user function returns. diff --git a/lib/runtime_tools/examples/function-calls.d b/lib/runtime_tools/examples/function-calls.d index 238c5211ac..3e015dc2d2 100644 --- a/lib/runtime_tools/examples/function-calls.d +++ b/lib/runtime_tools/examples/function-calls.d @@ -18,9 +18,15 @@ * %CopyrightEnd% */ -erlang*:::function-entry +erlang*:::local-function-entry { - printf("pid %s enter %s depth %d\n", + printf("pid %s enter (local) %s depth %d\n", + copyinstr(arg0), copyinstr(arg1), arg2); +} + +erlang*:::global-function-entry +{ + printf("pid %s enter (global) %s depth %d\n", copyinstr(arg0), copyinstr(arg1), arg2); } diff --git a/lib/runtime_tools/examples/function-calls.systemtap b/lib/runtime_tools/examples/function-calls.systemtap index 8fc4375135..16c9c04918 100644 --- a/lib/runtime_tools/examples/function-calls.systemtap +++ b/lib/runtime_tools/examples/function-calls.systemtap @@ -28,9 +28,15 @@ * environment. */ -probe process("beam").mark("function-entry") +probe process("beam").mark("local-function-entry") { - printf("pid %s enter %s depth %d\n", + printf("pid %s enter (local) %s depth %d\n", + user_string($arg1), user_string($arg2), $arg3); +} + +probe process("beam").mark("global-function-entry") +{ + printf("pid %s enter (global) %s depth %d\n", user_string($arg1), user_string($arg2), $arg3); } |