minitrace

package module
v0.0.0-...-dee15e7 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

minitrace-go

Basic Usage

package main

import (
    "fmt"
    "context"
    "github.com/zhongzc/minitrace-go"
)

func tracedFunc(ctx context.Context, event uint32) {
    span := minitrace.NewSpan(ctx, event)
    // code snippet...
    span.Finish()
}

func iterTracedFunc(ctx context.Context) {
    // extend tracing context from parent context
    ctx, span := minitrace.NewSpanWithContext(ctx, 1)

    for i := 2; i < 10; i++ {
        tracedFunc(ctx, uint32(i))
    }
    
    span.Finish()
}

func main() {
    ctx := context.Background()

    // enable tracing
    ctx, root := minitrace.TraceEnable(ctx, 0)

    // pass the context to traced functions
    iterTracedFunc(ctx)

    // collect tracing results into `spanSets`
    spanSets := root.Collect()

    // do something with `spanSets`
    fmt.Printf("%+v", spanSets)
}

Documentation

Index

Constants

View Source
const POW = 8

Variables

This section is empty.

Functions

This section is empty.

Types

type Span

type Span struct {
	Id      uint32
	Parent  uint32
	BeginNs uint64
	EndNs   uint64
	Event   uint32
}

type SpanHandle

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

func NewSpan

func NewSpan(ctx context.Context, event uint32) (res SpanHandle)

func NewSpanWithContext

func NewSpanWithContext(ctx context.Context, event uint32) (context.Context, SpanHandle)

func (*SpanHandle) Finish

func (hd *SpanHandle) Finish()

type SpanSet

type SpanSet struct {
	StartTimeNs uint64
	Spans       []Span
}

type TraceHandle

type TraceHandle struct {
	SpanHandle
}

func TraceEnable

func TraceEnable(ctx context.Context, event uint32) (context.Context, TraceHandle)

func (TraceHandle) Collect

func (hd TraceHandle) Collect() (res []SpanSet)

Jump to

Keyboard shortcuts

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