mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 17:13:19 +08:00
drop 0.4mb "runtime/pprof" and "runtime/trace" (#836)
This commit is contained in:
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -184,34 +182,22 @@ func main() {
|
||||
// To view a CPU trace, use "go tool trace [file]". Note that the trace
|
||||
// viewer doesn't work under Windows Subsystem for Linux for some reason.
|
||||
if traceFile != "" {
|
||||
f, err := os.Create(traceFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create trace file: %s", err.Error()))
|
||||
if done := createTraceFile(osArgs, traceFile); done == nil {
|
||||
return
|
||||
} else {
|
||||
defer done()
|
||||
}
|
||||
defer f.Close()
|
||||
trace.Start(f)
|
||||
defer trace.Stop()
|
||||
}
|
||||
|
||||
// To view a heap trace, use "go tool pprof [file]" and type "top". You can
|
||||
// also drop it into https://speedscope.app and use the "left heavy" or
|
||||
// "sandwich" view modes.
|
||||
if heapFile != "" {
|
||||
f, err := os.Create(heapFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create heap file: %s", err.Error()))
|
||||
if done := createHeapFile(osArgs, heapFile); done == nil {
|
||||
return
|
||||
} else {
|
||||
defer done()
|
||||
}
|
||||
defer func() {
|
||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to write heap profile: %s", err.Error()))
|
||||
}
|
||||
f.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
// To view a CPU profile, drop the file into https://speedscope.app.
|
||||
@@ -219,15 +205,11 @@ func main() {
|
||||
// Linux. The profiler has to be built for native Windows and run using the
|
||||
// command prompt instead.
|
||||
if cpuprofileFile != "" {
|
||||
f, err := os.Create(cpuprofileFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create cpuprofile file: %s", err.Error()))
|
||||
if done := createCpuprofileFile(osArgs, cpuprofileFile); done == nil {
|
||||
return
|
||||
} else {
|
||||
defer done()
|
||||
}
|
||||
defer f.Close()
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
if cpuprofileFile != "" {
|
||||
|
||||
56
cmd/esbuild/main_other.go
Normal file
56
cmd/esbuild/main_other.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// +build !js !wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"runtime/trace"
|
||||
|
||||
"github.com/evanw/esbuild/internal/logger"
|
||||
)
|
||||
|
||||
func createTraceFile(osArgs []string, traceFile string) func() {
|
||||
f, err := os.Create(traceFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create trace file: %s", err.Error()))
|
||||
return nil
|
||||
}
|
||||
trace.Start(f)
|
||||
return func() {
|
||||
trace.Stop()
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func createHeapFile(osArgs []string, heapFile string) func() {
|
||||
f, err := os.Create(heapFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create heap file: %s", err.Error()))
|
||||
return nil
|
||||
}
|
||||
return func() {
|
||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to write heap profile: %s", err.Error()))
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func createCpuprofileFile(osArgs []string, cpuprofileFile string) func() {
|
||||
f, err := os.Create(cpuprofileFile)
|
||||
if err != nil {
|
||||
logger.PrintErrorToStderr(osArgs, fmt.Sprintf(
|
||||
"Failed to create cpuprofile file: %s", err.Error()))
|
||||
return nil
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
return func() {
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
24
cmd/esbuild/main_wasm.go
Normal file
24
cmd/esbuild/main_wasm.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// +build js,wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/evanw/esbuild/internal/logger"
|
||||
)
|
||||
|
||||
// Remove this code from the WebAssembly binary to reduce size. This only removes 0.4mb of stuff.
|
||||
|
||||
func createTraceFile(osArgs []string, traceFile string) func() {
|
||||
logger.PrintErrorToStderr(osArgs, "The \"--trace\" flag is not supported when using WebAssembly")
|
||||
return nil
|
||||
}
|
||||
|
||||
func createHeapFile(osArgs []string, heapFile string) func() {
|
||||
logger.PrintErrorToStderr(osArgs, "The \"--heap\" flag is not supported when using WebAssembly")
|
||||
return nil
|
||||
}
|
||||
|
||||
func createCpuprofileFile(osArgs []string, cpuprofileFile string) func() {
|
||||
logger.PrintErrorToStderr(osArgs, "The \"--cpuprofile\" flag is not supported when using WebAssembly")
|
||||
return nil
|
||||
}
|
||||
@@ -4,6 +4,8 @@ package api
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Remove the serve API in the WebAssembly build. This removes 2.7mb of stuff.
|
||||
|
||||
func serveImpl(serveOptions ServeOptions, buildOptions BuildOptions) (ServeResult, error) {
|
||||
return ServeResult{}, fmt.Errorf("The \"serve\" API is not supported when using WebAssembly")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user