From 6d8e80e5c2e97d4e5b2636a953cff00f821b8dbf Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 6 Jul 2014 20:49:20 +0700 Subject: [PATCH] Remove sprintf where it's not required --- loadavg.go | 5 ++--- pid_stat.go | 4 ++-- pid_statm.go | 4 ++-- stat.go | 5 ++--- uptime.go | 5 ++--- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/loadavg.go b/loadavg.go index 5e3034e..9f68caf 100644 --- a/loadavg.go +++ b/loadavg.go @@ -26,15 +26,14 @@ type ProcLoadavg struct { } func NewProcLoadavg() ProcLoadavg { - file := fmt.Sprintf("/proc/loadavg") - bytes, err := ioutil.ReadFile(file) + b, err := ioutil.ReadFile("/proc/loadavg") if err != nil { panic(err) } p := ProcLoadavg{} - parsed, err := fmt.Sscanf(string(bytes), "%f %f %f %d/%d %d", + parsed, err := fmt.Sscanf(string(b), "%f %f %f %d/%d %d", &p.Avg1Min, &p.Avg5Min, &p.Avg15Min, &p.RunnableEntities, &p.TotalEntities, &p.LastPid) if parsed < 6 { diff --git a/pid_stat.go b/pid_stat.go index 9d2d0c1..d7cc3f0 100644 --- a/pid_stat.go +++ b/pid_stat.go @@ -212,14 +212,14 @@ type ProcPidStat struct { func NewProcPidStat(pid int) ProcPidStat { file := fmt.Sprintf("/proc/%d/stat", pid) - bytes, err := ioutil.ReadFile(file) + b, err := ioutil.ReadFile(file) if err != nil { panic(err) } p := ProcPidStat{} - parsed, err := fmt.Sscanf(string(bytes), + parsed, err := fmt.Sscanf(string(b), "%d %s %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d "+ "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &p.Pid, &p.Comm, &p.State, &p.Ppid, &p.Pgrp, &p.Session, &p.TtyNr, diff --git a/pid_statm.go b/pid_statm.go index 60ba14c..4701c93 100644 --- a/pid_statm.go +++ b/pid_statm.go @@ -19,14 +19,14 @@ type ProcPidStatm struct { func NewProcPidStatm(pid int) ProcPidStatm { file := fmt.Sprintf("/proc/%d/statm", pid) - bytes, err := ioutil.ReadFile(file) + b, err := ioutil.ReadFile(file) if err != nil { panic(err) } p := ProcPidStatm{} - parsed, err := fmt.Sscanf(string(bytes), "%d %d %d %d %d %d %d", + parsed, err := fmt.Sscanf(string(b), "%d %d %d %d %d %d %d", &p.Size, &p.Resident, &p.Share, &p.Text, &p.Lib, &p.Data, &p.Dt) if parsed < 7 { diff --git a/stat.go b/stat.go index 1477dc3..fb06cb1 100644 --- a/stat.go +++ b/stat.go @@ -30,15 +30,14 @@ type ProcStat struct { } func NewProcStat() ProcStat { - file := fmt.Sprintf("/proc/stat") - bytes, err := ioutil.ReadFile(file) + b, err := ioutil.ReadFile("/proc/stat") if err != nil { panic(err) } p := ProcStat{} - parsed, err := fmt.Sscanf(string(bytes), "cpu %d %d %d %d %d %d %d %d %d %d", + parsed, err := fmt.Sscanf(string(b), "cpu %d %d %d %d %d %d %d %d %d %d", &p.Cpu.User, &p.Cpu.Nice, &p.Cpu.System, &p.Cpu.Idle, &p.Cpu.Iowait, &p.Cpu.Irq, &p.Cpu.Softirq, &p.Cpu.Steal, &p.Cpu.Guest, &p.Cpu.GuestNice) diff --git a/uptime.go b/uptime.go index 0512d5e..b814c47 100644 --- a/uptime.go +++ b/uptime.go @@ -13,15 +13,14 @@ type ProcUptime struct { } func NewProcUptime() ProcUptime { - file := fmt.Sprintf("/proc/uptime") - bytes, err := ioutil.ReadFile(file) + b, err := ioutil.ReadFile("/proc/uptime") if err != nil { panic(err) } p := ProcUptime{} - parsed, err := fmt.Sscanf(string(bytes), "%f %f", &p.Uptime, &p.Idle) + parsed, err := fmt.Sscanf(string(b), "%f %f", &p.Uptime, &p.Idle) if parsed < 2 { fmt.Println("Managed to parse only", parsed, "fields out of 2") }