github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/cli/cli_darwin.go (about)

     1  package cli
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"runtime"
     7  	"strings"
     8  )
     9  
    10  func defaultAgentConfigPath() string {
    11  	return filepath.Join(getInstallPrefix(), "/etc/pyroscope/agent.yml")
    12  }
    13  
    14  func defaultAgentLogFilePath() string { return "" }
    15  
    16  // on mac pyroscope is usually installed via homebrew. homebrew installs under a prefix
    17  //   this is logic to figure out what prefix it is
    18  func getInstallPrefix() string {
    19  	if runtime.GOOS != "darwin" {
    20  		return ""
    21  	}
    22  
    23  	executablePath, err := os.Executable()
    24  	if err != nil {
    25  		// TODO: figure out what kind of errors might happen, handle it
    26  		return ""
    27  	}
    28  	cellarPath := filepath.Clean(filepath.Join(resolvePath(executablePath), "../../../.."))
    29  
    30  	if !strings.HasSuffix(cellarPath, "Cellar") {
    31  		// looks like it's not installed via homebrew
    32  		return ""
    33  	}
    34  
    35  	return filepath.Clean(filepath.Join(cellarPath, "../"))
    36  }
    37  
    38  func resolvePath(path string) string {
    39  	if res, err := filepath.EvalSymlinks(path); err == nil {
    40  		return res
    41  	}
    42  	return path
    43  }