code.gitea.io/gitea@v1.21.7/routers/web/admin/stacktrace.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package admin
     5  
     6  import (
     7  	"net/http"
     8  	"runtime"
     9  
    10  	"code.gitea.io/gitea/modules/context"
    11  	"code.gitea.io/gitea/modules/process"
    12  	"code.gitea.io/gitea/modules/setting"
    13  )
    14  
    15  // Stacktrace show admin monitor goroutines page
    16  func Stacktrace(ctx *context.Context) {
    17  	ctx.Data["Title"] = ctx.Tr("admin.monitor")
    18  	ctx.Data["PageIsAdminMonitorStacktrace"] = true
    19  
    20  	ctx.Data["GoroutineCount"] = runtime.NumGoroutine()
    21  
    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  
    34  		ctx.Data["ProcessStacks"] = processStacks
    35  		ctx.Data["ProcessCount"] = processCount
    36  	}
    37  
    38  	ctx.HTML(http.StatusOK, tplStacktrace)
    39  }
    40  
    41  // StacktraceCancel cancels a process
    42  func StacktraceCancel(ctx *context.Context) {
    43  	pid := ctx.Params("pid")
    44  	process.GetManager().Cancel(process.IDType(pid))
    45  	ctx.JSONRedirect(setting.AppSubURL + "/admin/monitor/stacktrace")
    46  }