-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
87 lines (72 loc) · 1.98 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package debug
import (
"io"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"strings"
"time"
"go.uber.org/zap"
. "m7s.live/engine/v4"
"m7s.live/engine/v4/config"
)
type DebugConfig struct {
config.HTTP
ChartPeriod time.Duration `default:"1s" desc:"图表更新周期"`
}
type WriteToFile struct {
header http.Header
io.Writer
}
func (w *WriteToFile) Header() http.Header {
// return w.w.Header()
return w.header
}
// func (w *WriteToFile) Write(p []byte) (int, error) {
// // w.w.Write(p)
// return w.Writer.Write(p)
// }
func (w *WriteToFile) WriteHeader(statusCode int) {
// w.w.WriteHeader(statusCode)
}
func (p *DebugConfig) OnEvent(event any) {
switch event.(type) {
case FirstConfig:
}
}
func (p *DebugConfig) Pprof_Trace(w http.ResponseWriter, r *http.Request) {
r.URL.Path = "/debug" + r.URL.Path
pprof.Trace(w, r)
}
func (p *DebugConfig) Profile(w http.ResponseWriter, r *http.Request) {
file, err := os.OpenFile("cpu.profile", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
plugin.Error("profile", zap.Error(err))
}
pprof.Profile(&WriteToFile{make(http.Header), file}, r)
file.Close()
if r.Host == "" {
r.Host = "localhost"
}
w.Write([]byte(strings.Join([]string{"go", "tool", "pprof", "-http :6060", ExecPath, filepath.Join(ExecDir, "cpu.profile")}, " ")))
}
func (p *DebugConfig) Pprof_profile(w http.ResponseWriter, r *http.Request) {
r.URL.Path = "/debug" + r.URL.Path
pprof.Profile(w, r)
}
func (p *DebugConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = "/debug" + r.URL.Path
pprof.Index(w, r)
}
var plugin = InstallPlugin(&DebugConfig{})
func (p *DebugConfig) Charts_(w http.ResponseWriter, r *http.Request) {
r.URL.Path = "/static" + strings.TrimPrefix(r.URL.Path, "/charts")
staticFSHandler.ServeHTTP(w, r)
}
func (p *DebugConfig) Charts_data(w http.ResponseWriter, r *http.Request) {
dataHandler(w, r)
}
func (p *DebugConfig) Charts_datafeed(w http.ResponseWriter, r *http.Request) {
s.dataFeedHandler(w, r)
}