From ae7b74d85806006055dd2c882bc2e6d673e9839d Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 1 Jun 2023 16:09:18 +0100 Subject: [PATCH] Upgrade wzprof. --- go.mod | 8 ++--- go.sum | 16 +++++----- .../tests/speedtest1/speedtest1_test.go | 29 ++++++++++++------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 6641e27..ab67779 100644 --- a/go.mod +++ b/go.mod @@ -5,15 +5,15 @@ go 1.19 require ( github.com/ncruces/julianday v0.1.5 github.com/psanford/httpreadat v0.1.0 - github.com/stealthrocket/wzprof v0.1.4 - github.com/tetratelabs/wazero v1.1.1-0.20230512012700-13e38966b6e0 + github.com/stealthrocket/wzprof v0.1.5 + github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970 golang.org/x/sync v0.2.0 golang.org/x/sys v0.8.0 ) require ( - github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect - golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 // indirect + github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3 // indirect + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect ) retract v0.4.0 // tagged from the wrong branch diff --git a/go.sum b/go.sum index 04babb4..6fc662b 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,15 @@ -github.com/google/pprof v0.0.0-20230406165453-00490a63f317 h1:hFhpt7CTmR3DX+b4R19ydQFtofxT0Sv3QsKNMVQYTMQ= -github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= +github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3 h1:2XF1Vzq06X+inNqgJ9tRnGuw+ZVCB3FazXODD6JE1R8= +github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/ncruces/julianday v0.1.5 h1:hDJ9ejiMp3DHsoZ5KW4c1lwfMjbARS7u/gbYcd0FBZk= github.com/ncruces/julianday v0.1.5/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= github.com/psanford/httpreadat v0.1.0 h1:VleW1HS2zO7/4c7c7zNl33fO6oYACSagjJIyMIwZLUE= github.com/psanford/httpreadat v0.1.0/go.mod h1:Zg7P+TlBm3bYbyHTKv/EdtSJZn3qwbPwpfZ/I9GKCRE= -github.com/stealthrocket/wzprof v0.1.4 h1:Yb/JHAQIpzCrpr/Nw/rgZxqqTigW2HT8SKNs6SLGFV4= -github.com/stealthrocket/wzprof v0.1.4/go.mod h1:lUNsjcNEjviNBV8+MhOGGNBI/SQa7miJQaoXOTgRRok= -github.com/tetratelabs/wazero v1.1.1-0.20230512012700-13e38966b6e0 h1:HlJHKQkBSPsHxseQausjzcbvU+njYSkagrWdCS7x4kU= -github.com/tetratelabs/wazero v1.1.1-0.20230512012700-13e38966b6e0/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= -golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o= -golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +github.com/stealthrocket/wzprof v0.1.5 h1:Y3jQHvdGFQMySV2VIjJhBu08OdcqcflfTz7CvrH5MGM= +github.com/stealthrocket/wzprof v0.1.5/go.mod h1:hqLzj5iDSncc6rlPMhC51O642AkaC+dWVPNNalZdlCY= +github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970 h1:X5OOeHRjoLA8XhVc7biEbh1/hnTzpYpPn7HuyarMslQ= +github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= diff --git a/sqlite3vfs/tests/speedtest1/speedtest1_test.go b/sqlite3vfs/tests/speedtest1/speedtest1_test.go index 39e3e98..c85ef0f 100644 --- a/sqlite3vfs/tests/speedtest1/speedtest1_test.go +++ b/sqlite3vfs/tests/speedtest1/speedtest1_test.go @@ -6,6 +6,7 @@ import ( "crypto/rand" "flag" "io" + "log" "os" "path/filepath" "runtime" @@ -40,7 +41,7 @@ func TestMain(m *testing.M) { initFlags() ctx := context.Background() - ctx, cpu, mem := setupProfiling(ctx) + ctx, prof, cpu, mem := setupProfiling(ctx) rt = wazero.NewRuntime(ctx) wasi_snapshot_preview1.MustInstantiate(ctx, rt) @@ -58,7 +59,7 @@ func TestMain(m *testing.M) { code := m.Run() defer os.Exit(code) io.Copy(os.Stderr, &output) - saveProfiles(module, cpu, mem) + saveProfiles(module, prof, cpu, mem) } func initFlags() { @@ -71,7 +72,7 @@ func initFlags() { // keep test flags os.Args[i] = arg i++ - case arg == "-wzprof": + case strings.HasSuffix(arg, "-wzprof"): // collect guest profile wzprof = true default: @@ -93,18 +94,23 @@ func initFlags() { } } -func setupProfiling(ctx context.Context) (context.Context, *wzprof.CPUProfiler, *wzprof.MemoryProfiler) { +func setupProfiling(ctx context.Context) (context.Context, *wzprof.Profiling, *wzprof.CPUProfiler, *wzprof.MemoryProfiler) { + if cpuprof == "" && memprof == "" { + return ctx, nil, nil, nil + } + var cpu *wzprof.CPUProfiler var mem *wzprof.MemoryProfiler + prof := wzprof.ProfilingFor(binary) var listeners []experimental.FunctionListenerFactory if cpuprof != "" { - cpu = wzprof.NewCPUProfiler() + cpu = prof.CPUProfiler() listeners = append(listeners, cpu) cpu.StartProfile() } if memprof != "" { - mem = wzprof.NewMemoryProfiler() + mem = prof.MemoryProfiler() listeners = append(listeners, mem) } if listeners != nil { @@ -112,21 +118,22 @@ func setupProfiling(ctx context.Context) (context.Context, *wzprof.CPUProfiler, experimental.FunctionListenerFactoryKey{}, experimental.MultiFunctionListenerFactory(listeners...)) } - return ctx, cpu, mem + return ctx, prof, cpu, mem } -func saveProfiles(module wazero.CompiledModule, cpu *wzprof.CPUProfiler, mem *wzprof.MemoryProfiler) { +func saveProfiles(module wazero.CompiledModule, prof *wzprof.Profiling, cpu *wzprof.CPUProfiler, mem *wzprof.MemoryProfiler) { if cpu == nil && mem == nil { return } - symbols, err := wzprof.BuildDwarfSymbolizer(module) + log.SetOutput(io.Discard) + err := prof.Prepare(module) if err != nil { panic(err) } if cpu != nil { - prof := cpu.StopProfile(1, symbols) + prof := cpu.StopProfile(1) err := wzprof.WriteProfile(cpuprof, prof) if err != nil { panic(err) @@ -134,7 +141,7 @@ func saveProfiles(module wazero.CompiledModule, cpu *wzprof.CPUProfiler, mem *wz } if mem != nil { - prof := mem.NewProfile(1, symbols) + prof := mem.NewProfile(1) err := wzprof.WriteProfile(memprof, prof) if err != nil { panic(err)