utils

package
v0.0.0-...-4017c26 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package utils provides miscellaneous utilities for ProxyFS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteSliceToString

func ByteSliceToString(byteSlice []byte) (str string)

func ByteSliceToUint32

func ByteSliceToUint32(byteSlice []byte) (u32 uint32, ok bool)

func ByteSliceToUint64

func ByteSliceToUint64(byteSlice []byte) (u64 uint64, ok bool)

func ByteToHexDigit

func ByteToHexDigit(u8 byte) (digit byte)

ByteToHexDigit returns the (uppercase) hex character representation of the low order nibble of the byte supplied.

func FetchRandomBool

func FetchRandomBool() (randBool bool)

func FetchRandomByteSlice

func FetchRandomByteSlice(len int) (randByteSlice []byte)

func FetchRandomUint64

func FetchRandomUint64() (randUint64 uint64)

func GetAFnName

func GetAFnName(level int) string

Return a string containing calling function and package

func GetCallerFnName

func GetCallerFnName() string

GetCallerFnName returns a string containing the name of the calling function. This can be useful for debug prints.

func GetFnName

func GetFnName() string

GetFnName returns a string containing the name of the running function and its package. This can be useful for debug prints.

func GetFuncPackage

func GetFuncPackage(level int) (fn string, pkg string, gid uint64)

Return separage strings containing calling function and package

XXX TODO TEMPORARY: also return goroutine id

func GetGID

func GetGID() uint64

XXX TODO TEMPORARY:

I know our go-overlords would prefer that we knew nothing about goroutines, but logging the goroutine context can be useful when trying to debug things like locking.

Intent is to have this now and hopefully remove it once we've gotten debugged.

func GetGoId

func GetGoId() uint64

func HexStrToUint64

func HexStrToUint64(value string) (uint64, error)

func JSONify

func JSONify(input interface{}, indentify bool) (output string)

func MyStackTrace

func MyStackTrace() (stackTrace string)

Return the stack track of the caller, including this function.

func PathToAcctContObj

func PathToAcctContObj(path string) (accountName string, containerName string, objectName string, err error)

func RandomizeList

func RandomizeList(theList *list.List)

func StackTraceToGoId

func StackTraceToGoId(buf []byte) uint64

Given the first line of a stack trace parse out and return the goroutine ID. The first line of a stack trace starts with: "goroutine 7 [runnable]:\n"

This function really should have some error checking to insure it matched "goroutine" though there's no way to log a failure.

func StackTracesToMap

func StackTracesToMap(buf []byte) (traceMap map[uint64]string, stateMap map[uint64]string)

Convert a slice filled in by runtime.Stack(buf, true), which contains the stack traceback of one or more go routines, into a map goid -> stack.

buffer looks like:

goroutine 1 [running]: main.main() /vagrant/guest_workspaces/swift-runway-001/ProxyFS/src/github.com/swiftstack/ProxyFS/stacktrace.go:27 +0x21e

goroutine 5 [runnable]: main.killTime() /vagrant/guest_workspaces/swift-runway-001/ProxyFS/src/github.com/swiftstack/ProxyFS/stacktrace.go:9 created by main.main /vagrant/guest_workspaces/swift-runway-001/ProxyFS/src/github.com/swiftstack/ProxyFS/stacktrace.go:14 +0x47

goroutine 7 [runnable]: main.killTime() /vagrant/guest_workspaces/swift-runway-001/ProxyFS/src/github.com/swiftstack/ProxyFS/stacktrace.go:9 created by main.main /vagrant/guest_workspaces/swift-runway-001/ProxyFS/src/github.com/swiftstack/ProxyFS/stacktrace.go:16 +0x77

func StringToByteSlice

func StringToByteSlice(str string) (byteSlice []byte)

func Uint32ToByteSlice

func Uint32ToByteSlice(u32 uint32) (byteSlice []byte)

func Uint64ToByteSlice

func Uint64ToByteSlice(u64 uint64) (byteSlice []byte)

func Uint64ToHexStr

func Uint64ToHexStr(value uint64) string

Types

type EventDuration

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

type EventStats

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

func GetStats

func GetStats(profiles map[int]*Profiler) *EventStats

func (*EventStats) DumpToStdout

func (s *EventStats) DumpToStdout()

func (*EventStats) DumpToString

func (s *EventStats) DumpToString(condensed bool) (out string)

type EventTime

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

func (*EventTime) Sub

func (t *EventTime) Sub(prevTime time.Time) (duration time.Duration)

func (*EventTime) SubUs

func (t *EventTime) SubUs(prevTime time.Time) (durationUs int64)

type MultiWaiterWaitGroup

type MultiWaiterWaitGroup struct {
	sync.Mutex
	// contains filtered or unexported fields
}

MultiWaiterWaitGroup emulates the behavior of sync.WaitGroup while enabling multiple waiters.

Unline sync.WaitGroup, however, you must allocate a MultiWaiterWaitGroup with a call to FetchMultiWaiterWaitGroup().

func FetchMultiWaiterWaitGroup

func FetchMultiWaiterWaitGroup() (mwwg *MultiWaiterWaitGroup)

func (*MultiWaiterWaitGroup) Add

func (mwwg *MultiWaiterWaitGroup) Add(delta int)

func (*MultiWaiterWaitGroup) Done

func (mwwg *MultiWaiterWaitGroup) Done()

func (*MultiWaiterWaitGroup) Wait

func (mwwg *MultiWaiterWaitGroup) Wait()

type Profiler

type Profiler struct {
	Timer *Stopwatch
	// contains filtered or unexported fields
}

func NewProfiler

func NewProfiler(timedOp string) *Profiler

func NewProfilerIf

func NewProfilerIf(condition bool, timedOp string) *Profiler

NewProfilerIf allocates and returns a new Profiler, if condition is true.

func (*Profiler) AddEventNow

func (p *Profiler) AddEventNow(eventName string)

func (*Profiler) Close

func (p *Profiler) Close()

func (*Profiler) Dump

func (p *Profiler) Dump()

func (*Profiler) DumpRaw

func (p *Profiler) DumpRaw()

func (*Profiler) Name

func (p *Profiler) Name() string

func (*Profiler) SetName

func (p *Profiler) SetName(opName string)

type Stopwatch

type Stopwatch struct {
	StartTime   time.Time
	StopTime    time.Time
	ElapsedTime time.Duration
	IsRunning   bool
}

func NewStopwatch

func NewStopwatch() *Stopwatch

func (*Stopwatch) Elapsed

func (sw *Stopwatch) Elapsed() time.Duration

func (*Stopwatch) ElapsedMs

func (sw *Stopwatch) ElapsedMs() int64

func (*Stopwatch) ElapsedMsString

func (sw *Stopwatch) ElapsedMsString() string

func (*Stopwatch) ElapsedNs

func (sw *Stopwatch) ElapsedNs() int64

func (*Stopwatch) ElapsedNsString

func (sw *Stopwatch) ElapsedNsString() string

func (*Stopwatch) ElapsedSec

func (sw *Stopwatch) ElapsedSec() int64

func (*Stopwatch) ElapsedSecString

func (sw *Stopwatch) ElapsedSecString() string

func (*Stopwatch) ElapsedString

func (sw *Stopwatch) ElapsedString() string

func (*Stopwatch) ElapsedUs

func (sw *Stopwatch) ElapsedUs() int64

func (*Stopwatch) ElapsedUsString

func (sw *Stopwatch) ElapsedUsString() string

func (*Stopwatch) Restart

func (sw *Stopwatch) Restart()

func (*Stopwatch) Stop

func (sw *Stopwatch) Stop() time.Duration

type TryLockMutex

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

TryLockMutex is used to support a timeout a the lock request

func NewTryLockMutex

func NewTryLockMutex() (tryLockMutex *TryLockMutex)

func (*TryLockMutex) Lock

func (tryLockMutex *TryLockMutex) Lock()

func (*TryLockMutex) TryLock

func (tryLockMutex *TryLockMutex) TryLock(timeout time.Duration) (gotIt bool)

func (*TryLockMutex) Unlock

func (tryLockMutex *TryLockMutex) Unlock()

Jump to

Keyboard shortcuts

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