-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system to track only Autometricized parents
This system will likely fail whenever a Trace forks into multiple goroutines, this is something to take care of. And likely the reason we will need some kind of goroutine local storage on top of the global state Fixes: AM-42
- Loading branch information
Showing
7 changed files
with
213 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package autometrics // import "github.com/autometrics-dev/autometrics-go/pkg/autometrics" | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// InstrumentedFunctionsCallStack is a stack containing only function IDs (pairs of function name and module name) for | ||
// autometricized functions in a given callstack. | ||
type InstrumentedFunctionsCallStack struct { | ||
storage []FunctionID | ||
} | ||
|
||
func NewInstrumentedFunctionsCallStack() *InstrumentedFunctionsCallStack { | ||
return &InstrumentedFunctionsCallStack{ | ||
storage: make([]FunctionID, 0, 16), | ||
} | ||
} | ||
|
||
func (stack InstrumentedFunctionsCallStack) IsEmpty() bool { | ||
return len(stack.storage) == 0 | ||
} | ||
|
||
func (stack InstrumentedFunctionsCallStack) Peek(fromTop int) (FunctionID, error) { | ||
l := len(stack.storage) | ||
if fromTop >= l { | ||
return FunctionID{}, fmt.Errorf("out of bounds access: %v while length is %v", fromTop, l) | ||
} | ||
|
||
return stack.storage[l-1-fromTop], nil | ||
} | ||
|
||
func (stack *InstrumentedFunctionsCallStack) Push(functionID FunctionID) int { | ||
stack.storage = append(stack.storage, functionID) | ||
|
||
return len(stack.storage) | ||
} | ||
|
||
func (stack *InstrumentedFunctionsCallStack) Pop() (FunctionID, error) { | ||
l := len(stack.storage) | ||
|
||
if l == 0 { | ||
return FunctionID{}, errors.New("out of bounds access: stack is empty") | ||
} | ||
|
||
topElem := stack.storage[l-1] | ||
stack.storage = stack.storage[:l] | ||
|
||
return topElem, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.