当前位置: 首页>>代码示例>>Golang>>正文


Golang runtime.Stack函数代码示例

本文整理汇总了Golang中runtime.Stack函数的典型用法代码示例。如果您正苦于以下问题:Golang Stack函数的具体用法?Golang Stack怎么用?Golang Stack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Stack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: onConn

func (s *Server) onConn(c net.Conn) {
	conn := s.newClientConn(c) //新建一个conn

	defer func() {
		err := recover()
		if err != nil {
			const size = 4096
			buf := make([]byte, size)
			buf = buf[:runtime.Stack(buf, false)] //获得当前goroutine的stacktrace
			golog.Error("server", "onConn", "error", 0,
				"remoteAddr", c.RemoteAddr().String(),
				"stack", string(buf),
			)
		}

		conn.Close()
	}()

	if allowConnect := conn.IsAllowConnect(); allowConnect == false {
		err := mysql.NewError(mysql.ER_ACCESS_DENIED_ERROR, "ip address access denied by kingshard.")
		conn.writeError(err)
		conn.Close()
		return
	}
	if err := conn.Handshake(); err != nil {
		golog.Error("server", "onConn", err.Error(), 0)
		c.Close()
		return
	}

	conn.Run()
}
开发者ID:jazzsun,项目名称:kingshard,代码行数:32,代码来源:server.go

示例2: valIdx

// helper function to validate index inputs
func (a *Arrayb) valIdx(index []int, mthd string) (idx int) {
	if a.HasErr() {
		return 0
	}
	if len(index) > len(a.shape) {
		a.err = InvIndexError
		if debug {
			a.debug = fmt.Sprintf("Incorrect number of indicies received by %s().  Shape: %v  Index: %v", mthd, a.shape, index)
			a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
		}
		return 0
	}
	for i, v := range index {
		if v >= a.shape[i] || v < 0 {
			a.err = IndexError
			if debug {
				a.debug = fmt.Sprintf("Index received by %s() does not exist shape: %v index: %v", mthd, a.shape, index)
				a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
			}
			return 0
		}
		idx += v * a.strides[i+1]
	}
	return
}
开发者ID:Kunde21,项目名称:numgo,代码行数:26,代码来源:bool.go

示例3: _CatchPanic

func _CatchPanic(err *error, functionName string) {
	if r := recover(); r != nil {
		fmt.Printf("%s : PANIC Defered : %v\n", functionName, r)

		// Capture the stack trace
		buf := make([]byte, 10000)
		runtime.Stack(buf, false)

		fmt.Printf("%s : Stack Trace : %s", functionName, string(buf))

		if err != nil {

			*err = errors.New(fmt.Sprintf("%v", r))
		}
	} else if err != nil && *err != nil {

		fmt.Printf("%s : ERROR : %v\n", functionName, *err)

		// Capture the stack trace
		buf := make([]byte, 10000)
		runtime.Stack(buf, false)

		fmt.Printf("%s : Stack Trace : %s", functionName, string(buf))
	}
}
开发者ID:gmallard,项目名称:go-samp,代码行数:25,代码来源:panrecov.go

示例4: valAxis

func (a *Array64) valAxis(axis *[]int, mthd string) bool {
	axis = cleanAxis(axis)
	switch {
	case a.HasErr():
		return true
	case len(*axis) > len(a.shape):
		a.err = ShapeError
		if debug {
			a.debug = fmt.Sprintf("Too many axes received by %s().  Shape: %v  Axes: %v", mthd, a.shape, axis)
			a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
		}
		return true
	}
	for _, v := range *axis {
		if v < 0 || v >= len(a.shape) {
			a.err = IndexError
			if debug {
				a.debug = fmt.Sprintf("Axis out of range received by %s().  Shape: %v  Axes: %v", mthd, a.shape, axis)
				a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
			}
			return true
		}
	}
	if len(*axis) == len(a.shape) {
		*axis = (*axis)[:0]
	}
	return false
}
开发者ID:Kunde21,项目名称:numgo,代码行数:28,代码来源:map.go

示例5: RLock

func (m *RWMutexTracker) RLock() {
	m.logOnce.Do(m.startLogger)
	atomic.AddInt32(&m.nwaitr, 1)

	// Catch read-write-read lock. See if somebody (us? via
	// another goroutine?) already has a read lock, and then
	// somebody else is waiting to write, meaning our second read
	// will deadlock.
	if atomic.LoadInt32(&m.nhaver) > 0 && atomic.LoadInt32(&m.nwaitw) > 0 {
		buf := getBuf()
		buf = buf[:runtime.Stack(buf, false)]
		log.Printf("Potential R-W-R deadlock at: %s", buf)
		putBuf(buf)
	}

	m.mu.RLock()
	atomic.AddInt32(&m.nwaitr, -1)
	atomic.AddInt32(&m.nhaver, 1)

	gid := GoroutineID()
	m.hmu.Lock()
	defer m.hmu.Unlock()
	if m.holdr == nil {
		m.holdr = make(map[int64]bool)
	}
	if m.holdr[gid] {
		buf := getBuf()
		buf = buf[:runtime.Stack(buf, false)]
		log.Fatalf("Recursive call to RLock: %s", buf)
	}
	m.holdr[gid] = true
}
开发者ID:edrex-duex,项目名称:go4,代码行数:32,代码来源:syncdebug.go

示例6: getStack

func getStack() string {
	stack := make([]byte, 1000)
	n := runtime.Stack(stack, false)
	stack = make([]byte, n)
	runtime.Stack(stack, false)
	return string(stack)
}
开发者ID:andrevalgrande,项目名称:gonex,代码行数:7,代码来源:exception.go

示例7: main

func main() {
	buf1 := make([]byte, 1000)
	buf2 := make([]byte, 1000)

	runtime.Stack(buf1, false)      // CALL is last instruction on this line
	n := runtime.Stack(buf2, false) // CALL is followed by load of result from stack

	buf1 = buf1[:bytes.IndexByte(buf1, 0)]
	buf2 = buf2[:n]

	re := regexp.MustCompile(`(?m)^main\.main\(\)\n.*/issue7690.go:([0-9]+)`)
	m1 := re.FindStringSubmatch(string(buf1))
	if m1 == nil {
		println("BUG: cannot find main.main in first trace")
		return
	}
	m2 := re.FindStringSubmatch(string(buf2))
	if m2 == nil {
		println("BUG: cannot find main.main in second trace")
		return
	}

	n1, _ := strconv.Atoi(m1[1])
	n2, _ := strconv.Atoi(m2[1])
	if n1+1 != n2 {
		println("BUG: expect runtime.Stack on back to back lines, have", n1, n2)
		println(string(buf1))
		println(string(buf2))
	}
}
开发者ID:Xiahl1990,项目名称:go,代码行数:30,代码来源:issue7690.go

示例8: PCall

func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
	err = nil
	sp := ls.stack.Sp()
	base := ls.reg.Top() - nargs - 1
	oldpanic := ls.Panic
	ls.Panic = panicWithoutTraceback
	defer func() {
		ls.Panic = oldpanic
		rcv := recover()
		if rcv != nil {
			if _, ok := rcv.(*ApiError); !ok {
				err = newApiErrorS(ApiErrorPanic, fmt.Sprint(rcv))
				if ls.Options.IncludeGoStackTrace {
					buf := make([]byte, 4096)
					runtime.Stack(buf, false)
					err.(*ApiError).StackTrace = strings.Trim(string(buf), "\000") + "\n" + ls.stackTrace(true)
				}
			} else {
				err = rcv.(*ApiError)
			}
			if errfunc != nil {
				ls.Push(errfunc)
				ls.Push(err.(*ApiError).Object)
				ls.Panic = panicWithoutTraceback
				defer func() {
					ls.Panic = oldpanic
					rcv := recover()
					if rcv != nil {
						if _, ok := rcv.(*ApiError); !ok {
							err = newApiErrorS(ApiErrorPanic, fmt.Sprint(rcv))
							if ls.Options.IncludeGoStackTrace {
								buf := make([]byte, 4096)
								runtime.Stack(buf, false)
								err.(*ApiError).StackTrace = strings.Trim(string(buf), "\000") + ls.stackTrace(true)
							}
						} else {
							err = rcv.(*ApiError)
							err.(*ApiError).StackTrace = ls.stackTrace(true)
						}
					}
				}()
				ls.Call(1, 1)
				err = newApiError(ApiErrorError, ls.Get(-1))
			} else if len(err.(*ApiError).StackTrace) == 0 {
				err.(*ApiError).StackTrace = ls.stackTrace(true)
			}
			ls.reg.SetTop(base)
		}
		ls.stack.SetSp(sp)
		if sp == 0 {
			ls.currentFrame = nil
		}
	}()

	ls.Call(nargs, nret)

	return
}
开发者ID:natural,项目名称:gopher-lua,代码行数:58,代码来源:state.go

示例9: GetStackTraces

func GetStackTraces(buf *[]byte) {
	*buf = (*buf)[0:cap(*buf)]
	neededBytes := runtime.Stack(*buf, true)
	for neededBytes > len(*buf) {
		*buf = make([]byte, neededBytes)
		runtime.Stack(*buf, true)
	}
	*buf = (*buf)[0:neededBytes]
}
开发者ID:gauravrmazra,项目名称:incubator-htrace,代码行数:9,代码来源:process.go

示例10: TestOpenClose

// Test that we can open and close a file
func TestOpenClose(test *testing.T) {
	fs, proc := OpenMinixImage(test)

	file, err := proc.Open("/sample/europarl-en.txt", common.O_RDONLY, 0666)
	if err != nil {
		testutils.FatalHere(test, "Failed opening file: %s", err)
	}

	found, count := checkFileAndCount(proc, file)

	if !found {
		testutils.FatalHere(test, "Did not find open file in proc.files")
	}
	if count != 1 {
		testutils.FatalHere(test, "Open file count incorrect got %d, expected %d", count, 1)
	}

	// Now close the file and make sure things are cleaned up
	err = proc.Close(file)

	found, count = checkFileAndCount(proc, file)

	if found {
		testutils.FatalHere(test, "Found file in process table, should not have")
	}
	if count != 0 {
		testutils.FatalHere(test, "Open file count mismatch got %d, expected %d", count, 0)
	}

	// How many goroutines are open right now?
	numgoros := runtime.NumGoroutine()
	stacknow := make([]byte, 4096)
	runtime.Stack(stacknow, true)

	fs.Exit(proc)
	err = fs.Shutdown()
	if err != nil {
		testutils.FatalHere(test, "Failed when shutting down filesystem: %s", err)
	}

	// We expect shutdown to have killed the following goroutines
	//  * device
	//  * block cache
	//  * inode cache
	//  * allocation table
	//  * file server

	// This test is fragile, so be careful with it!
	expected := numgoros - 5
	if runtime.NumGoroutine() != expected {
		test.Logf("Original stack:\n%s\n", stacknow)
		newstack := make([]byte, 4096)
		runtime.Stack(newstack, true)
		test.Logf("Current stack:\n%s\n", newstack)
		testutils.FatalHere(test, "Goroutine count mismatch got %d, expected %d", expected, runtime.NumGoroutine())
	}
}
开发者ID:jnwhiteh,项目名称:minixfs,代码行数:58,代码来源:openclose_test.go

示例11: AuditPanic

// AuditPanic catches panicking executables. This method should be added
// in a defer statement as early as possible
// AUDIT[ Error Conditions ] 9cc4d537-8534-4970-8665-4b382abe82f3
func (log *AuditLogger) AuditPanic() {
	if err := recover(); err != nil {
		buf := make([]byte, 8192)
		log.Audit(fmt.Sprintf("Panic caused by err: %s", err))

		runtime.Stack(buf, false)
		log.Audit(fmt.Sprintf("Stack Trace (Current frame) %s", buf))

		runtime.Stack(buf, true)
		log.Warning(fmt.Sprintf("Stack Trace (All frames): %s", buf))
	}
}
开发者ID:jgillula,项目名称:boulder,代码行数:15,代码来源:audit-logger.go

示例12: valRith

// valAr needs to be called before
func (a *Array64) valRith(b *Array64, mthd string) bool {
	var flag bool
	switch {
	case a.HasErr():
		return true
	case b == nil:
		a.err = NilError
		if debug {
			a.debug = "Array received by " + mthd + "() is a Nil pointer."
			a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
		}
		return true
	case b.HasErr():
		a.err = b.err
		if debug {
			a.debug = "Array received by " + mthd + "() is in error."
			a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
		}
		return true
	case len(a.shape) < len(b.shape):
		goto shape
	}

	for i, j := len(b.shape)-1, len(a.shape)-1; i >= 0; i, j = i-1, j-1 {
		if a.shape[j] != b.shape[i] {
			flag = true
			break
		}
	}
	if !flag {
		return false
	}
	if len(b.shape) != len(a.shape) || b.shape[len(b.shape)-1] != 1 {
		goto shape
	}
	for i := 0; i < len(a.shape)-1; i++ {
		if a.shape[i] != b.shape[i] {
			goto shape
		}
	}
	return false
shape:
	a.err = ShapeError
	if debug {
		a.debug = fmt.Sprintf("Array received by %s() can not be broadcast.  Shape: %v  Val shape: %v",
			mthd, a.shape, b.shape)
		a.stack = string(stackBuf[:runtime.Stack(stackBuf, false)])
	}
	return true
}
开发者ID:Kunde21,项目名称:numgo,代码行数:51,代码来源:arithmetic.go

示例13: Stacktrace

// Stacktrace returns the stacktrace of the goroutine that calls it.
func Stacktrace() string {
	// Write a stack trace
	buf := make([]byte, 10000)
	n := runtime.Stack(buf, true)

	// Incrementally grow the
	// buffer as the stack trace
	// requires.
	for n > len(buf) {
		buf = make([]byte, len(buf)*2)
		n = runtime.Stack(buf, false)
	}
	return string(buf)
}
开发者ID:leonardyp,项目名称:mandala,代码行数:15,代码来源:mandala.go

示例14: PCall

func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) {
	err = nil
	sp := ls.stack.Sp()
	base := ls.reg.Top() - nargs - 1
	oldpanic := ls.Panic
	ls.Panic = func(L *LState) {
		panic(newApiError(ApiErrorRun, "", L.Get(-1)))
	}
	defer func() {
		ls.Panic = oldpanic
		rcv := recover()
		if rcv != nil {
			if _, ok := rcv.(*ApiError); !ok {
				buf := make([]byte, 4096)
				runtime.Stack(buf, false)
				err = newApiError(ApiErrorPanic, fmt.Sprintf("%v\n%v", rcv, strings.Trim(string(buf), "\000")), LNil)
			} else {
				err = rcv.(*ApiError)
			}
			if errfunc != nil {
				ls.Push(errfunc)
				ls.Push(err.(*ApiError).Object)
				ls.Panic = func(L *LState) {
					panic(newApiError(ApiErrorError, "", L.Get(-1)))
				}
				defer func() {
					ls.Panic = oldpanic
					rcv := recover()
					if rcv != nil {
						if _, ok := rcv.(*ApiError); !ok {
							buf := make([]byte, 4096)
							runtime.Stack(buf, false)
							err = newApiError(ApiErrorPanic, fmt.Sprintf("%v\n%v", rcv, strings.Trim(string(buf), "\000")), LNil)
						} else {
							err = rcv.(*ApiError)
						}
					}
				}()
				ls.Call(1, 1)
			}
			ls.reg.SetTop(base)
		}
		ls.stack.SetSp(sp)
	}()

	ls.Call(nargs, nret)

	return
}
开发者ID:evangelistcollective,项目名称:hustlebot,代码行数:49,代码来源:state.go

示例15: Panicf

func (sl SysLogger) Panicf(format string, v ...interface{}) {
	var cnt int
	sl.Logf(format, v...)
	stack := make([]byte, 8192)
	if sl.verbose {
		cnt = runtime.Stack(stack, true)
	} else {
		cnt = runtime.Stack(stack, false)
	}
	lines := strings.Split(string(stack[:cnt]), "\n")
	for _, line := range lines {
		sl.Log(strings.TrimSpace(line))
	}
	panic(v)
}
开发者ID:xrfang,项目名称:mailing_list_daemon,代码行数:15,代码来源:syslog.go


注:本文中的runtime.Stack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。