Refactored op descriptions again.
parent
6868642c96
commit
d31b0cbd81
|
@ -39,8 +39,7 @@ var fTraceByPID = flag.Bool(
|
||||||
// A helper for embedding common behavior.
|
// A helper for embedding common behavior.
|
||||||
type commonOp struct {
|
type commonOp struct {
|
||||||
// The op in which this struct is embedded, and a short description of it.
|
// The op in which this struct is embedded, and a short description of it.
|
||||||
op Op
|
op Op
|
||||||
opDesc string
|
|
||||||
|
|
||||||
// The underlying bazilfuse request for this op.
|
// The underlying bazilfuse request for this op.
|
||||||
bazilReq bazilfuse.Request
|
bazilReq bazilfuse.Request
|
||||||
|
@ -54,23 +53,6 @@ type commonOp struct {
|
||||||
report reqtrace.ReportFunc
|
report reqtrace.ReportFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func describeOp(op Op) (desc string) {
|
|
||||||
name := reflect.TypeOf(op).String()
|
|
||||||
|
|
||||||
// The usual case: a string that looks like "*fuseops.GetInodeAttributesOp".
|
|
||||||
const prefix = "*fuseops."
|
|
||||||
const suffix = "Op"
|
|
||||||
if strings.HasPrefix(name, prefix) && strings.HasSuffix(name, suffix) {
|
|
||||||
desc = name[len(prefix) : len(name)-len(suffix)]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, it's not clear what to do.
|
|
||||||
desc = name
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var gPIDMapMu sync.Mutex
|
var gPIDMapMu sync.Mutex
|
||||||
|
|
||||||
// A map from PID to a traced context for that PID.
|
// A map from PID to a traced context for that PID.
|
||||||
|
@ -149,6 +131,23 @@ func (o *commonOp) maybeTraceByPID(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *commonOp) ShortDesc() (desc string) {
|
||||||
|
name := reflect.TypeOf(o.op).String()
|
||||||
|
|
||||||
|
// The usual case: a string that looks like "*fuseops.GetInodeAttributesOp".
|
||||||
|
const prefix = "*fuseops."
|
||||||
|
const suffix = "Op"
|
||||||
|
if strings.HasPrefix(name, prefix) && strings.HasSuffix(name, suffix) {
|
||||||
|
desc = name[len(prefix) : len(name)-len(suffix)]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, it's not clear what to do.
|
||||||
|
desc = name
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (o *commonOp) init(
|
func (o *commonOp) init(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
op Op,
|
op Op,
|
||||||
|
@ -160,13 +159,12 @@ func (o *commonOp) init(
|
||||||
|
|
||||||
// Initialize basic fields.
|
// Initialize basic fields.
|
||||||
o.op = op
|
o.op = op
|
||||||
o.opDesc = describeOp(op)
|
|
||||||
o.bazilReq = bazilReq
|
o.bazilReq = bazilReq
|
||||||
o.log = log
|
o.log = log
|
||||||
o.opsInFlight = opsInFlight
|
o.opsInFlight = opsInFlight
|
||||||
|
|
||||||
// Set up a trace span for this op.
|
// Set up a trace span for this op.
|
||||||
o.ctx, o.report = reqtrace.StartSpan(ctx, o.opDesc)
|
o.ctx, o.report = reqtrace.StartSpan(ctx, o.ShortDesc())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *commonOp) Header() OpHeader {
|
func (o *commonOp) Header() OpHeader {
|
||||||
|
@ -195,7 +193,7 @@ func (o *commonOp) respondErr(err error) {
|
||||||
|
|
||||||
o.Logf(
|
o.Logf(
|
||||||
"-> (%s) error: %v",
|
"-> (%s) error: %v",
|
||||||
o.opDesc,
|
o.ShortDesc(),
|
||||||
err)
|
err)
|
||||||
|
|
||||||
o.bazilReq.RespondError(err)
|
o.bazilReq.RespondError(err)
|
||||||
|
@ -215,7 +213,7 @@ func (o *commonOp) respond(resp interface{}) {
|
||||||
|
|
||||||
// Special case: handle successful ops with no response struct.
|
// Special case: handle successful ops with no response struct.
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
o.Logf("-> (%s) OK", o.opDesc)
|
o.Logf("-> (%s) OK", o.ShortDesc())
|
||||||
respond.Call([]reflect.Value{})
|
respond.Call([]reflect.Value{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,9 @@ import (
|
||||||
// to find particular concrete types, responding with fuse.ENOSYS if a type is
|
// to find particular concrete types, responding with fuse.ENOSYS if a type is
|
||||||
// not supported.
|
// not supported.
|
||||||
type Op interface {
|
type Op interface {
|
||||||
|
// A short description of the op, to be used in logging.
|
||||||
|
ShortDesc() string
|
||||||
|
|
||||||
// Return the fields common to all operations.
|
// Return the fields common to all operations.
|
||||||
Header() OpHeader
|
Header() OpHeader
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue