sysdigtracers

package module
v0.0.0-...-40637d2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: MIT Imports: 3 Imported by: 0

README

sysdigtracers

Add sysdig tracers in your Go code easily

sysdig tracers documentation

https://github.com/draios/sysdig/wiki/Tracers

usage

  • Fetch and install package :
go get github.com/Issif/sysdigtracers
  • Import package, add in your code :
import github.com/Issif/sysdigtracers
  • Idiomatic way is to add at beginning of each function you want to trace :
t:= sysdigtracers.Entry("id", "tags", "args")
defer t.Exit("args")
func myFunction() {
//... some stuff ...
t := sysdigtracers.Entry("", "")
//... some stuff ...
t.Exit()
//... some stuff ...
}

example

Inspired by : https://rosettacode.org/wiki/Mandelbrot_set#Go

package main

import (
	"fmt"
	"math/cmplx"

	"github.com/Issif/sysdigtracers"
)

func mandelbrot(a complex128) (z complex128) {
	t := sysdigtracers.Entry("", "")
	defer t.Exit("")
	for i := 0; i < 50; i++ {
		z = z*z + a
	}
	return
}

func main() {
	for y := 1.0; y >= -1.0; y -= 0.05 {
		for x := -2.0; x <= 0.5; x += 0.0315 {
			if cmplx.Abs(mandelbrot(complex(x, y))) < 2 {
				fmt.Print("*")
			} else {
				fmt.Print(" ")
			}
		}
		fmt.Println("")
	}
}
~# sysdig evt.type=tracer

330655 11:38:17.059175478 1 mandelbrot (3034) > tracer id=0 tags=main.mandelbrot args=
330681 11:38:17.059254204 1 mandelbrot (3034) < tracer id=0 tags=main.mandelbrot args=
330718 11:38:17.059373437 1 mandelbrot (3034) > tracer id=0 tags=main.mandelbrot args=
330737 11:38:17.059472125 1 mandelbrot (3034) < tracer id=0 tags=main.mandelbrot args=
330772 11:38:17.059605109 1 mandelbrot (3034) > tracer id=0 tags=main.mandelbrot args=
330802 11:38:17.059685106 1 mandelbrot (3034) < tracer id=0 tags=main.mandelbrot args=
330839 11:38:17.059828369 1 mandelbrot (3034) > tracer id=0 tags=main.mandelbrot args=

Documentation

Overview

Package sysdigtracers let you add easily sysdig tracers (https://github.com/draios/sysdig/wiki/Tracers) in your Go code.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracer

type Tracer struct {
	Id   string // Id string should be a 64bit integer or t, p, pp or empty (see: https://github.com/draios/sysdig/wiki/Tracers#fields-explanation).
	Tags string // Tags string should be a list of one or more strings separated by periods. if empty, name of caller function is set.
	Args string // Args string is a list of key-value pairs to be associated with the tracer (optionnal).
}

Tracer represents a tracer

func Entry

func Entry(id, tags string, args ...string) Tracer

Entry emits an entry event in /dev/null and returns a tracer struct. id and elements can be empty strings. first string in elements will be used as tags, other strings will be arguments. if elements is empty (no tag), name of caller function is set.

Example

Idiomatic way to add a tracer.

package main

import (
	"sysdigtracers"
)

func main() {
	t := sysdigtracers.Entry("id", "tags", "args")
	defer t.Exit("args")
}
Example (Goroutine)

Add a tracer in a sublevel goroutine.

package main

import (
	"sysdigtracers"
)

func main() {
	//... some stuff ...
	t := sysdigtracers.Entry("", "root")
	go func() {
		u := sysdigtracers.Entry("", "root.goroutine")
		defer u.Exit()
		//... some stuff ...
	}()
	t.Exit()
	//... some stuff ...
}
Example (Other)

Add a tracer anywhere.

package main

import (
	"sysdigtracers"
)

func main() {
	//... some stuff ...
	t := sysdigtracers.Entry("", "")
	//... some stuff ...
	t.Exit()
	//... some stuff ...
}

func (Tracer) Exit

func (t Tracer) Exit(args ...string)

Exit emits an exit event in /dev/null. args can be empty, if not, args of tracer are overrided by it.

Jump to

Keyboard shortcuts

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