Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package pprof
  5. import (
  6. "fmt"
  7. "io/ioutil"
  8. "runtime"
  9. "runtime/pprof"
  10. "code.gitea.io/gitea/modules/log"
  11. )
  12. // DumpMemProfileForUsername dumps a memory profile at pprofDataPath as memprofile_<username>_<temporary id>
  13. func DumpMemProfileForUsername(pprofDataPath, username string) {
  14. f, err := ioutil.TempFile(pprofDataPath, fmt.Sprintf("memprofile_%s_", username))
  15. if err != nil {
  16. log.GitLogger.Fatal("Could not create memory profile: %v", err)
  17. }
  18. defer f.Close()
  19. runtime.GC() // get up-to-date statistics
  20. if err := pprof.WriteHeapProfile(f); err != nil {
  21. log.GitLogger.Fatal("Could not write memory profile: %v", err)
  22. }
  23. }
  24. // DumpCPUProfileForUsername dumps a CPU profile at pprofDataPath as cpuprofile_<username>_<temporary id>
  25. // it returns the stop function which stops, writes and closes the CPU profile file
  26. func DumpCPUProfileForUsername(pprofDataPath, username string) func() {
  27. f, err := ioutil.TempFile(pprofDataPath, fmt.Sprintf("cpuprofile_%s_", username))
  28. if err != nil {
  29. log.GitLogger.Fatal("Could not create cpu profile: %v", err)
  30. }
  31. pprof.StartCPUProfile(f)
  32. return func() {
  33. pprof.StopCPUProfile()
  34. f.Close()
  35. }
  36. }