lock/instrumentation: Cleanup and print in user friendly form. (#2807)

This commit is contained in:
Harshavardhana
2016-10-11 00:50:27 -07:00
committed by GitHub
parent 3ac6790ca2
commit fa8ea41cd9
24 changed files with 856 additions and 476 deletions
+18 -1
View File
@@ -19,6 +19,9 @@ package cmd
import (
"bufio"
"bytes"
"fmt"
"path/filepath"
"runtime"
"runtime/debug"
"strings"
@@ -42,6 +45,20 @@ type logger struct {
// Add new loggers here.
}
// Function takes input with the results from runtime.Caller(1). Depending on the boolean.
// This function can either returned a shotFile form or a longFile form.
func funcFromPC(pc uintptr, file string, line int, shortFile bool) string {
var fn, name string
if shortFile {
fn = strings.Replace(file, filepath.ToSlash(GOPATH)+"/src/github.com/minio/minio/cmd/", "", -1)
name = strings.Replace(runtime.FuncForPC(pc).Name(), "github.com/minio/minio/cmd.", "", -1)
} else {
fn = strings.Replace(file, filepath.ToSlash(GOPATH)+"/src/", "", -1)
name = strings.Replace(runtime.FuncForPC(pc).Name(), "github.com/minio/minio/cmd.", "", -1)
}
return fmt.Sprintf("%s [%s:%d]", name, fn, line)
}
// stackInfo returns printable stack trace.
func stackInfo() string {
// Convert stack-trace bytes to io.Reader.
@@ -56,7 +73,7 @@ func stackInfo() string {
stackBuf.ReadFrom(rawStack)
// Strip GOPATH of the build system and return.
return strings.Replace(stackBuf.String(), GOPATH+"/src/", "", -1)
return strings.Replace(stackBuf.String(), filepath.ToSlash(GOPATH)+"/src/", "", -1)
}
// errorIf synonymous with fatalIf but doesn't exit on error != nil