iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

libbpf-tools/map_helpers: Fix duplicate map read operations #4998

Closed ekyooo closed 4 months ago

ekyooo commented 4 months ago

Even when the batch read is successful, a non-batch read is performed. Fixed so that non-batch reads are not performed once batch reads are done.

This is the result of testing tcpconnect by adding some logs to map_helpers.

Before:

  ./tcpconnect -c
    dump_hash_batch, *count: 3
    k: 16777343, v: 1
    k: 50331775, v: 0
    k: 385875968, v: 1

    dump_hash_iter, *count: 3
    k: 16777343, v: 1
    k: 50331775, v: 0
    k: 385875968, v: 1

    LADDR                     RADDR                     RPORT                CONNECT
    127.0.0.1                 127.0.0.3                 23                   1
    127.0.0.1                 127.0.0.1                 23                   1
    127.0.0.1                 127.0.0.2                 23                   1

After:

  ./tcpconnect -c
    dump_hash_batch *count: 2
    k: 16777343, v: 1
    k: 16777343, v: 0

    LADDR                     RADDR                     RPORT                CONNECT
    127.0.0.1                 127.0.0.1                 23                   1
    127.0.0.1                 127.0.0.2                 23                   1