"runtime"
"runtime/pprof"
tracepkg "runtime/trace"
+ "strings"
"cmd/compile/internal/base"
)
+func profileName(fn, suffix string) string {
+ if strings.HasSuffix(fn, string(os.PathSeparator)) {
+ err := os.MkdirAll(fn, 0755)
+ if err != nil {
+ base.Fatalf("%v", err)
+ }
+ }
+ if fi, statErr := os.Stat(fn); statErr == nil && fi.IsDir() {
+ fn = filepath.Join(fn, url.PathEscape(base.Ctxt.Pkgpath)+suffix)
+ }
+ return fn
+}
+
func startProfile() {
if base.Flag.CPUProfile != "" {
- f, err := os.Create(base.Flag.CPUProfile)
+ fn := profileName(base.Flag.CPUProfile, ".cpuprof")
+ f, err := os.Create(fn)
if err != nil {
base.Fatalf("%v", err)
}
// gzipFormat is what most people want, otherwise
var format = textFormat
fn := base.Flag.MemProfile
+ if strings.HasSuffix(fn, string(os.PathSeparator)) {
+ err := os.MkdirAll(fn, 0755)
+ if err != nil {
+ base.Fatalf("%v", err)
+ }
+ }
if fi, statErr := os.Stat(fn); statErr == nil && fi.IsDir() {
- fn = filepath.Join(fn, url.PathEscape(base.Ctxt.Pkgpath)+".mprof")
+ fn = filepath.Join(fn, url.PathEscape(base.Ctxt.Pkgpath)+".memprof")
format = gzipFormat
}
runtime.MemProfileRate = 0
}
if base.Flag.BlockProfile != "" {
- f, err := os.Create(base.Flag.BlockProfile)
+ f, err := os.Create(profileName(base.Flag.BlockProfile, ".blockprof"))
if err != nil {
base.Fatalf("%v", err)
}
})
}
if base.Flag.MutexProfile != "" {
- f, err := os.Create(base.Flag.MutexProfile)
+ f, err := os.Create(profileName(base.Flag.MutexProfile, ".mutexprof"))
if err != nil {
base.Fatalf("%v", err)
}
})
}
if base.Flag.TraceProfile != "" {
- f, err := os.Create(base.Flag.TraceProfile)
+ f, err := os.Create(profileName(base.Flag.TraceProfile, ".trace"))
if err != nil {
base.Fatalf("%v", err)
}