Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: print() no output when used on hist() maps with large top args #1437

Merged
merged 1 commit into from
Jul 25, 2020

Conversation

suyuee
Copy link
Contributor

@suyuee suyuee commented Jul 23, 2020

Currently, using print with a large top arg (any number larger than number
of map keys) on hist maps would result in a negative overflow bug, which will
make print fail to produce any output. This patch resolves this issue.

output.cpp
void TextOutput::map_hist
{
...
    if (top)
    {
        std::cerr << "values_by_key.size()       = " << values_by_key.size()       << std::endl;
        std::cerr << "                       top = " <<                        top << std::endl;
        std::cerr << "values_by_key.size() - top = " << values_by_key.size() - top << std::endl;
        if (i++ < (values_by_key.size() - top))
            continue;
    }
...
}

// output
# bpftrace -e 'kretprobe:vfs_read { @bytes = hist(retval); } i:s:5 {print(@bytes, 2, 1); exit();} END { clear(@bytes); }'
values_by_key.size()       = 1
                       top = 2
values_by_key.size() - top = 18446744073709551615
Checklist
  • Language changes are updated in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md

Currently, using `print` with a large `top` arg (any number larger than number
of map keys) on `hist` maps would result in a negative overflow bug, which will
make `print` fail to produce any output. This patch resolves this issue.
@suyuee suyuee force-pushed the fix_print_hist_with_top_arg branch from 1fc2c52 to e657f80 Compare July 24, 2020 21:24
@suyuee
Copy link
Contributor Author

suyuee commented Jul 24, 2020

Update CHANGLOG.md

Copy link
Member

@danobi danobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM

@danobi danobi merged commit b602b61 into bpftrace:master Jul 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants