Skip to content

Commit

Permalink
Merge pull request #8 from easyops-cn/jax/time_sleep
Browse files Browse the repository at this point in the history
chore(): update sleep time log
  • Loading branch information
revisegoal authored Jul 25, 2024
2 parents f04b221 + c37843c commit b010d7b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion net/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion net/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
6 changes: 3 additions & 3 deletions net/netlink/inetdiag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions net/sleepconfig/sleepconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}

0 comments on commit b010d7b

Please sign in to comment.