trace

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithTimer

func ContextWithTimer(ctx context.Context, t *Timer) context.Context

ContextWithTimer 将 Timer 存入 context,返回新的 context。

func MarkFrom

func MarkFrom(ctx context.Context, name string)

MarkFrom 便捷方法:从 context 中取 Timer 并记录标记。 Timer 不存在时什么都不做。

Types

type Stage

type Stage struct {
	From string
	To   string
	Cost time.Duration
}

Stage 表示两个标记之间的耗时阶段。

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer 用于在请求生命周期中记录各阶段时间标记并统计耗时。

func NewTimer

func NewTimer() *Timer

NewTimer 创建一个新的 Timer 实例。

func TimerFrom

func TimerFrom(ctx context.Context) *Timer

TimerFrom 从 context 中提取 Timer,不存在时返回 nil。

func (*Timer) Mark

func (t *Timer) Mark(name string)

Mark 记录一个时间标记。

func (*Timer) Stages

func (t *Timer) Stages() []Stage

Stages 返回按时间排序的各阶段耗时(相邻两个标记之间的间隔)。

func (*Timer) StagesFrom

func (t *Timer) StagesFrom(name string) []Stage

StagesFrom 返回从指定标记开始的各阶段耗时。 如果标记名不存在,返回 nil。

func (*Timer) Summary

func (t *Timer) Summary() string

Summary 返回一个格式化的耗时摘要字符串。

func (*Timer) Total

func (t *Timer) Total() time.Duration

Total 返回从第一个标记到最后一个标记的总耗时。 无标记时返回 0,仅一个标记时返回 0。

Jump to

Keyboard shortcuts

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