Skip to content

Commit 033a788

Browse files
committed
some minor changes
1 parent df92f51 commit 033a788

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

base/util.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,24 +1834,24 @@ func IsRevTreeID(s string) bool {
18341834
return false
18351835
}
18361836

1837+
// GetStackTrace will return goroutine stack traces for all goroutines in Sync Gateway.
18371838
func GetStackTrace() string {
1838-
// this nees logging in to warmn if we don;t successfully grab the stack in 10 tries
1839-
// mnaybe use some switch retyr logic
1839+
// make 1MB buffer but if this buffer isn't big enough, runtime.Stack will
1840+
// return nothing, thus have 5 retires doubling the capacity each time.
18401841
buf := make([]byte, 1<<20)
1841-
count := 0
1842-
for count < 10 {
1842+
for range 5 {
18431843
n := runtime.Stack(buf, true)
1844-
fmt.Println("n", n)
18451844
if n < len(buf) {
18461845
buf = buf[:n]
18471846
break
18481847
}
18491848
buf = make([]byte, 2*len(buf))
1850-
count++
18511849
}
18521850
return string(buf)
18531851
}
18541852

1853+
// RotateProfilesIfNeeded will remove old files if there are more than
1854+
// 10 matching the given filename pattern.
18551855
func RotateProfilesIfNeeded(filename string) error {
18561856
existingFiles, err := filepath.Glob(filename)
18571857
if err != nil {
@@ -1871,6 +1871,7 @@ func RotateProfilesIfNeeded(filename string) error {
18711871
return multiErr.ErrorOrNil()
18721872
}
18731873

1874-
func CreateFileInLoggingDirectory(filename string) (*os.File, error) {
1874+
// CreateFileInDirectory will create a file in directory specified by filename.
1875+
func CreateFileInDirectory(filename string) (*os.File, error) {
18751876
return os.Create(filename)
18761877
}

rest/server_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ func (sc *ServerContext) logStackTraces(ctx context.Context, timestamp string) {
18821882
_, _ = fmt.Fprintf(os.Stderr, "Stack trace:\n%s\n", stackTrace)
18831883

18841884
filename := filepath.Join(sc.Config.Logging.LogFilePath, stackFilePrefix+timestamp+".log")
1885-
file, err := base.CreateFileInLoggingDirectory(filename)
1885+
file, err := base.CreateFileInDirectory(filename)
18861886
defer func() {
18871887
err = file.Close()
18881888
if err != nil {

rest/stats_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (statsContext *statsContext) collectMemoryProfile(ctx context.Context, outp
392392

393393
memoryProfile := pprof.Lookup("heap")
394394
filename := filepath.Join(outputDir, pprofPrefix+timestamp+".pb.gz")
395-
file, err := base.CreateFileInLoggingDirectory(filename)
395+
file, err := base.CreateFileInDirectory(filename)
396396
defer func() {
397397
err = file.Close()
398398
if err != nil {

0 commit comments

Comments
 (0)