Revert "Improve trace logging for pulls and processes (#22633) (#22812)"

This reverts commit e4238583db.

Refs: https://codeberg.org/forgejo/forgejo/issues/395
This commit is contained in:
Loïc Dachary 2023-02-20 19:58:59 +01:00
commit cb7ea004ee
No known key found for this signature in database
GPG key ID: 992D23B392F9E4F2
9 changed files with 145 additions and 228 deletions

View file

@ -7,7 +7,6 @@ package process
import (
"context"
"log"
"runtime/pprof"
"strconv"
"sync"
@ -45,18 +44,6 @@ type IDType string
// - it is simply an alias for context.CancelFunc and is only for documentary purposes
type FinishedFunc = context.CancelFunc
var Trace = defaultTrace // this global can be overridden by particular logging packages - thus avoiding import cycles
func defaultTrace(start bool, pid IDType, description string, parentPID IDType, typ string) {
if start && parentPID != "" {
log.Printf("start process %s: %s (from %s) (%s)", pid, description, parentPID, typ)
} else if start {
log.Printf("start process %s: %s (%s)", pid, description, typ)
} else {
log.Printf("end process %s: %s", pid, description)
}
}
// Manager manages all processes and counts PIDs.
type Manager struct {
mutex sync.Mutex
@ -168,7 +155,6 @@ func (pm *Manager) Add(ctx context.Context, description string, cancel context.C
pm.processMap[pid] = process
pm.mutex.Unlock()
Trace(true, pid, description, parentPID, processType)
pprofCtx := pprof.WithLabels(ctx, pprof.Labels(DescriptionPProfLabel, description, PPIDPProfLabel, string(parentPID), PIDPProfLabel, string(pid), ProcessTypePProfLabel, processType))
if currentlyRunning {
@ -200,12 +186,18 @@ func (pm *Manager) nextPID() (start time.Time, pid IDType) {
return start, pid
}
// Remove a process from the ProcessManager.
func (pm *Manager) Remove(pid IDType) {
pm.mutex.Lock()
delete(pm.processMap, pid)
pm.mutex.Unlock()
}
func (pm *Manager) remove(process *process) {
pm.mutex.Lock()
defer pm.mutex.Unlock()
if p := pm.processMap[process.PID]; p == process {
delete(pm.processMap, process.PID)
Trace(false, process.PID, process.Description, process.ParentPID, process.Type)
}
}