tracing

package
v0.0.0-...-6e93ed8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const TiDBTrace = "tr"

TiDBTrace is set as Baggage on traces which are used for tidb tracing.

Variables

This section is empty.

Functions

func ChildSpanFromContxt

func ChildSpanFromContxt(ctx context.Context, opName string) (opentracing.Span, context.Context)

ChildSpanFromContxt return a non-nil span. If span can be got from ctx, then returned span is a child of such span. Otherwise, returned span is a noop span.

func CodecPlanName

func CodecPlanName(tp string, id int) string

CodecPlanName returns tp_id of plan.

func ContextWithTraceInfo

func ContextWithTraceInfo(ctx context.Context, info *model.TraceInfo) context.Context

ContextWithTraceInfo creates a new `model.TraceInfo` for context

func NewRecordedTrace

func NewRecordedTrace(opName string, callback func(sp basictracer.RawSpan)) opentracing.Span

NewRecordedTrace returns a Span which records directly via the specified callback.

func SpanFromContext

func SpanFromContext(ctx context.Context) (sp opentracing.Span)

SpanFromContext returns the span obtained from the context or, if none is found, a new one started through tracer.

func TraceInfoFromContext

func TraceInfoFromContext(ctx context.Context) *model.TraceInfo

TraceInfoFromContext returns the `model.TraceInfo` in context

Types

type CETraceRecord

type CETraceRecord struct {
	TableName string `json:"table_name"`
	Type      string `json:"type"`
	Expr      string `json:"expr"`
	TableID   int64  `json:"-"`
	RowCount  uint64 `json:"row_count"`
}

CETraceRecord records an expression and related cardinality estimation result.

func DedupCETrace

func DedupCETrace(records []*CETraceRecord) []*CETraceRecord

DedupCETrace deduplicate a slice of *CETraceRecord and return the deduplicated slice

type CallbackRecorder

type CallbackRecorder func(sp basictracer.RawSpan)

A CallbackRecorder immediately invokes itself on received trace spans.

func (CallbackRecorder) RecordSpan

func (cr CallbackRecorder) RecordSpan(sp basictracer.RawSpan)

RecordSpan implements basictracer.SpanRecorder.

type CandidatePlanTrace

type CandidatePlanTrace struct {
	*PlanTrace
	MappingLogicalPlan string `json:"mapping"`
}

CandidatePlanTrace indicates info for candidate

type LogicalOptimizeTracer

type LogicalOptimizeTracer struct {
	FinalLogicalPlan []*PlanTrace                 `json:"final"`
	Steps            []*LogicalRuleOptimizeTracer `json:"steps"`
	// contains filtered or unexported fields
}

LogicalOptimizeTracer indicates the trace for the whole logicalOptimize processing

func (*LogicalOptimizeTracer) AppendRuleTracerBeforeRuleOptimize

func (tracer *LogicalOptimizeTracer) AppendRuleTracerBeforeRuleOptimize(index int, name string, before *PlanTrace)

AppendRuleTracerBeforeRuleOptimize add plan tracer before optimize

func (*LogicalOptimizeTracer) AppendRuleTracerStepToCurrent

func (tracer *LogicalOptimizeTracer) AppendRuleTracerStepToCurrent(id int, tp, reason, action string)

AppendRuleTracerStepToCurrent add rule optimize step to current

func (*LogicalOptimizeTracer) RecordFinalLogicalPlan

func (tracer *LogicalOptimizeTracer) RecordFinalLogicalPlan(final *PlanTrace)

RecordFinalLogicalPlan add plan trace after logical optimize

type LogicalRuleOptimizeTraceStep

type LogicalRuleOptimizeTraceStep struct {
	Action string `json:"action"`
	Reason string `json:"reason"`
	TP     string `json:"type"`
	ID     int    `json:"id"`
	Index  int    `json:"index"`
}

LogicalRuleOptimizeTraceStep indicates the trace for the detailed optimize changing in logical rule optimize

type LogicalRuleOptimizeTracer

type LogicalRuleOptimizeTracer struct {
	RuleName string                         `json:"name"`
	Before   []*PlanTrace                   `json:"before"`
	Steps    []LogicalRuleOptimizeTraceStep `json:"steps"`
	Index    int                            `json:"index"`
}

LogicalRuleOptimizeTracer indicates the trace for the LogicalPlan tree before and after logical rule optimize

type OptimizeTracer

type OptimizeTracer struct {
	// Logical indicates logical plan
	Logical *LogicalOptimizeTracer `json:"logical"`
	// Physical indicates physical plan
	Physical *PhysicalOptimizeTracer `json:"physical"`
	// FinalPlan indicates the plan after post optimize
	FinalPlan []*PlanTrace `json:"final"`
	// IsFastPlan indicates whether the plan is generated by fast plan
	IsFastPlan bool `json:"isFastPlan"`
}

OptimizeTracer indicates tracer for optimizer

func (*OptimizeTracer) RecordFinalPlan

func (tracer *OptimizeTracer) RecordFinalPlan(final *PlanTrace)

RecordFinalPlan records plan after post optimize

func (*OptimizeTracer) SetFastPlan

func (tracer *OptimizeTracer) SetFastPlan(final *PlanTrace)

SetFastPlan sets fast plan

type PhysicalOptimizeTracer

type PhysicalOptimizeTracer struct {
	PhysicalPlanCostDetails map[string]*PhysicalPlanCostDetail `json:"costs"`
	Candidates              map[int]*CandidatePlanTrace        `json:"candidates"`
	// final indicates the final physical plan trace
	Final []*PlanTrace `json:"final"`
}

PhysicalOptimizeTracer indicates the trace for the whole physicalOptimize processing

func (*PhysicalOptimizeTracer) AppendCandidate

func (tracer *PhysicalOptimizeTracer) AppendCandidate(c *CandidatePlanTrace)

AppendCandidate appends physical CandidatePlanTrace in tracer. If the candidate already exists, the previous candidate would be covered depends on whether it has mapping logical plan

func (*PhysicalOptimizeTracer) RecordFinalPlanTrace

func (tracer *PhysicalOptimizeTracer) RecordFinalPlanTrace(root *PlanTrace)

RecordFinalPlanTrace records final physical plan trace

type PhysicalPlanCostDetail

type PhysicalPlanCostDetail struct {
	Params map[string]any `json:"params"`
	TP     string         `json:"type"`
	Desc   string         `json:"desc"`
	ID     int            `json:"id"`
	Cost   float64        `json:"cost"`
}

PhysicalPlanCostDetail indicates cost detail

func NewPhysicalPlanCostDetail

func NewPhysicalPlanCostDetail(id int, tp string) *PhysicalPlanCostDetail

NewPhysicalPlanCostDetail creates a cost detail

func (*PhysicalPlanCostDetail) AddParam

AddParam adds param

func (*PhysicalPlanCostDetail) Exists

func (d *PhysicalPlanCostDetail) Exists(k string) bool

Exists checks whether key exists in params

func (*PhysicalPlanCostDetail) GetPlanID

func (d *PhysicalPlanCostDetail) GetPlanID() int

GetPlanID gets plan id

func (*PhysicalPlanCostDetail) GetPlanType

func (d *PhysicalPlanCostDetail) GetPlanType() string

GetPlanType gets plan type

func (*PhysicalPlanCostDetail) SetDesc

func (d *PhysicalPlanCostDetail) SetDesc(desc string)

SetDesc sets desc

type PhysicalPlanCostParam

type PhysicalPlanCostParam struct {
	Params map[string]any `json:"params"`
	Name   string         `json:"name"`
	Desc   string         `json:"desc"`
	ID     int            `json:"id"`
	Cost   float64        `json:"cost"`
}

PhysicalPlanCostParam indicates cost params

type PlanTrace

type PlanTrace struct {
	TP         string `json:"type"`
	ProperType string `json:"property"`
	// ExplainInfo should be implemented by each implemented Plan
	ExplainInfo string       `json:"info"`
	Children    []*PlanTrace `json:"-"`
	ChildrenID  []int        `json:"children"`
	ID          int          `json:"id"`
	Cost        float64      `json:"cost"`
	Selected    bool         `json:"selected"`
	// contains filtered or unexported fields
}

PlanTrace indicates for the Plan trace information

func (*PlanTrace) AppendChildrenID

func (p *PlanTrace) AppendChildrenID(ids ...int)

AppendChildrenID appends children ids

type Region

type Region struct {
	*trace.Region
	opentracing.Span
}

Region is a region of code whose execution time interval is traced.

func StartRegion

func StartRegion(ctx context.Context, regionType string) Region

StartRegion provides better API, integrating both opentracing and runtime.trace facilities into one. Recommended usage is

defer tracing.StartRegion(ctx, "myTracedRegion").End()

func StartRegionEx

func StartRegionEx(ctx context.Context, regionType string) (Region, context.Context)

StartRegionEx returns Region together with the context. Recommended usage is

	r, ctx := tracing.StartRegionEx(ctx, "myTracedRegion")
     defer r.End()

func StartRegionWithNewRootSpan

func StartRegionWithNewRootSpan(ctx context.Context, regionType string) (Region, context.Context)

StartRegionWithNewRootSpan return Region together with the context. It create and start a new span by globalTracer and store it into `ctx`.

func (Region) End

func (r Region) End()

End marks the end of the traced code region.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL