add useful dtrace scripts to debug allocations (#352)
Motivation: dtrace is extrmely useful when debugging allocation related issues. This adds two scripts that have helped me many times. Modifications: - `dev/malloc-aggregation.d` which prints an aggregation of all stacks that have allocated - `dev/boxed-existentials.d` which live prints all allocations of boxed existentials Result: sharing debugging tools is great
This commit is contained in:
parent
fadbba8a5d
commit
5599bfe4c8
|
@ -0,0 +1,23 @@
|
|||
#!/usr/sbin/dtrace -q -s
|
||||
/*===----------------------------------------------------------------------===*
|
||||
*
|
||||
* This source file is part of the SwiftNIO open source project
|
||||
*
|
||||
* Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
||||
* Licensed under Apache License v2.0
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
* See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*===----------------------------------------------------------------------===*/
|
||||
|
||||
/*
|
||||
* example invocation:
|
||||
* sudo dev/boxed-existentials.d -c .build/release/NIOHTTP1Server
|
||||
*/
|
||||
|
||||
pid$target::__swift_allocate_boxed_opaque_existential*:entry {
|
||||
ustack();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/sbin/dtrace -q -s
|
||||
/*===----------------------------------------------------------------------===*
|
||||
*
|
||||
* This source file is part of the SwiftNIO open source project
|
||||
*
|
||||
* Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
||||
* Licensed under Apache License v2.0
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
* See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*===----------------------------------------------------------------------===*/
|
||||
|
||||
/*
|
||||
* example invocation:
|
||||
* sudo dev/malloc-aggregation.d -c .build/release/NIOHTTP1Server
|
||||
*/
|
||||
|
||||
::BEGIN {
|
||||
printf("\n\n");
|
||||
printf("=====\n");
|
||||
printf("This will collect stack shots of allocations and print it when ");
|
||||
printf("you exit dtrace.\n");
|
||||
printf("So go ahead, run your tests and then press Ctrl+C in this window ");
|
||||
printf("to see the aggregated result\n");
|
||||
printf("=====\n");
|
||||
}
|
||||
|
||||
pid$target::malloc:entry {
|
||||
@malloc_calls[ustack()] = count();
|
||||
}
|
||||
|
||||
::END {
|
||||
printa(@malloc_calls);
|
||||
}
|
|
@ -31,7 +31,7 @@ fi
|
|||
printf "=> Checking license headers... "
|
||||
tmp=$(mktemp /tmp/.swift-nio-sanity_XXXXXX)
|
||||
|
||||
for language in swift-or-c bash; do
|
||||
for language in swift-or-c bash dtrace; do
|
||||
declare -a matching_files
|
||||
declare -a exceptions
|
||||
expections=( )
|
||||
|
@ -73,6 +73,25 @@ EOF
|
|||
## SPDX-License-Identifier: Apache-2.0
|
||||
##
|
||||
##===----------------------------------------------------------------------===##
|
||||
EOF
|
||||
;;
|
||||
dtrace)
|
||||
matching_files=( -name '*.d' )
|
||||
cat > "$tmp" <<"EOF"
|
||||
#!/usr/sbin/dtrace -q -s
|
||||
/*===----------------------------------------------------------------------===*
|
||||
*
|
||||
* This source file is part of the SwiftNIO open source project
|
||||
*
|
||||
* Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
||||
* Licensed under Apache License v2.0
|
||||
*
|
||||
* See LICENSE.txt for license information
|
||||
* See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
*===----------------------------------------------------------------------===*/
|
||||
EOF
|
||||
;;
|
||||
*)
|
||||
|
|
Loading…
Reference in New Issue