tracing

package
v4.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package tracing help simulator users to trace what is happening in the simulation.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	HookPosTaskStart = &sim.HookPos{Name: "HookPosTaskStart"}
	HookPosTaskStep  = &sim.HookPos{Name: "HookPosTaskStep"}
	HookPosTaskEnd   = &sim.HookPos{Name: "HookPosTaskEnd"}
)

A list of hook poses for the hooks to apply to

Functions

func AddTaskStep

func AddTaskStep(
	id string,
	domain NamedHookable,
	what string,
)

AddTaskStep marks that a milestone has been reached when processing a task.

func CollectTrace

func CollectTrace(domain NamedHookable, tracer Tracer)

CollectTrace let the tracer to collect trace from a domain

func EndTask

func EndTask(
	id string,
	domain NamedHookable,
)

EndTask notifies the hooks about the end of a task.

func EndTask2

func EndTask2(
	id string,
	domain NamedHookable,
	detail interface{},
)

func MsgIDAtReceiver

func MsgIDAtReceiver(msg sim.Msg, domain NamedHookable) string

MsgIDAtReceiver generates a standard ID for the message task at the message receiver.

func StartTask

func StartTask(
	id string,
	parentID string,
	domain NamedHookable,
	kind string,
	what string,
	detail interface{},
)

StartTask notifies the hooks that hook to the domain about the start of a task.

func StartTaskWithSpecificLocation

func StartTaskWithSpecificLocation(
	id string,
	parentID string,
	domain NamedHookable,
	kind string,
	what string,
	location string,
	detail interface{},
)

StartTaskWithSpecificLocation notifies the hooks that hook to the domain about the start of a task, and is able to customize `where` field of a task, especially for network tracing.

func TraceReqComplete

func TraceReqComplete(
	msg sim.Msg,
	domain NamedHookable,
)

TraceReqComplete terminates the message handling task.

func TraceReqFinalize

func TraceReqFinalize(
	msg sim.Msg,
	domain NamedHookable,
)

TraceReqFinalize terminates the message task. This function should be called when the sender receives the response.

func TraceReqInitiate

func TraceReqInitiate(
	msg sim.Msg,
	domain NamedHookable,
	taskParentID string,
)

TraceReqInitiate generatse a new task. The new task has Type="req_out", What=[the type name of the message]. This function is to be called by the sender of the message.

func TraceReqReceive

func TraceReqReceive(
	msg sim.Msg,
	domain NamedHookable,
)

TraceReqReceive generates a new task for the message handling. The kind of the task is always "req_in".

Types

type AverageTimeTracer

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

AverageTimeTracer can collect the total time of executing a certain type of task. If the execution of two tasks overlaps, this tracer will simply add the two task processing time together.

func NewAverageTimeTracer

func NewAverageTimeTracer(
	timeTeller sim.TimeTeller,
	filter TaskFilter,
) *AverageTimeTracer

NewAverageTimeTracer creates a new AverageTimeTracer

func (*AverageTimeTracer) AverageTime

func (t *AverageTimeTracer) AverageTime() sim.VTimeInSec

AverageTime returns the total time has been spent on a certain type of tasks.

func (*AverageTimeTracer) EndTask

func (t *AverageTimeTracer) EndTask(task Task)

EndTask records the end of the task

func (*AverageTimeTracer) StartTask

func (t *AverageTimeTracer) StartTask(task Task)

StartTask records the task start time

func (*AverageTimeTracer) StepTask

func (t *AverageTimeTracer) StepTask(task Task)

StepTask does nothing

func (*AverageTimeTracer) TotalCount

func (t *AverageTimeTracer) TotalCount() uint64

TotalCount returns the total number of tasks.

type BusyTimeTracer

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

BusyTimeTracer traces the that a domain is processing a kind of task. If the task processing time overlaps, this tracer only consider one instance of the overlapped time.

func NewBusyTimeTracer

func NewBusyTimeTracer(
	timeTeller sim.TimeTeller,
	filter TaskFilter,
) *BusyTimeTracer

NewBusyTimeTracer creates a new BusyTimeTracer

func (*BusyTimeTracer) BusyTime

func (t *BusyTimeTracer) BusyTime() sim.VTimeInSec

BusyTime returns the total time has been spent on a certain type of tasks.

func (*BusyTimeTracer) EndTask

func (t *BusyTimeTracer) EndTask(task Task)

EndTask records the end of the task

func (*BusyTimeTracer) StartTask

func (t *BusyTimeTracer) StartTask(task Task)

StartTask records the task start time

func (*BusyTimeTracer) StepTask

func (t *BusyTimeTracer) StepTask(task Task)

StepTask does nothing

func (*BusyTimeTracer) TerminateAllTasks

func (t *BusyTimeTracer) TerminateAllTasks(now sim.VTimeInSec)

TerminateAllTasks will mark all the tasks as completed.

type JSONTracer

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

JSONTracer can write tasks into json format.

func NewJSONTracer

func NewJSONTracer() *JSONTracer

NewJSONTracer creates a new JsonTracer, injecting a writer as dependency.

func (*JSONTracer) EndTask

func (t *JSONTracer) EndTask(task Task)

EndTask records the time that a task is completed.

func (*JSONTracer) StartTask

func (t *JSONTracer) StartTask(task Task)

StartTask records the start of a task

func (*JSONTracer) StepTask

func (t *JSONTracer) StepTask(task Task)

StepTask records the moment that a task reaches a milestone

type MongoDBTracer

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

MongoDBTracer is a tracer that can dump the tasks into a MongoDB database.

func NewMongoDBTracer

func NewMongoDBTracer() *MongoDBTracer

NewMongoDBTracer returns a new MongoDBTracer

func (*MongoDBTracer) EndTask

func (t *MongoDBTracer) EndTask(task Task)

EndTask writes the task into the database.

func (*MongoDBTracer) Init

func (t *MongoDBTracer) Init()

Init connects to the MongoDB database.

func (*MongoDBTracer) SetURI

func (t *MongoDBTracer) SetURI(uri string)

SetURI sets the server and the port to connect to

func (*MongoDBTracer) StartTask

func (t *MongoDBTracer) StartTask(task Task)

StartTask marks the start of a task.

func (*MongoDBTracer) StepTask

func (t *MongoDBTracer) StepTask(task Task)

StepTask marks a milestone during the executing of a task.

type MySQLTracer

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

MySQLTracer is a task tracer that can store the tasks into a MySQL database.

func NewMySQLTracer

func NewMySQLTracer(timeTeller sim.TimeTeller) *MySQLTracer

NewMySQLTracer returns a new MySQLTracer.

func NewMySQLTracerWithTimeRange

func NewMySQLTracerWithTimeRange(
	timeTeller sim.TimeTeller,
	startTime, endTime sim.VTimeInSec,
) *MySQLTracer

NewMySQLTracerWithTimeRange creates a MySQLTracer which can only trace the tasks that at least partially overlaps with the given start and end time. If the start time is negative, the tracer will start tracing at the beginning of the simulation. If the end time is negative, the tracer will not stop tracing until the end of the simulation.

func (*MySQLTracer) EndTask

func (t *MySQLTracer) EndTask(task Task)

EndTask writes the task into the database.

func (*MySQLTracer) Init

func (t *MySQLTracer) Init()

Init establishes a connection to MySQL and creates a database.

func (*MySQLTracer) StartTask

func (t *MySQLTracer) StartTask(task Task)

StartTask marks the start of a task.

func (*MySQLTracer) StepTask

func (t *MySQLTracer) StepTask(task Task)

StepTask marks a milestone during the execution of a task.

type NamedHookable

type NamedHookable interface {
	sim.Named
	sim.Hookable
	InvokeHook(sim.HookCtx)
}

NamedHookable represent something both have a name and can be hooked

type StepCountTracer

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

StepCountTracer can collect the total time of a certain step is triggerred.

func NewStepCountTracer

func NewStepCountTracer(filter TaskFilter) *StepCountTracer

NewStepCountTracer creates a new StepCountTracer

func (*StepCountTracer) EndTask

func (t *StepCountTracer) EndTask(task Task)

EndTask records the end of the task

func (*StepCountTracer) GetStepCount

func (t *StepCountTracer) GetStepCount(stepName string) uint64

GetStepCount returns the number of steps that is recorded with a certain step name.

func (*StepCountTracer) GetStepNames

func (t *StepCountTracer) GetStepNames() []string

GetStepNames returns all the step names collected.

func (*StepCountTracer) GetTaskCount

func (t *StepCountTracer) GetTaskCount(stepName string) uint64

GetTaskCount returns the number of tasks that is recorded to have a certain step with a given name.

func (*StepCountTracer) StartTask

func (t *StepCountTracer) StartTask(task Task)

StartTask records the task start time

func (*StepCountTracer) StepTask

func (t *StepCountTracer) StepTask(task Task)

StepTask does nothing

type Task

type Task struct {
	ID        string         `json:"id"`
	ParentID  string         `json:"parent_id"`
	Kind      string         `json:"kind"`
	What      string         `json:"what"`
	Where     string         `json:"where"`
	StartTime sim.VTimeInSec `json:"start_time"`
	EndTime   sim.VTimeInSec `json:"end_time"`
	Steps     []TaskStep     `json:"steps"`
	Detail    interface{}    `json:"-"`
}

A Task is a task

type TaskFilter

type TaskFilter func(t Task) bool

TaskFilter is a function that can filter interesting tasks. If this function returns true, the task is considered useful.

type TaskStep

type TaskStep struct {
	Time sim.VTimeInSec `json:"time"`
	What string         `json:"what"`
}

A TaskStep represents a milestone in the processing of task

type TotalTimeTracer

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

TotalTimeTracer can collect the total time of executing a certain type of task. If the execution of two tasks overlaps, this tracer will simply add the two task processing time together.

func NewTotalTimeTracer

func NewTotalTimeTracer(
	timeTeller sim.TimeTeller,
	filter TaskFilter,
) *TotalTimeTracer

NewTotalTimeTracer creates a new TotalTimeTracer

func (*TotalTimeTracer) EndTask

func (t *TotalTimeTracer) EndTask(task Task)

EndTask records the end of the task

func (*TotalTimeTracer) StartTask

func (t *TotalTimeTracer) StartTask(task Task)

StartTask records the task start time

func (*TotalTimeTracer) StepTask

func (t *TotalTimeTracer) StepTask(task Task)

StepTask does nothing

func (*TotalTimeTracer) TotalTime

func (t *TotalTimeTracer) TotalTime() sim.VTimeInSec

TotalTime returns the total time has been spent on a certain type of tasks.

type Tracer

type Tracer interface {
	StartTask(task Task)
	StepTask(task Task)
	EndTask(task Task)
}

A Tracer can collect task traces

Example

Example for how to use standard tracers

package main

import (
	"fmt"

	"gitlab.com/akita/akita/v3/sim"
	"gitlab.com/akita/akita/v3/tracing"
)

type SampleTimeTeller struct {
	time sim.VTimeInSec
}

func (t *SampleTimeTeller) CurrentTime() sim.VTimeInSec {
	return t.time
}

type SampleDomain struct {
	*sim.HookableBase
	timeTeller sim.TimeTeller
	taskIDs    []int
	nextID     int
}

func (d *SampleDomain) Name() string {
	return "sample domain"
}

func (d *SampleDomain) Start() {
	tracing.StartTask(
		fmt.Sprintf("%d", d.nextID),
		"",
		d,
		"sampleTaskKind",
		"something",
		nil,
	)
	d.taskIDs = append(d.taskIDs, d.nextID)

	d.nextID++
}

func (d *SampleDomain) End() {
	tracing.EndTask(
		fmt.Sprintf("%d", d.taskIDs[0]),
		d,
	)
	d.taskIDs = d.taskIDs[1:]
}

// Example for how to use standard tracers
func main() {
	timeTeller := &SampleTimeTeller{}
	domain := &SampleDomain{
		HookableBase: sim.NewHookableBase(),
		timeTeller:   timeTeller,
	}

	filter := func(t tracing.Task) bool {
		return t.Kind == "sampleTaskKind"
	}

	totalTimeTracer := tracing.NewTotalTimeTracer(timeTeller, filter)
	busyTimeTracer := tracing.NewBusyTimeTracer(timeTeller, filter)
	avgTimeTracer := tracing.NewAverageTimeTracer(timeTeller, filter)
	tracing.CollectTrace(domain, totalTimeTracer)
	tracing.CollectTrace(domain, busyTimeTracer)
	tracing.CollectTrace(domain, avgTimeTracer)

	timeTeller.time = 1
	domain.Start()
	timeTeller.time = 1.5
	domain.Start()
	timeTeller.time = 2
	domain.End()
	timeTeller.time = 3
	domain.End()

	fmt.Println(totalTimeTracer.TotalTime())
	fmt.Println(busyTimeTracer.BusyTime())
	fmt.Println(avgTimeTracer.AverageTime())

}
Output:

2.5
2
1.25

Jump to

Keyboard shortcuts

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