Update to new version of probe

This commit is contained in:
Harshavardhana
2015-09-29 10:19:03 -07:00
parent 14daf88890
commit 638efef814
2 changed files with 41 additions and 21 deletions
+4 -4
View File
@@ -55,15 +55,15 @@
"canonical": "github.com/minio/minio/pkg/probe",
"comment": "",
"local": "vendor/github.com/minio/minio/pkg/probe",
"revision": "2f260adc69701f89a38fc8a27cde4b868dfe9ddf",
"revisionTime": "2015-08-24T03:43:13-07:00"
"revision": "daa089fb06b05ad7a9ce945e51362d349ffaf662",
"revisionTime": "2015-09-29T10:17:19-07:00"
},
{
"canonical": "github.com/minio/minio/pkg/quick",
"comment": "",
"local": "vendor/github.com/minio/minio/pkg/quick",
"revision": "4d1f38d28cabcfa321e9d88acef67e16e7bafb2a",
"revisionTime": "2015-08-22T18:37:56-07:00"
"revision": "daa089fb06b05ad7a9ce945e51362d349ffaf662",
"revisionTime": "2015-09-29T10:17:19-07:00"
},
{
"canonical": "github.com/minio/pb",
+37 -17
View File
@@ -50,11 +50,12 @@ func GetSysInfo() map[string]string {
}
}
// TracePoint container for individual trace entries in overall call trace
type TracePoint struct {
Line int `json:"Line,omitempty"`
Filename string `json:"File,omitempty"`
Function string `json:"Func,omitempty"`
Env map[string][]string `json:"Env,omitempty"`
Line int `json:"line,omitempty"`
Filename string `json:"file,omitempty"`
Function string `json:"func,omitempty"`
Env map[string][]string `json:"env,omitempty"`
}
// Error implements tracing error functionality.
@@ -65,10 +66,24 @@ type Error struct {
SysInfo map[string]string `json:"sysinfo,omitempty"`
}
// NewError function instantiates an error probe for tracing. Original errors.error (golang's error
// interface) is injected in only once during this New call. Rest of the time, you
// trace the return path with Probe.Trace and finally handle reporting or quitting
// at the top level.
// NewError function instantiates an error probe for tracing.
// Default ``error`` (golang's error interface) is injected in
// only once. Rest of the time, you trace the return path with
// ``probe.Trace`` and finally handling them at top level
//
// Following dummy code talks about how one can pass up the
// errors and put them in CallTrace.
//
// func sendError() *probe.Error {
// return probe.NewError(errors.New("Help Needed"))
// }
// func recvError() *probe.Error {
// return sendError().Trace()
// }
// if err := recvError(); err != nil {
// log.Fatalln(err.Trace())
// }
//
func NewError(e error) *Error {
if e == nil {
return nil
@@ -77,8 +92,8 @@ func NewError(e error) *Error {
return Err.trace()
}
// Trace records the point at which it is invoked. Stack traces are important for
// debugging purposes.
// Trace records the point at which it is invoked.
// Stack traces are important for debugging purposes.
func (e *Error) Trace(fields ...string) *Error {
if e == nil {
return nil
@@ -90,9 +105,11 @@ func (e *Error) Trace(fields ...string) *Error {
return e.trace(fields...)
}
// internal trace - records the point at which it is invoked. Stack traces are important for
// debugging purposes.
// Internal trace - records the point at which it is invoked.
func (e *Error) trace(fields ...string) *Error {
if e == nil {
return nil
}
pc, file, line, _ := runtime.Caller(2)
function := runtime.FuncForPC(pc).Name()
_, function = filepath.Split(function)
@@ -107,7 +124,7 @@ func (e *Error) trace(fields ...string) *Error {
return e
}
// Untrace erases last trace entry.
// Untrace erases last known trace entry.
func (e *Error) Untrace() *Error {
if e == nil {
return nil
@@ -125,6 +142,9 @@ func (e *Error) Untrace() *Error {
// ToGoError returns original error message.
func (e *Error) ToGoError() error {
if e == nil || e.Cause == nil {
return nil
}
return e.Cause
}
@@ -137,19 +157,19 @@ func (e *Error) String() string {
defer e.lock.RUnlock()
if e.Cause != nil {
str := e.Cause.Error() + "\n"
str := e.Cause.Error()
callLen := len(e.CallTrace)
for i := callLen - 1; i >= 0; i-- {
if len(e.CallTrace[i].Env) > 0 {
str += fmt.Sprintf(" (%d) %s:%d %s(..) Tags: [%s]\n",
str += fmt.Sprintf("\n (%d) %s:%d %s(..) Tags: [%s]",
i, e.CallTrace[i].Filename, e.CallTrace[i].Line, e.CallTrace[i].Function, strings.Join(e.CallTrace[i].Env["Tags"], ", "))
} else {
str += fmt.Sprintf(" (%d) %s:%d %s(..)\n",
str += fmt.Sprintf("\n (%d) %s:%d %s(..)",
i, e.CallTrace[i].Filename, e.CallTrace[i].Line, e.CallTrace[i].Function)
}
}
str += " Host:" + e.SysInfo["host.name"] + " | "
str += "\n" + " Host:" + e.SysInfo["host.name"] + " | "
str += "OS:" + e.SysInfo["host.os"] + " | "
str += "Arch:" + e.SysInfo["host.arch"] + " | "
str += "Lang:" + e.SysInfo["host.lang"] + " | "