go-ethereum/common/debug/debug.go
marcello33 3ed22568fd
Hotfixes and deps bump (#776)
* dev: chg: bump deps

* internal/cli/server, rpc: lower down http readtimeout to 10s

* dev: chg: get p2p adapter

* dev: chg: lower down jsonrpc readtimeout to 10s

* cherry-pick txpool optimisation changes

* add check for empty lists in txpool (#704)

* add check

* linters

* core, miner: add empty instrumentation name for tracing

---------

Co-authored-by: Raneet Debnath <raneetdebnath10@gmail.com>
Co-authored-by: SHIVAM SHARMA <shivam691999@gmail.com>
Co-authored-by: Evgeny Danilenko <6655321@bk.ru>
Co-authored-by: Manav Darji <manavdarji.india@gmail.com>
2023-03-14 12:40:23 +01:00

52 lines
910 B
Go

package debug
import (
"fmt"
"runtime"
)
// Callers returns given number of callers with packages
func Callers(show int) []string {
fpcs := make([]uintptr, show)
n := runtime.Callers(2, fpcs)
if n == 0 {
return nil
}
callers := make([]string, 0, len(fpcs))
for _, p := range fpcs {
caller := runtime.FuncForPC(p - 1)
if caller == nil {
continue
}
callers = append(callers, caller.Name())
}
return callers
}
func CodeLine() (string, string, int) {
pc, filename, line, _ := runtime.Caller(1)
return runtime.FuncForPC(pc).Name(), filename, line
}
func CodeLineStr() string {
pc, filename, line, _ := runtime.Caller(1)
return fmt.Sprintf("%s:%d - %s", filename, line, runtime.FuncForPC(pc).Name())
}
func Stack(all bool) []byte {
buf := make([]byte, 4096)
for {
n := runtime.Stack(buf, all)
if n < len(buf) {
return buf[:n]
}
buf = make([]byte, 2*len(buf))
}
}