Skip to content

Commit

Permalink
feat: add flag to dump pprof profiles to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
ddlees committed Oct 9, 2023
1 parent cf0f5ab commit 873de02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ import (
"os"
"path"
"path/filepath"
"runtime/pprof"
"time"

"github.com/spf13/cobra"
"golang.org/x/net/proxy"

"github.com/bloodhoundad/azurehound/v2/client"
client_config "github.com/bloodhoundad/azurehound/v2/client/config"
"github.com/bloodhoundad/azurehound/v2/client/rest"
Expand All @@ -45,8 +49,6 @@ import (
"github.com/bloodhoundad/azurehound/v2/models"
"github.com/bloodhoundad/azurehound/v2/pipeline"
"github.com/bloodhoundad/azurehound/v2/sinks"
"github.com/spf13/cobra"
"golang.org/x/net/proxy"
)

func exit(err error) {
Expand Down Expand Up @@ -86,7 +88,9 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
func gracefulShutdown(stop context.CancelFunc) {
stop()
fmt.Fprintln(os.Stderr, "\nshutting down gracefully, press ctrl+c again to force")
// TODO timeout context
if profile := pprof.Lookup(config.Pprof.Value().(string)); profile != nil {
profile.WriteTo(os.Stderr, 1)
}
}

func testConnections() error {
Expand Down Expand Up @@ -224,7 +228,6 @@ func newAzureClient() (client.AzureClient, error) {
} else {
clientCert = string(content)
}

}

if file, ok := keyFile.(string); ok && file != "" {
Expand Down
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ var (
Persistent: true,
Default: "",
}
Pprof = Config{
Name: "pprof",
Usage: "During graceful shutdown, prints the pprof profile with the provided name to stderr",
Persistent: true,
Default: "",
}

// Azure Configurations
AzAppId = Config{
Expand Down Expand Up @@ -283,6 +289,7 @@ var (
LogFile,
Proxy,
RefreshToken,
Pprof,
}

AzureConfig = []Config{
Expand Down

0 comments on commit 873de02

Please sign in to comment.