Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/analytics/parentprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@ import (
"runtime"
"strconv"
"strings"
"time"
)

// getParentProcessInfo returns the name and full command line of the parent process.
// Times out after 100ms to avoid blocking the CLI.
func getParentProcessInfo() (name, cmdline string) {
type result struct {
name, cmdline string
}
ch := make(chan result, 1)
go func() {
n, c := getParentProcessInfoSync()
ch <- result{name: n, cmdline: c}
}()
select {
case r := <-ch:
return r.name, r.cmdline
case <-time.After(100 * time.Millisecond):
return "", ""
}
}

func getParentProcessInfoSync() (name, cmdline string) {
ppid := os.Getppid()
if ppid <= 0 {
return "", ""
Expand Down
18 changes: 16 additions & 2 deletions pkg/analytics/posthog.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,24 @@ func getTimezone() string {
}

func getGPUInfo() string {
type result struct {
out string
}
ch := make(chan result, 1)
go func() {
ch <- result{out: getGPUInfoSync()}
}()
select {
case r := <-ch:
return r.out
case <-time.After(100 * time.Millisecond):
return ""
}
}

func getGPUInfoSync() string {
out, err := exec.Command("nvidia-smi", "--query-gpu=name,memory.total,driver_version,count", "--format=csv,noheader,nounits").Output() // #nosec G204
if err != nil {
// nvidia-smi not available or no NVIDIA GPU
if runtime.GOOS == "darwin" {
return getAppleGPUInfo()
}
Expand All @@ -335,7 +350,6 @@ func getAppleGPUInfo() string {
if err != nil {
return ""
}
// Extract just the chipset/model lines
lines := strings.Split(string(out), "\n")
var gpuLines []string
for _, line := range lines {
Expand Down
Loading