Documentation
¶
Overview ¶
Package tracing help simulator users to trace what is happening in the simulation.
Index ¶
- Variables
- func AddTaskStep(id string, now akita.VTimeInSec, domain NamedHookable, what string)
- func CollectTrace(domain NamedHookable, tracer Tracer)
- func EndTask(id string, now akita.VTimeInSec, domain NamedHookable)
- func MsgIDAtReceiver(msg akita.Msg, domain NamedHookable) string
- func StartTask(id string, parentID string, now akita.VTimeInSec, domain NamedHookable, ...)
- func TraceReqComplete(msg akita.Msg, now akita.VTimeInSec, domain NamedHookable)
- func TraceReqFinalize(msg akita.Msg, now akita.VTimeInSec, domain NamedHookable)
- func TraceReqInitiate(msg akita.Msg, now akita.VTimeInSec, domain NamedHookable, taskParentID string)
- func TraceReqReceive(msg akita.Msg, now akita.VTimeInSec, domain NamedHookable)
- type AverageTimeTracer
- type BusyTimeTracer
- type JSONTracer
- type MongoDBTracer
- type MySQLTracer
- type NamedHookable
- type StepCountTracer
- func (t *StepCountTracer) EndTask(task Task)
- func (t *StepCountTracer) GetStepCount(stepName string) uint64
- func (t *StepCountTracer) GetStepNames() []string
- func (t *StepCountTracer) GetTaskCount(stepName string) uint64
- func (t *StepCountTracer) StartTask(task Task)
- func (t *StepCountTracer) StepTask(task Task)
- type Task
- type TaskFilter
- type TaskStep
- type TotalTimeTracer
- type Tracer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( HookPosTaskStart = &akita.HookPos{Name: "HookPosTaskStart"} HookPosTaskStep = &akita.HookPos{Name: "HookPosTaskStep"} HookPosTaskEnd = &akita.HookPos{Name: "HookPosTaskEnd"} )
A list of hook poses for the hooks to apply to
Functions ¶
func AddTaskStep ¶
func AddTaskStep( id string, now akita.VTimeInSec, 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, now akita.VTimeInSec, domain NamedHookable, )
EndTask notifies the hooks about the end of a task.
func MsgIDAtReceiver ¶
func MsgIDAtReceiver(msg akita.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, now akita.VTimeInSec, domain NamedHookable, kind string, what string, detail interface{}, )
StartTask notifies the hooks that hook to the domain about the start of a task.
func TraceReqComplete ¶
func TraceReqComplete( msg akita.Msg, now akita.VTimeInSec, domain NamedHookable, )
TraceReqComplete terminates the message handling task.
func TraceReqFinalize ¶
func TraceReqFinalize( msg akita.Msg, now akita.VTimeInSec, domain NamedHookable, )
TraceReqFinalize terminates the message task. This function should be called when the sender receives the response.
func TraceReqInitiate ¶
func TraceReqInitiate( msg akita.Msg, now akita.VTimeInSec, 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 akita.Msg, now akita.VTimeInSec, 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(filter TaskFilter) *AverageTimeTracer
NewAverageTimeTracer creates a new AverageTimeTracer
func (*AverageTimeTracer) AverageTime ¶
func (t *AverageTimeTracer) AverageTime() akita.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(filter TaskFilter) *BusyTimeTracer
NewBusyTimeTracer creates a new BusyTimeTracer
func (*BusyTimeTracer) BusyTime ¶
func (t *BusyTimeTracer) BusyTime() akita.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 akita.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) 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 NewMySQLTracerWithTimeRange ¶
func NewMySQLTracerWithTimeRange( startTime, endTime akita.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 ¶
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 akita.VTimeInSec `json:"start_time"` EndTime akita.VTimeInSec `json:"end_time"` Steps []TaskStep `json:"steps"` Detail interface{} `json:"-"` }
A Task is a task
type TaskFilter ¶
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 akita.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(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() akita.VTimeInSec
TotalTime returns the total time has been spent on a certain type of tasks.
type Tracer ¶
A Tracer can collect task traces
Example ¶
Example for how to use standard tracers
package main import ( "fmt" "gitlab.com/akita/akita" "gitlab.com/akita/util/tracing" ) type SampleDomain struct { *akita.HookableBase taskIDs []int nextID int } func (d *SampleDomain) Name() string { return "sample domain" } func (d *SampleDomain) Start(now akita.VTimeInSec) { tracing.StartTask( fmt.Sprintf("%d", d.nextID), "", now, d, "sampleTaskKind", "something", nil, ) d.taskIDs = append(d.taskIDs, d.nextID) d.nextID++ } func (d *SampleDomain) End(now akita.VTimeInSec) { tracing.EndTask( fmt.Sprintf("%d", d.taskIDs[0]), now, d, ) d.taskIDs = d.taskIDs[1:] } // Example for how to use standard tracers func main() { domain := &SampleDomain{ HookableBase: akita.NewHookableBase(), } filter := func(t tracing.Task) bool { return t.Kind == "sampleTaskKind" } totalTimeTracer := tracing.NewTotalTimeTracer(filter) busyTimeTracer := tracing.NewBusyTimeTracer(filter) avgTimeTracer := tracing.NewAverageTimeTracer(filter) tracing.CollectTrace(domain, totalTimeTracer) tracing.CollectTrace(domain, busyTimeTracer) tracing.CollectTrace(domain, avgTimeTracer) domain.Start(1) domain.Start(1.5) domain.End(2) domain.End(3) fmt.Println(totalTimeTracer.TotalTime()) fmt.Println(busyTimeTracer.BusyTime()) fmt.Println(avgTimeTracer.AverageTime()) }
Output: 2.5 2 1.25