debug.go 756 B

12345678910111213141516171819202122232425262728293031
  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 http://mozilla.org/MPL/2.0/.
  6. package sync
  7. import (
  8. "os"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "github.com/calmh/logger"
  13. )
  14. var (
  15. debug = strings.Contains(os.Getenv("STTRACE"), "locks") || os.Getenv("STTRACE") == "all"
  16. threshold = time.Duration(100 * time.Millisecond)
  17. l = logger.DefaultLogger
  18. )
  19. func init() {
  20. if n, err := strconv.Atoi(os.Getenv("STLOCKTHRESHOLD")); debug && err == nil {
  21. threshold = time.Duration(n) * time.Millisecond
  22. }
  23. if debug {
  24. l.Debugf("Enabling lock logging at %v threshold", threshold)
  25. }
  26. }