forgejo/modules/process/process.go
Gusted 3f44b97b5f
feat: add limited execution tracing support
- For every process that is spawned (every new non-trivial goroutine
such as http requests, queues or tasks) start a [execution
tracer](https://pkg.go.dev/runtime/trace). This allows very precise
diagnosis of how each individual process over a time period.
- It's safe and [fast](https://go.dev/blog/execution-traces-2024#low-overhead-tracing) to
be run in production, hence no setting to disable this. There's only
noticable overhead when tracing is actually performed and not continuous.
- Proper tracing support would mean the codebase would be full of
`trace.WithRegion` and `trace.Log`, which feels premature for this patch
as there's no real-world usage yet to indicate which places would need
this the most. So far only Git commands and SQL queries receive somewhat
proper tracing support given that these are used throughout the codebase.
- Make git commands a new process type.
- Add tracing to diagnosis zip file.
2025-01-05 04:07:49 +01:00

41 lines
869 B
Go

// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package process
import (
"context"
"runtime/trace"
"time"
)
var (
SystemProcessType = "system"
RequestProcessType = "request"
GitProcessType = "git"
NormalProcessType = "normal"
NoneProcessType = "none"
)
// process represents a working process inheriting from Gitea.
type process struct {
PID IDType // Process ID, not system one.
ParentPID IDType
Description string
Start time.Time
Cancel context.CancelFunc
Type string
TraceTrask *trace.Task
}
// ToProcess converts a process to a externally usable Process
func (p *process) toProcess() *Process {
process := &Process{
PID: p.PID,
ParentPID: p.ParentPID,
Description: p.Description,
Start: p.Start,
Type: p.Type,
}
return process
}