Skip to content

Commit 91e0823

Browse files
committed
Replace DTrace sample with a premissive license
1 parent cba9b95 commit 91e0823

File tree

2 files changed

+184
-73
lines changed

2 files changed

+184
-73
lines changed

samples/DTrace/javascript-trace.d

Lines changed: 0 additions & 73 deletions
This file was deleted.

samples/DTrace/trace_futexes.d

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#!/usr/sbin/dtrace -qs
2+
3+
// Source: https://github.com/bycn82/freebsd/blob/12a4a4a008eac3cfa71e496b33eaeaf426c374c1/sys/compat/linux/trace_futexes.d
4+
5+
/*-
6+
* Copyright (c) 2011-2012 Alexander Leidinger <netchild@FreeBSD.org>
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer
14+
* in this position and unchanged.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*
30+
* $FreeBSD$
31+
*/
32+
33+
/**
34+
* Trace futex operations:
35+
* - internal locks
36+
* - size of the futex list
37+
* - report error conditions (emulation errors, kernel errors,
38+
* programming errors)
39+
* - execution time (wallclock) of futex related functions
40+
*/
41+
42+
#pragma D option specsize=32m
43+
44+
/* Error conditions */
45+
linuxulator*:futex:futex_get:error,
46+
linuxulator*:futex:futex_sleep:requeue_error,
47+
linuxulator*:futex:futex_sleep:sleep_error,
48+
linuxulator*:futex:futex_wait:copyin_error,
49+
linuxulator*:futex:futex_wait:itimerfix_error,
50+
linuxulator*:futex:futex_wait:sleep_error,
51+
linuxulator*:futex:futex_atomic_op:missing_access_check,
52+
linuxulator*:futex:futex_atomic_op:unimplemented_op,
53+
linuxulator*:futex:futex_atomic_op:unimplemented_cmp,
54+
linuxulator*:futex:linux_sys_futex:unimplemented_clockswitch,
55+
linuxulator*:futex:linux_sys_futex:copyin_error,
56+
linuxulator*:futex:linux_sys_futex:unhandled_efault,
57+
linuxulator*:futex:linux_sys_futex:unimplemented_lock_pi,
58+
linuxulator*:futex:linux_sys_futex:unimplemented_unlock_pi,
59+
linuxulator*:futex:linux_sys_futex:unimplemented_trylock_pi,
60+
linuxulator*:futex:linux_sys_futex:unimplemented_wait_requeue_pi,
61+
linuxulator*:futex:linux_sys_futex:unimplemented_cmp_requeue_pi,
62+
linuxulator*:futex:linux_sys_futex:unknown_operation,
63+
linuxulator*:futex:linux_get_robust_list:copyout_error,
64+
linuxulator*:futex:handle_futex_death:copyin_error,
65+
linuxulator*:futex:fetch_robust_entry:copyin_error,
66+
linuxulator*:futex:release_futexes:copyin_error
67+
{
68+
printf("ERROR: %s in %s:%s:%s\n", probename, probeprov, probemod,
69+
probefunc);
70+
stack();
71+
ustack();
72+
}
73+
74+
linuxulator*:futex:linux_sys_futex:invalid_cmp_requeue_use,
75+
linuxulator*:futex:linux_sys_futex:deprecated_requeue,
76+
linuxulator*:futex:linux_set_robust_list:size_error
77+
{
78+
printf("WARNING: %s:%s:%s:%s in application %s, maybe an application error?\n",
79+
probename, probeprov, probemod, probefunc, execname);
80+
stack();
81+
ustack();
82+
}
83+
84+
85+
/* Per futex checks/statistics */
86+
87+
linuxulator*:futex:futex:create
88+
{
89+
++futex_count;
90+
@max_futexes = max(futex_count);
91+
}
92+
93+
linuxulator*:futex:futex:destroy
94+
/futex_count == 0/
95+
{
96+
printf("ERROR: Request to destroy a futex which was not created,\n");
97+
printf(" or this script was started after some futexes where\n");
98+
printf(" created. Stack trace:\n");
99+
stack();
100+
ustack();
101+
}
102+
103+
linuxulator*:futex:futex:destroy
104+
{
105+
--futex_count;
106+
}
107+
108+
109+
/* Internal locks */
110+
111+
linuxulator*:locks:futex_mtx:locked
112+
{
113+
++check[probefunc, arg0];
114+
@stats[probefunc] = count();
115+
116+
ts[probefunc] = timestamp;
117+
spec[probefunc] = speculation();
118+
printf("Stacktrace of last lock operation of the %s:\n", probefunc);
119+
stack();
120+
}
121+
122+
linuxulator*:locks:futex_mtx:unlock
123+
/check[probefunc, arg0] == 0/
124+
{
125+
printf("ERROR: unlock attempt of unlocked %s (%p),", probefunc, arg0);
126+
printf(" missing SDT probe in kernel, or dtrace program started");
127+
printf(" while the %s was already held (race condition).", probefunc);
128+
printf(" Stack trace follows:");
129+
stack();
130+
}
131+
132+
linuxulator*:locks:futex_mtx:unlock
133+
{
134+
discard(spec[probefunc]);
135+
spec[probefunc] = 0;
136+
--check[probefunc, arg0];
137+
}
138+
139+
/* Timeout handling for internal locks */
140+
141+
tick-10s
142+
/spec["futex_mtx"] != 0 && timestamp - ts["futex_mtx"] >= 9999999000/
143+
{
144+
commit(spec["futex_mtx"]);
145+
spec["futex_mtx"] = 0;
146+
}
147+
148+
149+
/* Timing statistings */
150+
151+
linuxulator*:futex::entry
152+
{
153+
self->time[probefunc] = timestamp;
154+
@calls[probeprov, execname, probefunc] = count();
155+
}
156+
157+
linuxulator*:futex::return
158+
/self->time[probefunc] != 0/
159+
{
160+
this->timediff = self->time[probefunc] - timestamp;
161+
162+
@timestats[probeprov, execname, probefunc] = quantize(this->timediff);
163+
@longest[probeprov, probefunc] = max(this->timediff);
164+
165+
self->time[probefunc] = 0;
166+
}
167+
168+
169+
/* Statistics */
170+
171+
END
172+
{
173+
printf("Number of locks per type:");
174+
printa(@stats);
175+
printf("Number of maximum number of futexes in the futex list:");
176+
printa(@max_futexes);
177+
printf("Number of futexes still existing: %d", futex_count);
178+
printf("Number of calls per provider/application/kernel function:");
179+
printa(@calls);
180+
printf("Wallclock-timing statistics per provider/application/kernel function (in ns):");
181+
printa(@timestats);
182+
printf("Longest running (wallclock!) functions per provider (in ns):");
183+
printa(@longest);
184+
}

0 commit comments

Comments
 (0)