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 trace.py USDT argument filtering #710

Merged
merged 1 commit into from
Sep 28, 2016
Merged

Conversation

palmtenor
Copy link
Member

@goldshtn fixed general USDT support in trace.py in #698 . However, filtering is still not able to function since we are not reading the arguments correctly.

This Diffs replaces argX variables in filtering conditions to argX_filter, and use the bpf_readarg_N macros to read argument values into argX_filter variables.

In order to define the variables correctly, this Diff also exposes the ability to get USDT argument type (i.e., size) in Python USDT class. I think this would be useful elsewhere as well.

Tested by defining an USDT probe with two parameters in my test binary and run

trace.py 'u:pathToBinary:theProbeName (arg1!=0) "Arg1 %lld Arg2 %s", arg1, arg2'

Generated BPF program looks like:

int probe_contextSwitch_1(struct pt_regs *ctx)
{

        u32 __pid = bpf_get_current_pid_tgid();
        if (__pid == 3787616) { return 0; }

        uint64_t arg1_filter;
        bpf_usdt_readarg(1, ctx, &arg1_filter);

        if (!((arg1_filter!=0))) return 0;

        struct probe_contextSwitch_1_data_t __data = {0};
        __data.timestamp_ns = bpf_ktime_get_ns();
        __data.pid = bpf_get_current_pid_tgid();
        bpf_get_current_comm(&__data.comm, sizeof(__data.comm));
        u64 arg1;
        bpf_usdt_readarg(1, ctx, &arg1);
        __data.v0 = (long long)arg1;
        u64 arg2;
        bpf_usdt_readarg(2, ctx, &arg2);

        if (arg2 != 0) {
                bpf_probe_read(&__data.v1, sizeof(__data.v1), (void *)arg2);
        }

        probe_contextSwitch_1_events.perf_submit(ctx, &__data, sizeof(__data));
        return 0;
}

@4ast
Copy link
Member

4ast commented Sep 28, 2016

Teng, Thanks for the fix!
@goldshtn please review.

Copy link
Collaborator

@goldshtn goldshtn left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good. I totally forgot about the filters, and it's really great that you were able to fix them cleanly. Getting the argument type for each argument will be useful for @4ast 's request to print this information in -v -v mode.

def _generate_usdt_filter_read(self):
text = ""
if self.probe_type == "u":
for arg, _ in Probe.aliases.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just check arg[0:3] == "arg" as we do elsewhere? It's just that depending on Probe.aliases is a bit fragile, because the arg aliases are not really used for USDT probes and might change or move at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we should do this. The issue here is for filters, unlike the return (printf) values, we don't actually parse them. We just take what's in between brackets in the CLI argument and put it in the if statement directly, with some direct find-and-replace on variable names (as you can see here). We would have to parse the filter expression in order to get type and expr as we do for printf values:(

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, forgot about that. The filter is indeed quite unstructured. Good to go then.

arg_ctype = self.usdt.get_probe_arg_ctype(
self.usdt_name, arg_index)
if not arg_ctype:
self._bail("Unable to determine type {} "
Copy link
Collaborator

@goldshtn goldshtn Sep 28, 2016

Choose a reason for hiding this comment

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

Maybe "Unable to determine type of {} " to be a bit clearer. (Add "of".)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done:)

@4ast 4ast merged commit 0615bff into iovisor:master Sep 28, 2016
@palmtenor palmtenor deleted the usdtfilter branch September 28, 2016 18:33
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.

None yet

3 participants