MCPcopy
hub / github.com/google/mtail / BenchmarkProgram

Function BenchmarkProgram

internal/mtail/examples_integration_test.go:149–187  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

147}
148
149func BenchmarkProgram(b *testing.B) {
150 for _, bm := range exampleProgramTests {
151 bm := bm
152 b.Run(fmt.Sprintf("%s on %s", bm.programfile, bm.logfile), func(b *testing.B) {
153 b.ReportAllocs()
154 logDir := testutil.TestTempDir(b)
155 logFile := filepath.Join(logDir, "test.log")
156 log := testutil.TestOpenFile(b, logFile)
157 ctx, cancel := context.WithCancel(context.Background())
158 waker, awaken := waker.NewTest(ctx, 1, "streams")
159 store := metrics.NewStore()
160 programFile := filepath.Join("../..", bm.programfile)
161 mtail, err := mtail.New(ctx, store, mtail.ProgramPath(programFile), mtail.LogPathPatterns(log.Name()), mtail.LogstreamPollWaker(waker))
162 testutil.FatalIfErr(b, err)
163
164 var wg sync.WaitGroup
165 wg.Add(1)
166 go func() {
167 defer wg.Done()
168 testutil.FatalIfErr(b, mtail.Run())
169 }()
170
171 var total int64
172 b.ResetTimer()
173 for i := 0; i < b.N; i++ {
174 l, err := os.Open(bm.logfile)
175 testutil.FatalIfErr(b, err)
176 count, err := io.Copy(log, l)
177 testutil.FatalIfErr(b, err)
178 total += count
179 awaken(1, 1)
180 }
181 cancel()
182 wg.Wait()
183 b.StopTimer()
184 b.SetBytes(total)
185 })
186 }
187}

Callers

nothing calls this directly

Calls 10

TestTempDirFunction · 0.92
TestOpenFileFunction · 0.92
NewStoreFunction · 0.92
NewFunction · 0.92
ProgramPathTypeAlias · 0.92
LogPathPatternsFunction · 0.92
LogstreamPollWakerFunction · 0.92
FatalIfErrFunction · 0.92
RunMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected