MCPcopy Create free account
hub / github.com/microsoft/typescript-go / BeginProfiling

Function BeginProfiling

internal/pprof/pprof.go:23–47  ·  view source on GitHub ↗

BeginProfiling starts CPU and memory profiling, writing the profiles to the specified directory.

(profileDir string, logWriter io.Writer)

Source from the content-addressed store, hash-verified

21
22// BeginProfiling starts CPU and memory profiling, writing the profiles to the specified directory.
23func BeginProfiling(profileDir string, logWriter io.Writer) *ProfileSession {
24 if err := os.MkdirAll(profileDir, 0o755); err != nil {
25 panic(err)
26 }
27
28 pid := os.Getpid()
29
30 cpuProfilePath := filepath.Join(profileDir, fmt.Sprintf("%d-cpuprofile.pb.gz", pid))
31 memProfilePath := filepath.Join(profileDir, fmt.Sprintf("%d-memprofile.pb.gz", pid))
32 cpuFile, err := os.Create(cpuProfilePath)
33 if err != nil {
34 panic(err)
35 }
36
37 if err := pprof.StartCPUProfile(cpuFile); err != nil {
38 panic(err)
39 }
40
41 return &ProfileSession{
42 cpuFilePath: cpuProfilePath,
43 memFilePath: memProfilePath,
44 cpuFile: cpuFile,
45 logWriter: logWriter,
46 }
47}
48
49func (p *ProfileSession) Stop() {
50 pprof.StopCPUProfile()

Callers 3

tscBuildCompilationFunction · 0.92
tscCompilationFunction · 0.92
runLSPFunction · 0.92

Calls 3

panicFunction · 0.85
StartCPUProfileMethod · 0.80
MkdirAllMethod · 0.65

Tested by

no test coverage detected