• golang 运行时信息


    package runtime
    
    import "runtime/internal/sys"
    
    // Caller reports file and line number information about function invocations on
    // the calling goroutine's stack. The argument skip is the number of stack frames
    // to ascend, with 0 identifying the caller of Caller.  (For historical reasons the
    // meaning of skip differs between Caller and Callers.) The return values report the
    // program counter, file name, and line number within the file of the corresponding
    // call. The boolean ok is false if it was not possible to recover the information.
    func Caller(skip int) (pc uintptr, file string, line int, ok bool) {
    	rpc := make([]uintptr, 1)
    	n := callers(skip+1, rpc[:])
    	if n < 1 {
    		return
    	}
    	frame, _ := CallersFrames(rpc).Next()
    	return frame.PC, frame.File, frame.Line, frame.PC != 0
    }
    
    // Callers fills the slice pc with the return program counters of function invocations
    // on the calling goroutine's stack. The argument skip is the number of stack frames
    // to skip before recording in pc, with 0 identifying the frame for Callers itself and
    // 1 identifying the caller of Callers.
    // It returns the number of entries written to pc.
    //
    // To translate these PCs into symbolic information such as function
    // names and line numbers, use CallersFrames. CallersFrames accounts
    // for inlined functions and adjusts the return program counters into
    // call program counters. Iterating over the returned slice of PCs
    // directly is discouraged, as is using FuncForPC on any of the
    // returned PCs, since these cannot account for inlining or return
    // program counter adjustment.
    func Callers(skip int, pc []uintptr) int {
    	// runtime.callers uses pc.array==nil as a signal
    	// to print a stack trace. Pick off 0-length pc here
    	// so that we don't let a nil pc slice get to it.
    	if len(pc) == 0 {
    		return 0
    	}
    	return callers(skip, pc)
    }
    

      

  • 相关阅读:
    《SQL 基础教程》第五章:复杂查询
    Ruby on Rails Tutorial 第一章笔记
    《Practical Vim》第十章:复制和粘贴
    《Practical Vim》第五章:命令行模式
    《SQL 基础教程》第四章:数据更新
    用户的三次登录验证及进度条
    socket模块开启一个永久性服务
    TCP协议实现切换目录
    爬取好友微信信息
    TCP协议中传输系统命令及上传下载文件
  • 原文地址:https://www.cnblogs.com/rsapaper/p/16009622.html
Copyright © 2020-2023  润新知