mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Add stackdiff dump (#3289)
Motivation: Sometimes it's helpful to view the alloc stacks from a program. Modifications: - Add a 'dump' subcommand to stackdiff allowing you to dump the stack diff from heaptrack/dtrace/bpftrace - You can also filter the stacks so that only certain stacks are included Result: Can dump filtered alloc stacks to stdout
This commit is contained in:
1 parent
7ea505e5bf
commit
4d7097406f
2 files changed
+47
-1
No files matched your search
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftNIO open source project
|
||||
//
|
||||
// Copyright (c) 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
struct Dump: ParsableCommand {
|
||||
@Argument
|
||||
var file: String
|
||||
|
||||
@OptionGroup
|
||||
var options: StackdiffOptions
|
||||
|
||||
func run() throws {
|
||||
let aggregate = try self.options.load(file: self.file)
|
||||
let allocs = aggregate.netAllocations
|
||||
|
||||
// Sort by allocations.
|
||||
let sortedStacks = aggregate.sorted {
|
||||
$0.value.netAllocations > $1.value.netAllocations
|
||||
}
|
||||
|
||||
for (stack, weightedSubstacks) in sortedStacks {
|
||||
for line in StackFormatter.lines(
|
||||
forStack: stack,
|
||||
weightedSubstacks: weightedSubstacks,
|
||||
substackPrefix: " "
|
||||
) {
|
||||
print(line)
|
||||
}
|
||||
print("")
|
||||
}
|
||||
|
||||
print("TOTAL ALLOCATIONS: \(allocs)")
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import Stacks
|
||||
@main
|
||||
struct Stackdiff: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
CommandConfiguration(subcommands: [Diff.self])
|
||||
CommandConfiguration(subcommands: [Diff.self, Dump.self])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user