项目文件夹

文件
wehub-resource-sync 36b3af2e3d
PR Check / Code Quality: Format (push) Failing after 1s
PR Check / Code Quality: Lint (darwin) (push) Failing after 0s
PR Check / Code Quality: Lint (freebsd) (push) Failing after 1s
PR Check / Code Quality: Lint (windows) (push) Failing after 1s
PR Check / Code Quality: Lint (linux) (push) Failing after 1s
PR Check / Security: Vulnerability Scan (push) Failing after 0s
Update Documentation / update-docs (push) Failing after 2s
PR Check / Code Quality: Vendor (push) Failing after 1s
PR Check / Code Quality: Coverage (push) Failing after 0s
PR Check / Tests: Unit (macos-latest) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04) (push) Has been cancelled
PR Check / Tests: Unit (ubuntu-24.04-arm) (push) Has been cancelled
PR Check / Tests: Unit (windows-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:06 +08:00

45 行
1.1 KiB
Go

//go:build freebsd
package proc
import (
"fmt"
"os/exec"
"strconv"
"strings"
"github.com/pranshuparmar/witr/pkg/model"
)
// GetResourceContext returns resource usage context for a process
// FreeBSD implementation - basic support
func GetResourceContext(pid int) *model.ResourceContext {
// FreeBSD doesn't have macOS-style power assertions or thermal monitoring
// Could potentially check CPU temperature via sysctl dev.cpu.*.temperature
// but this is not process-specific
ctx := &model.ResourceContext{}
out, err := exec.Command("ps", "-p", fmt.Sprintf("%d", pid), "-o", "%cpu,rss").Output()
if err == nil {
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
if len(lines) > 0 {
fields := strings.Fields(lines[len(lines)-1])
if len(fields) >= 2 {
if cpu, err := strconv.ParseFloat(fields[0], 64); err == nil {
ctx.CPUUsage = cpu
}
if rssKB, err := strconv.ParseUint(fields[1], 10, 64); err == nil {
ctx.MemoryUsage = rssKB * 1024
}
}
}
}
if ctx.CPUUsage > 0 || ctx.MemoryUsage > 0 {
return ctx
}
return nil
}