gitea源码

stacktrace.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package admin
  4. import (
  5. "net/http"
  6. "runtime"
  7. "code.gitea.io/gitea/modules/process"
  8. "code.gitea.io/gitea/modules/setting"
  9. "code.gitea.io/gitea/services/context"
  10. )
  11. func monitorTraceCommon(ctx *context.Context) {
  12. ctx.Data["Title"] = ctx.Tr("admin.monitor")
  13. ctx.Data["PageIsAdminMonitorTrace"] = true
  14. // Hide the performance trace tab in production, because it shows a lot of SQLs and is not that useful for end users.
  15. // To avoid confusing end users, do not let them know this tab. End users should "download diagnosis report" instead.
  16. ctx.Data["ShowAdminPerformanceTraceTab"] = !setting.IsProd
  17. }
  18. // Stacktrace show admin monitor goroutines page
  19. func Stacktrace(ctx *context.Context) {
  20. monitorTraceCommon(ctx)
  21. ctx.Data["GoroutineCount"] = runtime.NumGoroutine()
  22. show := ctx.FormString("show")
  23. ctx.Data["ShowGoroutineList"] = show
  24. // by default, do not do anything which might cause server errors, to avoid unnecessary 500 pages.
  25. // this page is the entrance of the chance to collect diagnosis report.
  26. if show != "" {
  27. showNoSystem := show == "process"
  28. processStacks, processCount, _, err := process.GetManager().ProcessStacktraces(false, showNoSystem)
  29. if err != nil {
  30. ctx.ServerError("GoroutineStacktrace", err)
  31. return
  32. }
  33. ctx.Data["ProcessStacks"] = processStacks
  34. ctx.Data["ProcessCount"] = processCount
  35. }
  36. ctx.HTML(http.StatusOK, tplStacktrace)
  37. }
  38. // StacktraceCancel cancels a process
  39. func StacktraceCancel(ctx *context.Context) {
  40. pid := ctx.PathParam("pid")
  41. process.GetManager().Cancel(process.IDType(pid))
  42. ctx.JSONRedirect(setting.AppSubURL + "/-/admin/monitor/stacktrace")
  43. }