-
Notifications
You must be signed in to change notification settings - Fork 0
/
nogolivi.go
61 lines (49 loc) · 1.62 KB
/
nogolivi.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package nogolivi
import (
"fmt"
"runtime"
"strconv"
"github.com/usuyuki/nogolivi/getter"
"github.com/usuyuki/nogolivi/parser"
"github.com/usuyuki/nogolivi/viewer"
)
func Trace() {
defer func() {
// main関数のpanicはハンドリングできないので、あくまでnogolivi内部のpanicハンドリング用
if r := recover(); r != nil {
fmt.Println("Cannot display due to Panic '", r.(string), "' inside of nogolivi package")
fmt.Println("It would be helpful if you could report it to contact@usuyuki.net.")
return
}
}()
fmt.Println("\n=== 🔥 Nogolivi Check Started 🔥 ===")
var message []string
goroutineCount := runtime.NumGoroutine()
if goroutineCount == 1 {
/*
goroutineがmain goroutineのみの場合
*/
message = append(message, "\n🟢OK\n", "No living goroutines except main goroutine")
// goroutineの残りがない場合はruntime.Stackなどを呼び出さず終える
// 結果の表示
viewer.ShowResult(message)
} else {
/*
goroutineがmain goroutine以外もある場合
*/
message = append(message, "\n❌NG\n", "Number of remaining goroutines excluding the main goroutine: "+strconv.Itoa(goroutineCount-1))
// スタックトレースの取得 文字列を返す
trace, isFull := getter.GetTrace()
if isFull {
message = append(message, "and more")
}
// スタックトレースのパース 解析結果を返す
parseResult := parser.Parse(trace)
// 結果の表示
viewer.ShowResult(message)
// スタックトレースの表示
viewer.ShowTree(parseResult)
}
// 結果表示
fmt.Println("\n=== 🔥 Nogolivi Check End 🔥 ===")
}