mirror of
https://github.com/apple/swift-nio.git
synced 2026-05-20 20:30:36 +00:00
99ac8ec29c
Motivation: When debugging allocations it is frequently helpful to be able to use bpftrace instead of the more limited heaptrack. Modifications: Offer an equivalent of malloc-aggregation.d for bpftrace. Result: Allocation recording on Linux is available.
52 lines
1.4 KiB
Plaintext
Executable File
52 lines
1.4 KiB
Plaintext
Executable File
#!/usr/bin/env bpftrace
|
|
/*===----------------------------------------------------------------------===*
|
|
*
|
|
* This source file is part of the SwiftNIO open source project
|
|
*
|
|
* Copyright (c) 2017-2025 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.bt -c .build/release/NIOHTTP1Server
|
|
*
|
|
* This will frequently lack symbols, so consider using the pid-based version:
|
|
* sudo dev/malloc-aggregation.bt -p 19898
|
|
*/
|
|
|
|
BEGIN {
|
|
printf("\n\n");
|
|
printf("=====\n");
|
|
printf("This will collect stack shots of allocations and print it when ");
|
|
printf("you exit bpftrace.\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");
|
|
}
|
|
|
|
uprobe:*:aligned_alloc,
|
|
uprobe:*:calloc,
|
|
uprobe:*:malloc,
|
|
uprobe:*:posix_memalign,
|
|
uprobe:*:realloc,
|
|
uprobe:*:reallocf,
|
|
uprobe:*:valloc,
|
|
uprobe:*:malloc_zone_calloc,
|
|
uprobe:*:malloc_zone_malloc,
|
|
uprobe:*:malloc_zone_memalign,
|
|
uprobe:*:malloc_zone_realloc,
|
|
uprobe:*:malloc_zone_valloc {
|
|
@malloc_calls[ustack()] = count();
|
|
}
|
|
|
|
END {
|
|
print(@malloc_calls);
|
|
}
|