static bool read_counts_map()

in profiler/stack_printer.cpp [87:129]


static bool read_counts_map(int fd, struct key_ext_t *items, __u32 *count)
{
    struct stack_key empty = {};
    struct stack_key *lookup_key = ∅
    int i = 0;
    int err;

    if (batch_map_ops)
    {
        bool ok = read_batch_counts_map(fd, items, count);
        if (!ok && errno == EINVAL)
        {
            /* fall back to a racy variant */
            batch_map_ops = false;
        }
        else
        {
            return ok;
        }
    }

    if (!items || !count || !*count)
        return true;

    while (!bpf_map_get_next_key(fd, lookup_key, &items[i].k))
    {

        err = bpf_map_lookup_elem(fd, &items[i].k, &items[i].v);
        if (err < 0)
        {
            fprintf(stderr, "failed to lookup counts: %d\n", err);
            return false;
        }
        if (items[i].v == 0)
            continue;

        lookup_key = &items[i].k;
        i++;
    }

    *count = i;
    return true;
}