Skip to content

Commit 6c2ecc1

Browse files
committed
Add bpftrace fallback for dtrace tests
1 parent 1173f80 commit 6c2ecc1

19 files changed

+357
-4
lines changed

Doc/howto/instrumentation.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ Available static markers
298298

299299
The arguments are the same as for :c:func:`function__entry`
300300

301+
.. object:: cfunction__entry(str modulename, str funcname)
302+
303+
This marker indicates that execution of a built-in or extension function has
304+
begun. The module name and function name are provided as C strings. The
305+
module name may be empty when the function is not associated with a
306+
particular module.
307+
308+
.. object:: cfunction__return(str modulename, str funcname)
309+
310+
This marker is the converse of :c:func:`cfunction__entry`, and indicates that
311+
execution of a built-in or extension function has ended. The arguments are
312+
the same as for :c:func:`cfunction__entry`.
313+
301314
.. object:: line(str filename, str funcname, int lineno)
302315

303316
This marker indicates a Python line is about to be executed. It is

Include/pydtrace.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
provider python {
44
probe function__entry(const char *, const char *, int);
55
probe function__return(const char *, const char *, int);
6+
probe cfunction__entry(const char *, const char *);
7+
probe cfunction__return(const char *, const char *);
68
probe instance__new__start(const char *, const char *);
79
probe instance__new__done(const char *, const char *);
810
probe instance__delete__start(const char *, const char *);

Include/pydtrace.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ extern "C" {
2828
static inline void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2) {}
2929
static inline void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1, int arg2) {}
3030
static inline void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1, int arg2) {}
31+
static inline void PyDTrace_CFUNCTION_ENTRY(const char *arg0, const char *arg1) {}
32+
static inline void PyDTrace_CFUNCTION_RETURN(const char *arg0, const char *arg1) {}
3133
static inline void PyDTrace_GC_START(int arg0) {}
3234
static inline void PyDTrace_GC_DONE(Py_ssize_t arg0) {}
33-
static inline void PyDTrace_INSTANCE_NEW_START(int arg0) {}
34-
static inline void PyDTrace_INSTANCE_NEW_DONE(int arg0) {}
35-
static inline void PyDTrace_INSTANCE_DELETE_START(int arg0) {}
36-
static inline void PyDTrace_INSTANCE_DELETE_DONE(int arg0) {}
35+
static inline void PyDTrace_INSTANCE_NEW_START(const char *arg0, const char *arg1) {}
36+
static inline void PyDTrace_INSTANCE_NEW_DONE(const char *arg0, const char *arg1) {}
37+
static inline void PyDTrace_INSTANCE_DELETE_START(const char *arg0, const char *arg1) {}
38+
static inline void PyDTrace_INSTANCE_DELETE_DONE(const char *arg0, const char *arg1) {}
3739
static inline void PyDTrace_IMPORT_FIND_LOAD_START(const char *arg0) {}
3840
static inline void PyDTrace_IMPORT_FIND_LOAD_DONE(const char *arg0, int arg1) {}
3941
static inline void PyDTrace_AUDIT(const char *arg0, void *arg1) {}
4042

4143
static inline int PyDTrace_LINE_ENABLED(void) { return 0; }
4244
static inline int PyDTrace_FUNCTION_ENTRY_ENABLED(void) { return 0; }
4345
static inline int PyDTrace_FUNCTION_RETURN_ENABLED(void) { return 0; }
46+
static inline int PyDTrace_CFUNCTION_ENTRY_ENABLED(void) { return 0; }
47+
static inline int PyDTrace_CFUNCTION_RETURN_ENABLED(void) { return 0; }
4448
static inline int PyDTrace_GC_START_ENABLED(void) { return 0; }
4549
static inline int PyDTrace_GC_DONE_ENABLED(void) { return 0; }
4650
static inline int PyDTrace_INSTANCE_NEW_START_ENABLED(void) { return 0; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BEGIN { printf("probe: success\n"); exit(); }

Lib/test/dtracedata/call_stack.bt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@seq = 0;
2+
3+
usdt:@TARGET@:python:function__entry /str(args->arg1) == "start"/ {
4+
@trace[tid] = 1;
5+
@indent[tid] = 0;
6+
}
7+
8+
usdt:@TARGET@:python:function__entry /@trace[tid]/ {
9+
@seq += 1;
10+
printf("%d\t%15s:", (int)@seq, "function-entry");
11+
printf("%*s", @indent[tid], "");
12+
printf("%s:%s:%d\n", str(args->arg0), str(args->arg1), args->arg2);
13+
@indent[tid] = @indent[tid] + 1;
14+
}
15+
16+
usdt:@TARGET@:python:function__return /@trace[tid]/ {
17+
@indent[tid] = @indent[tid] - 1;
18+
@seq += 1;
19+
printf("%d\t%15s:", (int)@seq, "function-return");
20+
printf("%*s", @indent[tid], "");
21+
printf("%s:%s:%d\n", str(args->arg0), str(args->arg1), args->arg2);
22+
}
23+
24+
usdt:@TARGET@:python:function__return /str(args->arg1) == "start"/ {
25+
@trace[tid] = 0;
26+
@indent[tid] = 0;
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function-entry:call_stack.py:start:23
2+
function-entry: call_stack.py:function_1:1
3+
function-entry: call_stack.py:function_3:9
4+
function-return: call_stack.py:function_3:10
5+
function-return: call_stack.py:function_1:2
6+
function-entry: call_stack.py:function_2:5
7+
function-entry: call_stack.py:function_1:1
8+
function-entry: call_stack.py:function_3:9
9+
function-return: call_stack.py:function_3:10
10+
function-return: call_stack.py:function_1:2
11+
function-return: call_stack.py:function_2:6
12+
function-entry: call_stack.py:function_3:9
13+
function-return: call_stack.py:function_3:10
14+
function-entry: call_stack.py:function_4:13
15+
function-return: call_stack.py:function_4:14
16+
function-entry: call_stack.py:function_5:18
17+
function-return: call_stack.py:function_5:21
18+
function-return:call_stack.py:start:28

Lib/test/dtracedata/cfunction.bt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@seq = 0;
2+
3+
usdt:@TARGET@:python:function__entry /str(args->arg1) == "start"/ { @trace[tid] = 1; }
4+
5+
usdt:@TARGET@:python:cfunction__entry /@trace[tid]/ {
6+
@seq += 1;
7+
const char *module = args->arg0 ? str(args->arg0) : "";
8+
printf("%d\tcfunction-entry:%s:%s\n", (int)@seq, module, str(args->arg1));
9+
}
10+
11+
usdt:@TARGET@:python:cfunction__return /@trace[tid]/ {
12+
@seq += 1;
13+
const char *module = args->arg0 ? str(args->arg0) : "";
14+
printf("%d\tcfunction-return:%s:%s\n", (int)@seq, module, str(args->arg1));
15+
}
16+
17+
usdt:@TARGET@:python:function__return /str(args->arg1) == "start"/ { @trace[tid] = 0; }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cfunction-entry:builtins:len
2+
cfunction-return:builtins:len
3+
cfunction-entry:math:sqrt
4+
cfunction-return:math:sqrt
5+
cfunction-entry:builtins:sum
6+
cfunction-return:builtins:sum

Lib/test/dtracedata/cfunction.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
self int tracing;
2+
3+
python$target:::function-entry
4+
/copyinstr(arg1) == "start"/
5+
{
6+
self->tracing = 1;
7+
}
8+
9+
python$target:::cfunction-entry,
10+
python$target:::cfunction-return
11+
/self->tracing/
12+
{
13+
this->module = arg0 ? copyinstr(arg0) : "";
14+
printf("%d\t%s:%s:%s\n", timestamp, probename, this->module, copyinstr(arg1));
15+
}
16+
17+
python$target:::function-return
18+
/copyinstr(arg1) == "start"/
19+
{
20+
self->tracing = 0;
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cfunction-entry:builtins:len
2+
cfunction-return:builtins:len
3+
cfunction-entry:math:sqrt
4+
cfunction-return:math:sqrt
5+
cfunction-entry:builtins:sum
6+
cfunction-return:builtins:sum

0 commit comments

Comments
 (0)