OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / rjeczalik / notify / debug_debug.go
1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
4
5 // +build debug
6
7 package notify
8
9 import (
10         "fmt"
11         "os"
12         "runtime"
13         "strings"
14 )
15
16 func dbgprint(v ...interface{}) {
17         fmt.Printf("[D] ")
18         fmt.Print(v...)
19         fmt.Printf("\n\n")
20 }
21
22 func dbgprintf(format string, v ...interface{}) {
23         fmt.Printf("[D] ")
24         fmt.Printf(format, v...)
25         fmt.Printf("\n\n")
26 }
27
28 func dbgcallstack(max int) []string {
29         pc, stack := make([]uintptr, max), make([]string, 0, max)
30         runtime.Callers(2, pc)
31         for _, pc := range pc {
32                 if f := runtime.FuncForPC(pc); f != nil {
33                         fname := f.Name()
34                         idx := strings.LastIndex(fname, string(os.PathSeparator))
35                         if idx != -1 {
36                                 stack = append(stack, fname[idx+1:])
37                         } else {
38                                 stack = append(stack, fname)
39                         }
40                 }
41         }
42         return stack
43 }