debug.go 899 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package sync
  7. import (
  8. "os"
  9. "strconv"
  10. "time"
  11. "github.com/syncthing/syncthing/lib/logger"
  12. )
  13. var (
  14. threshold = 100 * time.Millisecond
  15. l = logger.DefaultLogger.NewFacility("sync", "Mutexes")
  16. // We make an exception in this package and have an actual "if debug { ...
  17. // }" variable, as it may be rather performance critical and does
  18. // nonstandard things (from a debug logging PoV).
  19. debug = logger.DefaultLogger.ShouldDebug("sync")
  20. )
  21. func init() {
  22. if n, _ := strconv.Atoi(os.Getenv("STLOCKTHRESHOLD")); n > 0 {
  23. threshold = time.Duration(n) * time.Millisecond
  24. }
  25. l.Debugf("Enabling lock logging at %v threshold", threshold)
  26. }