Remove wzprof.

This commit is contained in:
Nuno Cruces
2023-06-01 23:48:33 +01:00
parent 7bf5312bd4
commit 8fe77a065c
4 changed files with 3 additions and 90 deletions

View File

@@ -35,7 +35,7 @@ var (
instances atomic.Uint64
)
func init() {
func TestMain(m *testing.M) {
ctx := context.TODO()
rt = wazero.NewRuntime(ctx)
@@ -52,6 +52,8 @@ func init() {
if err != nil {
panic(err)
}
os.Exit(m.Run())
}
func config(ctx context.Context) wazero.ModuleConfig {

View File

@@ -6,7 +6,6 @@ import (
"crypto/rand"
"flag"
"io"
"log"
"os"
"path/filepath"
"runtime"
@@ -16,9 +15,7 @@ import (
_ "embed"
"github.com/stealthrocket/wzprof"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/ncruces/go-sqlite3/vfs"
@@ -33,16 +30,12 @@ var (
module wazero.CompiledModule
output bytes.Buffer
options []string
cpuprof string
memprof string
)
func TestMain(m *testing.M) {
initFlags()
ctx := context.Background()
ctx, prof, cpu, mem := setupProfiling(ctx)
rt = wazero.NewRuntime(ctx)
wasi_snapshot_preview1.MustInstantiate(ctx, rt)
env := vfs.ExportHostFunctions(rt.NewHostModuleBuilder("env"))
@@ -59,12 +52,10 @@ func TestMain(m *testing.M) {
code := m.Run()
defer os.Exit(code)
io.Copy(os.Stderr, &output)
saveProfiles(module, prof, cpu, mem)
}
func initFlags() {
i := 1
wzprof := false
options = append(options, "speedtest1")
for _, arg := range os.Args[1:] {
switch {
@@ -72,9 +63,6 @@ func initFlags() {
// keep test flags
os.Args[i] = arg
i++
case strings.HasSuffix(arg, "-wzprof"):
// collect guest profile
wzprof = true
default:
// collect everything else
options = append(options, arg)
@@ -82,71 +70,6 @@ func initFlags() {
}
os.Args = os.Args[:i]
flag.Parse()
if wzprof {
var f *flag.Flag
f = flag.Lookup("test.cpuprofile")
cpuprof = f.Value.String()
f.Value.Set("")
f = flag.Lookup("test.memprofile")
memprof = f.Value.String()
f.Value.Set("")
}
}
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 = prof.CPUProfiler()
listeners = append(listeners, cpu)
cpu.StartProfile()
}
if memprof != "" {
mem = prof.MemoryProfiler()
listeners = append(listeners, mem)
}
if listeners != nil {
ctx = context.WithValue(ctx,
experimental.FunctionListenerFactoryKey{},
experimental.MultiFunctionListenerFactory(listeners...))
}
return ctx, prof, cpu, mem
}
func saveProfiles(module wazero.CompiledModule, prof *wzprof.Profiling, cpu *wzprof.CPUProfiler, mem *wzprof.MemoryProfiler) {
if cpu == nil && mem == nil {
return
}
log.SetOutput(io.Discard)
err := prof.Prepare(module)
if err != nil {
panic(err)
}
if cpu != nil {
prof := cpu.StopProfile(1)
err := wzprof.WriteProfile(cpuprof, prof)
if err != nil {
panic(err)
}
}
if mem != nil {
prof := mem.NewProfile(1)
err := wzprof.WriteProfile(memprof, prof)
if err != nil {
panic(err)
}
}
}
func Benchmark_speedtest1(b *testing.B) {