g0debug

package
v0.4.185 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: ISC Imports: 9 Imported by: 0

Documentation

Overview

Package g0debug provides troubleshooting types for Go threads and thread-groups

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoErrorDump

func GoErrorDump(goError parl.GoError) (s string)

GoErrorDump prints everything about parl.GoError

  • parl.GoError: type: *g0.GoError
  • err: pnet.InterfaceAddrs netInterface.Addrs route ip+net: invalid network interface at pnet.InterfaceAddrs()-interface.go:30
  • t: 2023-05-10 15:53:07.885969000-07:00
  • errContext: GeLocalChan
  • goroutine: 72_func:g5.(*Netlink).streamReaderThread()-netlink.go:156_cre:g5.(*Netlink).ReaderThread()-netlink.go:79

Types

type ThreadLogger

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

ThreadLogger waits for a GoGroup, SubGo or SubGroup to terminate while printing information on threads that have yet to exit every second.

  • Because the GoGroup owner needs to continue consuming the GoGroup’s error channel, ThreadLogger has built-in threading
  • the returned sync.WaitGroup pointer should be used to ensure main does not exit prematurely. The WaitGroup ends when the GoGroup ends and ThreadLogger ceases output

func NewThreadLogger

func NewThreadLogger(goGen parl.GoGen, logFn ...parl.PrintfFunc) (threadLogger *ThreadLogger)

NewThreadLogger provides debug logging for a thread-group

  • GoGen: an thread-group object managing threads implemented by g0.GoGroup:
  • parl.GoGroup
  • parl.Subgo
  • parl.SubGroup
  • logFn: an optional logging function, default parl.Log to stderr
  • the new function does not take any action or prepare logging, actions begin by invoking the Log method
  • ThreadLogger.Log begins monitoring and should be invoked prior to launching any threads
  • — ThreadLogger enables parl.AggregateThread for the thread-group. This causes the thread-group to collect thread information for debug purposes
  • — ThreadLogger then listens for thread-group Cancel allowing logging to start automatically
  • ThreadLogger.Wait awaits the end of the thread-group and the thread logger
  • — Wait should not be invoked prior to ensuring that the thread-group is shutting down
  • — a thread-group is typically shut down via its Cancel method, but a thread-group also shuts down on its last thread exiting, a fatal thread error or for other reasons
  • — invoking the Wait method ensures the process does not exit prior to ThreadLogger complete
  • ThreadLogger uses a thread for logging that exits upon the thread-group ending

Usage:

main() {
  var threadGroup = g0.NewGoGroup(context.Background())
  defer threadGroup.Wait()
  defer g0debug.NewThreadLogger(threadGroup).Log().Wait()
  defer threadGroup.Cancel()
  …
 threadGroup.Cancel()

func (*ThreadLogger) Log

func (t *ThreadLogger) Log() (t2 *ThreadLogger)

Log prepares the threadgroup for logging on Cancel

  • Log activates a Cancel listener on the thread-group allowing thread-logging to start automatically
  • supports functional chaining

func (*ThreadLogger) Wait

func (t *ThreadLogger) Wait()

Wait awaits the monitored thread-group end which ends the thread-logger, too

Jump to

Keyboard shortcuts

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