From c37843c5c830e8f8e2494e56a08727be8566bae9 Mon Sep 17 00:00:00 2001 From: jaxfang Date: Thu, 25 Jul 2024 15:35:13 +0800 Subject: [PATCH] chore(): update sleep time log --- net/net_linux.go | 2 +- net/net_windows.go | 2 +- net/netlink/inetdiag.go | 6 +++--- net/sleepconfig/sleepconfig.go | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/net/net_linux.go b/net/net_linux.go index 3df95bc9a..f3e39050b 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -673,7 +673,7 @@ func getProcInodesAllWithContext(ctx context.Context, root string, max int) (map ret := make(map[string][]inodeMap) for i, pid := range pids { - sleepconfig.TimeSleep(i) + sleepconfig.TimeSleep(i, len(pids)) t, err := getProcInodes(root, pid, max) if err != nil { // skip if permission error or no longer exists diff --git a/net/net_windows.go b/net/net_windows.go index e2bfdc229..e8c01df10 100644 --- a/net/net_windows.go +++ b/net/net_windows.go @@ -465,7 +465,7 @@ func getTCPConnections(family uint32) ([]ConnectionStat, error) { } for i := 0; i < length; i++ { - sleepconfig.TimeSleep(i) + sleepconfig.TimeSleep(i, length) switch family { case kindTCP4.family: mibs := (*mibTCPRowOwnerPid)(unsafe.Pointer(&buf[index])) diff --git a/net/netlink/inetdiag.go b/net/netlink/inetdiag.go index 9e3990c51..d1f5371cc 100644 --- a/net/netlink/inetdiag.go +++ b/net/netlink/inetdiag.go @@ -5,8 +5,8 @@ // https://github.com/elastic/gosigar/tree/master/sys/linux // // modified point: -// - delete NewInetDiagReq. gopsutil only support v2. -// - change connection state strings. +// - delete NewInetDiagReq. gopsutil only support v2. +// - change connection state strings. package netlink import ( @@ -164,7 +164,7 @@ done: } for i, m := range msgs { - sleepconfig.TimeSleep(i) + sleepconfig.TimeSleep(i, len(msgs)) if m.Header.Type == syscall.NLMSG_DONE { break done } diff --git a/net/sleepconfig/sleepconfig.go b/net/sleepconfig/sleepconfig.go index 62f061b7c..15e0aee13 100644 --- a/net/sleepconfig/sleepconfig.go +++ b/net/sleepconfig/sleepconfig.go @@ -23,7 +23,7 @@ func InitSleepConfig(ms int, loop int, logger slog.Logger) { config.logger = logger } -func TimeSleep(i int) { +func TimeSleep(i int, total int) { if !config.enable { return } @@ -33,7 +33,9 @@ func TimeSleep(i int) { } ms := config.sleepMs.Load() if ms != 0 { - config.logger.Infof("time sleep, sleep duration: %d, current loop count: %d", ms, i) + if (i+1) == j || (i+1) == (total/j)*j || (i+1)%10000 == 0 { + config.logger.Infof("time sleep, sleep duration: %d, current loop count: %d", ms, i) + } time.Sleep(time.Duration(ms) * time.Millisecond) } }