github.com/haraldrudell/parl@v0.4.176/if-tracer.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package parl 7 8 import ( 9 "time" 10 ) 11 12 // Tracer lists events in terms of tasks rather than per time or thread. 13 // A task is executed by threads assigned to it. 14 // Threads are uniquely identified by threadID. 15 // A task can have zero or one threads assigned at any one time. 16 // A thread can be assigned to zero or one tasks. 17 // Each task has an ID, a name and a list of events and thread assignments 18 // Tracer can record branching in the code and return that for a particular 19 // item being processed. For an item processed incorrectly, or when 20 // threads hang, Tracer will find unfavorable branching and last known locations. 21 type Tracer interface { 22 // AssignTaskToThread assigns a Thread to a task 23 AssignTaskToThread(threadID ThreadID, task TracerTaskID) (tracer Tracer) 24 // RecordTaskEvent adds an event to the task threadID is currently assigned to. 25 // If threadID is not assigned, a new task is created. 26 RecordTaskEvent(threadID ThreadID, text string) (tracer Tracer) 27 // Records returns the current map of tasks and their events 28 Records(clear bool) (records map[TracerTaskID][]TracerRecord) 29 } 30 31 type TracerTaskID string 32 33 type TracerRecord interface { 34 Values() (at time.Time, text string) 35 } 36 37 type TracerFactory interface { 38 // NewTracer creates tracer storage. 39 // use false indicates a nil Tracer whose output will not be used 40 NewTracer(use bool) (tracer Tracer) 41 }