| 1 |
#include "sys/sdt.h" |
| 2 |
#include "string.h" |
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
class ProbeClass |
| 6 |
{ |
| 7 |
private: |
| 8 |
int& ref; |
| 9 |
const char *name; |
| 10 |
|
| 11 |
public: |
| 12 |
ProbeClass(int& v, const char *n) : ref(v), name(n) |
| 13 |
{ |
| 14 |
char nm [32]; |
| 15 |
strcpy (nm, name); |
| 16 |
STAP_PROBE2(_test_, cons, nm, ref); |
| 17 |
} |
| 18 |
|
| 19 |
void method(int min) |
| 20 |
{ |
| 21 |
char nm [32]; |
| 22 |
strcpy (nm, name); |
| 23 |
STAP_PROBE3(_test_, meth, nm, ref, min); |
| 24 |
ref -= min; |
| 25 |
} |
| 26 |
|
| 27 |
~ProbeClass() |
| 28 |
{ |
| 29 |
char nm [32]; |
| 30 |
strcpy (nm, name); |
| 31 |
STAP_PROBE2(_test_, dest, nm, ref); |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
static void |
| 36 |
call() |
| 37 |
{ |
| 38 |
int i = 64; |
| 39 |
STAP_PROBE1(_test_, call, i); |
| 40 |
ProbeClass inst = ProbeClass(i, "call"); |
| 41 |
inst.method(24); |
| 42 |
i += 2; |
| 43 |
// Here the destructor goes out of scope and uses i as ref one last time. |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
call2() |
| 48 |
{ |
| 49 |
int j = 24; |
| 50 |
STAP_PROBE1(_test_, call2, j); |
| 51 |
ProbeClass inst = ProbeClass(j, "call2"); |
| 52 |
inst.method(40); |
| 53 |
j += 58; |
| 54 |
// Here the destructor goes out of scope and uses i as ref one last time. |
| 55 |
} |
| 56 |
|
| 57 |
int |
| 58 |
main (int argc, char **argv) |
| 59 |
{ |
| 60 |
STAP_PROBE(_test_, main_enter); |
| 61 |
call(); |
| 62 |
call2(); |
| 63 |
STAP_PROBE(_test_, main_exit); |
| 64 |
return 0; |
| 65 |
} |