debug_debug.go 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // +build debug
  5. package notify
  6. import (
  7. "fmt"
  8. "os"
  9. "runtime"
  10. "strings"
  11. )
  12. func dbgprint(v ...interface{}) {
  13. fmt.Printf("[D] ")
  14. fmt.Print(v...)
  15. fmt.Printf("\n\n")
  16. }
  17. func dbgprintf(format string, v ...interface{}) {
  18. fmt.Printf("[D] ")
  19. fmt.Printf(format, v...)
  20. fmt.Printf("\n\n")
  21. }
  22. func dbgcallstack(max int) []string {
  23. pc, stack := make([]uintptr, max), make([]string, 0, max)
  24. runtime.Callers(2, pc)
  25. for _, pc := range pc {
  26. if f := runtime.FuncForPC(pc); f != nil {
  27. fname := f.Name()
  28. idx := strings.LastIndex(fname, string(os.PathSeparator))
  29. if idx != -1 {
  30. stack = append(stack, fname[idx+1:])
  31. } else {
  32. stack = append(stack, fname)
  33. }
  34. }
  35. }
  36. return stack
  37. }