mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 18:45:17 +00:00
perf: pre-compile regex patterns for GPU usage parsing
This commit is contained in:
BIN
bin/status-go
BIN
bin/status-go
Binary file not shown.
@@ -17,6 +17,12 @@ const (
|
|||||||
powermetricsTimeout = 2 * time.Second
|
powermetricsTimeout = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Pre-compiled regex patterns for GPU usage parsing
|
||||||
|
var (
|
||||||
|
gpuActiveResidencyRe = regexp.MustCompile(`GPU HW active residency:\s+([\d.]+)%`)
|
||||||
|
gpuIdleResidencyRe = regexp.MustCompile(`GPU idle residency:\s+([\d.]+)%`)
|
||||||
|
)
|
||||||
|
|
||||||
func (c *Collector) collectGPU(now time.Time) ([]GPUStatus, error) {
|
func (c *Collector) collectGPU(now time.Time) ([]GPUStatus, error) {
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
// Get static GPU info (cached for 10 min)
|
// Get static GPU info (cached for 10 min)
|
||||||
@@ -159,8 +165,7 @@ func getMacGPUUsage() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse "GPU HW active residency: X.XX%"
|
// Parse "GPU HW active residency: X.XX%"
|
||||||
re := regexp.MustCompile(`GPU HW active residency:\s+([\d.]+)%`)
|
matches := gpuActiveResidencyRe.FindStringSubmatch(out)
|
||||||
matches := re.FindStringSubmatch(out)
|
|
||||||
if len(matches) >= 2 {
|
if len(matches) >= 2 {
|
||||||
usage, err := strconv.ParseFloat(matches[1], 64)
|
usage, err := strconv.ParseFloat(matches[1], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -169,8 +174,7 @@ func getMacGPUUsage() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: parse "GPU idle residency: X.XX%" and calculate active
|
// Fallback: parse "GPU idle residency: X.XX%" and calculate active
|
||||||
reIdle := regexp.MustCompile(`GPU idle residency:\s+([\d.]+)%`)
|
matchesIdle := gpuIdleResidencyRe.FindStringSubmatch(out)
|
||||||
matchesIdle := reIdle.FindStringSubmatch(out)
|
|
||||||
if len(matchesIdle) >= 2 {
|
if len(matchesIdle) >= 2 {
|
||||||
idle, err := strconv.ParseFloat(matchesIdle[1], 64)
|
idle, err := strconv.ParseFloat(matchesIdle[1], 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user