2015-04-22 22:54:31 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2016-11-05 02:24:53 +00:00
|
|
|
"github.com/sasha-s/go-deadlock"
|
2016-11-05 02:31:52 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/logger"
|
2015-04-22 22:54:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-12-17 14:37:11 +00:00
|
|
|
threshold = 100 * time.Millisecond
|
2015-10-03 15:25:21 +00:00
|
|
|
l = logger.DefaultLogger.NewFacility("sync", "Mutexes")
|
|
|
|
|
|
|
|
// We make an exception in this package and have an actual "if debug { ...
|
|
|
|
// }" variable, as it may be rather performance critical and does
|
|
|
|
// nonstandard things (from a debug logging PoV).
|
2016-11-05 02:24:53 +00:00
|
|
|
debug = strings.Contains(os.Getenv("STTRACE"), "sync") || os.Getenv("STTRACE") == "all"
|
|
|
|
useDeadlock = os.Getenv("STDEADLOCK") != ""
|
2015-04-22 22:54:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-10-03 15:25:21 +00:00
|
|
|
l.SetDebug("sync", strings.Contains(os.Getenv("STTRACE"), "sync") || os.Getenv("STTRACE") == "all")
|
|
|
|
|
|
|
|
if n, err := strconv.Atoi(os.Getenv("STLOCKTHRESHOLD")); err == nil {
|
2016-11-05 02:31:52 +00:00
|
|
|
threshold = time.Duration(n) * time.Millisecond
|
|
|
|
}
|
|
|
|
if n, err := strconv.Atoi(os.Getenv("STDEADLOCK")); err == nil {
|
|
|
|
deadlock.Opts.DeadlockTimeout = time.Duration(n) * time.Second
|
2015-04-22 22:54:31 +00:00
|
|
|
}
|
2015-10-03 15:25:21 +00:00
|
|
|
l.Debugf("Enabling lock logging at %v threshold", threshold)
|
|
|
|
}
|