From 28f6d1b35ac4f133fc820c82e70a90c921685520 Mon Sep 17 00:00:00 2001 From: Daniel Shank Date: Fri, 22 Sep 2023 18:59:11 -0400 Subject: [PATCH] These two methods can be consolidated in order to avoid opening the /proc/{pid}/stat file multiple times --- process/process.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/process/process.go b/process/process.go index 1a7fe1b80..ed6ee0f18 100644 --- a/process/process.go +++ b/process/process.go @@ -341,12 +341,7 @@ func (p *Process) CPUPercent() (float64, error) { } func (p *Process) CPUPercentWithContext(ctx context.Context) (float64, error) { - crt_time, err := p.createTimeWithContext(ctx) - if err != nil { - return 0, err - } - - cput, err := p.TimesWithContext(ctx) + _, _, cput, crt_time, _, _, _, err := p.fillFromStatWithContext(ctx) if err != nil { return 0, err }