Add more documentation for probe

master
Harshavardhana 9 years ago
parent f4bd7b151c
commit 03ef6533c8
  1. 40
      pkg/probe/probe.go

@ -50,11 +50,12 @@ func GetSysInfo() map[string]string {
} }
} }
// TracePoint container for individual trace entries in overall call trace
type TracePoint struct { type TracePoint struct {
Line int `json:"Line,omitempty"` Line int `json:"line,omitempty"`
Filename string `json:"File,omitempty"` Filename string `json:"file,omitempty"`
Function string `json:"Func,omitempty"` Function string `json:"func,omitempty"`
Env map[string][]string `json:"Env,omitempty"` Env map[string][]string `json:"env,omitempty"`
} }
// Error implements tracing error functionality. // Error implements tracing error functionality.
@ -65,10 +66,24 @@ type Error struct {
SysInfo map[string]string `json:"sysinfo,omitempty"` SysInfo map[string]string `json:"sysinfo,omitempty"`
} }
// NewError function instantiates an error probe for tracing. Original errors.error (golang's error // NewError function instantiates an error probe for tracing.
// interface) is injected in only once during this New call. Rest of the time, you // Default ``error`` (golang's error interface) is injected in
// trace the return path with Probe.Trace and finally handle reporting or quitting // only once. Rest of the time, you trace the return path with
// at the top level. // ``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 { func NewError(e error) *Error {
if e == nil { if e == nil {
return nil return nil
@ -77,8 +92,8 @@ func NewError(e error) *Error {
return Err.trace() return Err.trace()
} }
// Trace records the point at which it is invoked. Stack traces are important for // Trace records the point at which it is invoked.
// debugging purposes. // Stack traces are important for debugging purposes.
func (e *Error) Trace(fields ...string) *Error { func (e *Error) Trace(fields ...string) *Error {
if e == nil { if e == nil {
return nil return nil
@ -90,8 +105,7 @@ func (e *Error) Trace(fields ...string) *Error {
return e.trace(fields...) return e.trace(fields...)
} }
// internal trace - records the point at which it is invoked. Stack traces are important for // Internal trace - records the point at which it is invoked.
// debugging purposes.
func (e *Error) trace(fields ...string) *Error { func (e *Error) trace(fields ...string) *Error {
pc, file, line, _ := runtime.Caller(2) pc, file, line, _ := runtime.Caller(2)
function := runtime.FuncForPC(pc).Name() function := runtime.FuncForPC(pc).Name()
@ -107,7 +121,7 @@ func (e *Error) trace(fields ...string) *Error {
return e return e
} }
// Untrace erases last trace entry. // Untrace erases last known trace entry.
func (e *Error) Untrace() *Error { func (e *Error) Untrace() *Error {
if e == nil { if e == nil {
return nil return nil

Loading…
Cancel
Save