(t *testing.T)
| 21 | } |
| 22 | |
| 23 | func TestCPUProfilerTime(t *testing.T) { |
| 24 | currentTime := int64(0) |
| 25 | |
| 26 | p := ProfilingFor(nil).CPUProfiler( |
| 27 | TimeFunc(func() int64 { return currentTime }), |
| 28 | ) |
| 29 | |
| 30 | module := wazerotest.NewModule(nil, |
| 31 | wazerotest.NewFunction(func(context.Context, api.Module) {}), |
| 32 | wazerotest.NewFunction(func(context.Context, api.Module) {}), |
| 33 | wazerotest.NewFunction(func(context.Context, api.Module) {}), |
| 34 | ) |
| 35 | |
| 36 | f0 := p.NewFunctionListener(module.Function(0).Definition()) |
| 37 | f1 := p.NewFunctionListener(module.Function(1).Definition()) |
| 38 | f2 := p.NewFunctionListener(module.Function(2).Definition()) |
| 39 | |
| 40 | stack0 := []experimental.StackFrame{ |
| 41 | {Function: module.Function(0)}, |
| 42 | } |
| 43 | |
| 44 | stack1 := []experimental.StackFrame{ |
| 45 | {Function: module.Function(0)}, |
| 46 | {Function: module.Function(1)}, |
| 47 | } |
| 48 | |
| 49 | stack2 := []experimental.StackFrame{ |
| 50 | {Function: module.Function(0)}, |
| 51 | {Function: module.Function(1)}, |
| 52 | {Function: module.Function(2)}, |
| 53 | } |
| 54 | |
| 55 | def0 := stack0[0].Function.Definition() |
| 56 | def1 := stack1[1].Function.Definition() |
| 57 | def2 := stack2[2].Function.Definition() |
| 58 | |
| 59 | ctx := context.Background() |
| 60 | |
| 61 | const ( |
| 62 | t0 int64 = 1 |
| 63 | t1 int64 = 10 |
| 64 | t2 int64 = 42 |
| 65 | t3 int64 = 100 |
| 66 | t4 int64 = 101 |
| 67 | t5 int64 = 102 |
| 68 | ) |
| 69 | |
| 70 | p.StartProfile() |
| 71 | |
| 72 | currentTime = t0 |
| 73 | f0.Before(ctx, module, def0, nil, experimental.NewStackIterator(stack0...)) |
| 74 | |
| 75 | currentTime = t1 |
| 76 | f1.Before(ctx, module, def1, nil, experimental.NewStackIterator(stack1...)) |
| 77 | |
| 78 | currentTime = t2 |
| 79 | f2.Before(ctx, module, def2, nil, experimental.NewStackIterator(stack2...)) |
| 80 |
nothing calls this directly
no test coverage detected