[MM-54290] Add CPU profile to support package (#24477)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
153ebc31d7
Коммит
845ea2a984
@@ -10,6 +10,7 @@ import (
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
@@ -21,6 +22,10 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/config"
|
||||
)
|
||||
|
||||
const (
|
||||
cpuProfileDuration = 5 * time.Second
|
||||
)
|
||||
|
||||
func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
// If any errors we come across within this function, we will log it in a warning.txt file so that we know why certain files did not get produced if any
|
||||
var warnings []string
|
||||
@@ -35,6 +40,7 @@ func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
"config": a.createSanitizedConfigFile,
|
||||
"mattermost log": a.getMattermostLog,
|
||||
"notification log": a.getNotificationsLog,
|
||||
"cpu profile": a.createCPUProfile,
|
||||
"heap profile": a.createHeapProfile,
|
||||
}
|
||||
|
||||
@@ -294,6 +300,25 @@ func (a *App) createSanitizedConfigFile(_ *request.Context) (*model.FileData, er
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) createCPUProfile(_ *request.Context) (*model.FileData, error) {
|
||||
var b bytes.Buffer
|
||||
|
||||
err := pprof.StartCPUProfile(&b)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to start CPU profile")
|
||||
}
|
||||
|
||||
time.Sleep(cpuProfileDuration)
|
||||
|
||||
pprof.StopCPUProfile()
|
||||
|
||||
fileData := &model.FileData{
|
||||
Filename: "cpu.prof",
|
||||
Body: b.Bytes(),
|
||||
}
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (a *App) createHeapProfile(*request.Context) (*model.FileData, error) {
|
||||
var b bytes.Buffer
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user