aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/rjeczalik/notify/debug_debug.go
blob: f0622917f500200c26ef162b5d32df9b70134854 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

// +build debug

package notify

import (
    "fmt"
    "os"
    "runtime"
    "strings"
)

func dbgprint(v ...interface{}) {
    fmt.Printf("[D] ")
    fmt.Print(v...)
    fmt.Printf("\n\n")
}

func dbgprintf(format string, v ...interface{}) {
    fmt.Printf("[D] ")
    fmt.Printf(format, v...)
    fmt.Printf("\n\n")
}

func dbgcallstack(max int) []string {
    pc, stack := make([]uintptr, max), make([]string, 0, max)
    runtime.Callers(2, pc)
    for _, pc := range pc {
        if f := runtime.FuncForPC(pc); f != nil {
            fname := f.Name()
            idx := strings.LastIndex(fname, string(os.PathSeparator))
            if idx != -1 {
                stack = append(stack, fname[idx+1:])
            } else {
                stack = append(stack, fname)
            }
        }
    }
    return stack
}