diff options
author | Jerry Jacobs <xor-gate@users.noreply.github.com> | 2018-08-07 20:49:18 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@users.noreply.github.com> | 2018-08-07 14:49:18 -0400 |
commit | b1bc08e2686e2aa73aaf2108fdc50d9e700def38 (patch) | |
tree | 5f3f155e6290176c4e0b0aaa1cc557d87df56210 /cmd/serv.go | |
parent | ed3589f4296a17ee201f44dcf6e87f8bd5741d09 (diff) | |
download | gitea-b1bc08e2686e2aa73aaf2108fdc50d9e700def38.tar.gz gitea-b1bc08e2686e2aa73aaf2108fdc50d9e700def38.zip |
cmd/serve: pprof cpu and memory profile dumps to disk (#4560)
Diffstat (limited to 'cmd/serv.go')
-rw-r--r-- | cmd/serv.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/cmd/serv.go b/cmd/serv.go index 990355be98..b532b95494 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/pprof" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -42,6 +43,9 @@ var CmdServ = cli.Command{ Value: "custom/conf/app.ini", Usage: "Custom configuration file path", }, + cli.BoolFlag{ + Name: "enable-pprof", + }, }, } @@ -143,6 +147,18 @@ func runServ(c *cli.Context) error { username := strings.ToLower(rr[0]) reponame := strings.ToLower(strings.TrimSuffix(rr[1], ".git")) + if setting.EnablePprof || c.Bool("enable-pprof") { + if err := os.MkdirAll(setting.PprofDataPath, os.ModePerm); err != nil { + fail("Error while trying to create PPROF_DATA_PATH", "Error while trying to create PPROF_DATA_PATH: %v", err) + } + + stopCPUProfiler := pprof.DumpCPUProfileForUsername(setting.PprofDataPath, username) + defer func() { + stopCPUProfiler() + pprof.DumpMemProfileForUsername(setting.PprofDataPath, username) + }() + } + isWiki := false unitType := models.UnitTypeCode if strings.HasSuffix(reponame, ".wiki") { |