目录 搜索
archive archive/tar archive/zip bufio bufio(缓存) builtin builtin(内置包) bytes bytes(包字节) compress compress/bzip2(压缩/bzip2) compress/flate(压缩/flate) compress/gzip(压缩/gzip) compress/lzw(压缩/lzw) compress/zlib(压缩/zlib) container container/heap(容器数据结构heap) container/list(容器数据结构list) container/ring(容器数据结构ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(数据库/sql) database/sql/driver(数据库/sql/driver) debug debug/dwarf(调试/dwarf) debug/elf(调试/elf) debug/gosym(调试/gosym) debug/macho(调试/macho) debug/pe(调试/pe) debug/plan9obj(调试/plan9obj) encoding encoding(编码) encoding/ascii85(编码/ascii85) encoding/asn1(编码/asn1) encoding/base32(编码/base32) encoding/base64(编码/base64) encoding/binary(编码/binary) encoding/csv(编码/csv) encoding/gob(编码/gob) encoding/hex(编码/hex) encoding/json(编码/json) encoding/pem(编码/pem) encoding/xml(编码/xml) errors errors(错误) expvar expvar flag flag(命令行参数解析flag包) fmt fmt go go/ast(抽象语法树) go/build go/constant(常量) go/doc(文档) go/format(格式) go/importer go/parser go/printer go/scanner(扫描仪) go/token(令牌) go/types(类型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(图像) image/color(颜色) image/color/palette(调色板) image/draw(绘图) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系统) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路径) plugin plugin(插件) reflect reflect(反射) regexp regexp(正则表达式) regexp/syntax runtime runtime(运行时) runtime/debug(调试) runtime/internal/sys runtime/pprof runtime/race(竞争) runtime/trace(执行追踪器) sort sort(排序算法) strconv strconv(转换) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系统调用) testing testing(测试) testing/iotest testing/quick text text/scanner(扫描文本) text/tabwriter text/template(定义模板) text/template/parse time time(时间戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "runtime/debug"

  • 概况

  • 索引

概况

程序包调试了包含程序在运行时进行调试的功能。

索引

  • func FreeOSMemory()

  • func PrintStack()

  • func ReadGCStats(stats *GCStats)

  • func SetGCPercent(percent int) int

  • func SetMaxStack(bytes int) int

  • func SetMaxThreads(threads int) int

  • func SetPanicOnFault(enabled bool) bool

  • func SetTraceback(level string)

  • func Stack() []byte

  • func WriteHeapDump(fd uintptr)

  • type GCStats

包文件

garbage.go stack.go stubs.go

func FreeOSMemory

func FreeOSMemory()

FreeOSMemory 强制进行垃圾收集,然后尝试尽可能多地将内存返回给操作系统。(即使未调用此函数,运行时也会逐渐将内存返回到后台任务中的操作系统。)

func PrintStack

func PrintStack()

PrintStack 将由 runtime.Stack 返回的堆栈跟踪打印到标准错误。

func ReadGCStats

func ReadGCStats(stats *GCStats)

ReadGCStats 将有关垃圾收集的统计信息读入统计信息。暂停历史记录中的条目数与系统有关; stats.Pause 片断将在足够大时重用,否则重新分配。ReadGCStats 可能会使用 stats.Pause 片断的全部容量。如果 stats.PauseQuantiles 不是空的,ReadGCStats 会用分位数来填充总结暂停时间的分布。例如,如果 len(stats.PauseQuantiles)为5,则将填充最小值,25%,50%,75%和最大暂停时间。

func SetGCPercent

func SetGCPercent(percent int) int

SetGCPercent 设置垃圾收集目标百分比:当新分配的数据与上一次收集后剩余的实时数据的比率达到此百分比时,触发收集。SetGCPercent 返回先前的设置。初始设置是启动时 GOGC 环境变量的值,如果未设置该变量,则为100。负数百分比会禁用垃圾回收。

func SetMaxStack

func SetMaxStack(bytes int) int

SetMaxStack 设置单个 goroutine 堆栈可以使用的最大内存量。如果任何 goroutine 在增长堆栈时超过此限制,则该程序崩溃。SetMaxStack 返回先前的设置。初始设置在64位系统上为1 GB,在32位系统上为250 MB。

SetMaxStack 主要用于限制进入无限递归的 goroutines 所造成的破坏。它只会限制未来的堆栈增长。

func SetMaxThreads

func SetMaxThreads(threads int) int

SetMaxThreads 设置 Go 程序可以使用的最大操作系统线程数。如果它试图使用超过这么多,程序崩溃。SetMaxThreads 返回先前的设置。初始设置是10,000个线程。

该限制控制操作系统线程的数量,而不是 goroutines 的数量。Go 程序仅在 goroutine 准备好运行时创建新线程,但由于使用 runtime.LockOSThread,所有现有线程在系统调用,cgo 调用中被阻止,或者被锁定到其他 goroutine 。

SetMaxThreads 主要用于限制创建无限数量线程的程序所造成的损害。这个想法是在取消操作系统之前取消该程序。

func SetPanicOnFault

func SetPanicOnFault(enabled bool) bool

当程序在意外(非零)地址发生故障时,SetPanicOnFault 控制运行时的行为。这种故障通常是由运行时内存损坏等错误引起的,所以默认响应是使程序崩溃。使用内存映射文件的程序或内存的不安全操作可能会导致出现故障的非零地址发生故障; SetPanicOnFault 允许这样的程序请求运行时只触发恐慌,而不是崩溃。SetPanicOnFault 仅适用于当前的 goroutine 。它返回以前的设置。

func SetTraceback

func SetTraceback(level string)

SetTraceback 在由于未发现的恐慌或内部运行时错误而退出之前,设置运行时在其打印的回溯中打印的详细信息量。level 参数采用与 GOTRACEBACK 环境变量相同的值。例如,SetTraceback(“all”)确保程序在崩溃时打印所有的 goroutine 。详情请参阅软件包运行时文档。如果 SetTraceback 的调用级别低于环境变量的级别,则调用将被忽略。

func Stack

func Stack() []byte

Stack 返回调用它的 goroutine 的格式化堆栈跟踪。它调用 runtime.Stack 具有足够大的缓冲区来捕获整个跟踪。

func WriteHeapDump

func WriteHeapDump(fd uintptr)

WriteHeapDump 将堆和其中的对象的描述写入给定的文件描述符。

WriteHeapDump 停止所有 goroutine 的执行,直到堆转储完全写入。因此,文件描述符一定不能连接到另一端在同一个 Go 进程中的管道或套接字; 相反,使用临时文件或网络套接字。

堆转储格式在https://golang.org/s/go15heapdump中定义。

type GCStats

GCStats 收集有关最近垃圾收集的信息。

type GCStats struct {
        LastGC         time.Time       // time of last collection
        NumGC          int64           // number of garbage collections
        PauseTotal     time.Duration   // total pause for all collections
        Pause          []time.Duration // pause history, most recent first
        PauseEnd       []time.Time     // pause end times history, most recent first
        PauseQuantiles []time.Duration}
上一篇: 下一篇: