mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-02 03:57:38 +03:00
feat: pprof
This commit is contained in:
parent
3b4af8035b
commit
531b23baa4
3 changed files with 39 additions and 8 deletions
22
app/pprof.go
Normal file
22
app/pprof.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
//go:build pprof
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
const (
|
||||
pprofListenAddr = ":6060"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Printf("!!! pprof enabled, listening on %s\n", pprofListenAddr)
|
||||
go func() {
|
||||
if err := http.ListenAndServe(pprofListenAddr, nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
}
|
|
@ -137,6 +137,7 @@ github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm
|
|||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe h1:W/GaMY0y69G4cFlmsC6B9sbuo2fP8OFP1ABjt4kPz+w=
|
||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
|
@ -144,6 +145,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
|||
github.com/microcosm-cc/bluemonday v1.0.1 h1:SIYunPjnlXcW+gVfvm0IlSeR5U3WZUOLfVmqg85Go44=
|
||||
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
|
|
23
hyperbole.py
23
hyperbole.py
|
@ -74,7 +74,8 @@ def get_app_commit():
|
|||
if not app_commit:
|
||||
try:
|
||||
app_commit = (
|
||||
subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
|
||||
subprocess.check_output(
|
||||
["git", "rev-parse", "HEAD"]).decode().strip()
|
||||
)
|
||||
except Exception:
|
||||
app_commit = "Unknown"
|
||||
|
@ -85,7 +86,8 @@ def get_app_platforms():
|
|||
platforms = os.environ.get("HY_APP_PLATFORMS")
|
||||
if not platforms:
|
||||
d_os = subprocess.check_output(["go", "env", "GOOS"]).decode().strip()
|
||||
d_arch = subprocess.check_output(["go", "env", "GOARCH"]).decode().strip()
|
||||
d_arch = subprocess.check_output(
|
||||
["go", "env", "GOARCH"]).decode().strip()
|
||||
return [(d_os, d_arch)]
|
||||
|
||||
result = []
|
||||
|
@ -100,7 +102,7 @@ def get_app_platforms():
|
|||
return result
|
||||
|
||||
|
||||
def cmd_build(release=False):
|
||||
def cmd_build(pprof=False, release=False):
|
||||
if not check_build_env():
|
||||
return
|
||||
|
||||
|
@ -116,7 +118,8 @@ def cmd_build(release=False):
|
|||
"-X",
|
||||
APP_SRC_CMD_PKG + ".appDate=" + app_date,
|
||||
"-X",
|
||||
APP_SRC_CMD_PKG + ".appType=" + ("release" if release else "dev"),
|
||||
APP_SRC_CMD_PKG + ".appType=" +
|
||||
("release" if release else "dev") + ("-pprof" if pprof else ""),
|
||||
"-X",
|
||||
APP_SRC_CMD_PKG + ".appCommit=" + app_commit,
|
||||
]
|
||||
|
@ -143,6 +146,9 @@ def cmd_build(release=False):
|
|||
"-ldflags",
|
||||
" ".join(ldflags),
|
||||
]
|
||||
if pprof:
|
||||
cmd.append("-tags")
|
||||
cmd.append("pprof")
|
||||
if release:
|
||||
cmd.append("-trimpath")
|
||||
cmd.append(APP_SRC_DIR)
|
||||
|
@ -235,9 +241,10 @@ def main():
|
|||
|
||||
# Build
|
||||
p_build = p_cmd.add_parser("build", help="Build the app")
|
||||
p_build.add_argument(
|
||||
"-r", "--release", action="store_true", help="Build a release version"
|
||||
)
|
||||
p_build.add_argument("-p", "--pprof", action="store_true",
|
||||
help="Build with pprof enabled")
|
||||
p_build.add_argument("-r", "--release", action="store_true",
|
||||
help="Build a release version")
|
||||
|
||||
# Format
|
||||
p_cmd.add_parser("format", help="Format the code")
|
||||
|
@ -256,7 +263,7 @@ def main():
|
|||
if args.command == "run":
|
||||
cmd_run(args.args)
|
||||
elif args.command == "build":
|
||||
cmd_build(args.release)
|
||||
cmd_build(args.pprof, args.release)
|
||||
elif args.command == "format":
|
||||
cmd_format()
|
||||
elif args.command == "mockgen":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue