-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (57 loc) · 1.32 KB
/
main.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
62
63
64
65
66
package main
import (
"bytes"
"fmt"
"log"
"net/http"
"runtime"
_ "net/http/pprof"
"github.com/luchsh/agentlib.go/jgo"
)
func handleIndex(w http.ResponseWriter, req *http.Request) {
var b bytes.Buffer
b.WriteString(`<html>
<head>
<title>/debug/java/</title>
</head>
<body>
/debug/java/<br>
<br>
<li><a href="/debug/java/version">Java version</a></li>
<li><a href="/debug/java/threads">All Java threads</a></li>
</body>
</html>`)
w.Write(b.Bytes())
}
func init() {
var err error
_, err = jgo.Exec([]string{"-Djava.class.path=./testdata", "loop"})
if err != nil {
panic(err)
}
}
func main() {
http.HandleFunc("/debug/java/version", func(w http.ResponseWriter, req *http.Request) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
vm := jgo.CurrentVM()
w.Write([]byte(vm.FullVersion()))
})
http.HandleFunc("/debug/java/threads", func(w http.ResponseWriter, req *http.Request) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
vm := jgo.CurrentVM()
thrds, e := vm.DumpThreads()
if e != nil {
s := fmt.Sprintf("Failed to DumpThreads: %v", e)
w.Write([]byte(s))
return
}
for i, th := range thrds {
s := fmt.Sprintf("Thread-%d %s\n", i, th.String())
w.Write([]byte(s))
}
})
http.HandleFunc("/debug/java", handleIndex)
log.Fatal(http.ListenAndServe(":8081", nil))
}