-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid opening log output before start &
Replace tracing logs with task monitor
- Loading branch information
1 parent
7772ba9
commit 5077a87
Showing
14 changed files
with
222 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package taskmonitor | ||
|
||
import ( | ||
"time" | ||
|
||
F "github.com/sagernet/sing/common/format" | ||
"github.com/sagernet/sing/common/logger" | ||
) | ||
|
||
type Monitor struct { | ||
logger logger.Logger | ||
timeout time.Duration | ||
timer *time.Timer | ||
} | ||
|
||
func New(logger logger.Logger, timeout time.Duration) *Monitor { | ||
return &Monitor{ | ||
logger: logger, | ||
timeout: timeout, | ||
} | ||
} | ||
|
||
func (m *Monitor) Start(taskName ...any) { | ||
m.timer = time.AfterFunc(m.timeout, func() { | ||
m.logger.Warn(F.ToString(taskName...), " take too much time to finish!") | ||
}) | ||
} | ||
|
||
func (m *Monitor) Finish() { | ||
m.timer.Stop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.