MCPcopy
hub / github.com/google/gvisor / BenchmarkFDLookupAndDecRefConcurrent

Function BenchmarkFDLookupAndDecRefConcurrent

pkg/sentry/kernel/fd_table_test.go:286–315  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

284}
285
286func BenchmarkFDLookupAndDecRefConcurrent(b *testing.B) {
287 b.StopTimer() // Setup.
288
289 runTest(b, func(ctx context.Context, fdTable *FDTable, fd *vfs.FileDescription, _ *limits.LimitSet) {
290 fds, err := fdTable.NewFDs(ctx, 0, []*vfs.FileDescription{fd, fd, fd, fd, fd}, FDFlags{})
291 if err != nil {
292 b.Fatalf("fdTable.NewFDs: got %v, wanted nil", err)
293 }
294
295 concurrency := runtime.GOMAXPROCS(0)
296 if concurrency < 4 {
297 concurrency = 4
298 }
299 each := b.N / concurrency
300
301 b.StartTimer() // Benchmark.
302 var wg sync.WaitGroup
303 for i := 0; i < concurrency; i++ {
304 wg.Add(1)
305 go func() {
306 defer wg.Done()
307 for i := 0; i < each; i++ {
308 tf, _ := fdTable.Get(fds[i%len(fds)])
309 tf.DecRef(ctx)
310 }
311 }()
312 }
313 wg.Wait()
314 })
315}
316
317func TestSetFlagsForRange(t *testing.T) {
318 type testCase struct {

Callers

nothing calls this directly

Calls 8

runTestFunction · 0.70
FatalfMethod · 0.65
AddMethod · 0.65
GetMethod · 0.65
DecRefMethod · 0.65
WaitMethod · 0.65
NewFDsMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…