当前位置: 首页>>代码示例>>Python>>正文


Python USDT.get_probe_arg_ctype方法代码示例

本文整理汇总了Python中bcc.USDT.get_probe_arg_ctype方法的典型用法代码示例。如果您正苦于以下问题:Python USDT.get_probe_arg_ctype方法的具体用法?Python USDT.get_probe_arg_ctype怎么用?Python USDT.get_probe_arg_ctype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bcc.USDT的用法示例。


在下文中一共展示了USDT.get_probe_arg_ctype方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Probe

# 需要导入模块: from bcc import USDT [as 别名]
# 或者: from bcc.USDT import get_probe_arg_ctype [as 别名]

#.........这里部分代码省略.........
                }
        }
        return true;
}
                """ % (fname, string)
                return fname

        def _substitute_exprs(self):
                def repl(expr):
                        expr = self._substitute_aliases(expr)
                        matches = re.finditer('STRCMP\\(("[^"]+\\")', expr)
                        for match in matches:
                                string = match.group(1)
                                fname = self._generate_streq_function(string)
                                expr = expr.replace("STRCMP", fname, 1)
                        return expr.replace("$retval", "PT_REGS_RC(ctx)")
                for i in range(0, len(self.exprs)):
                        self.exprs[i] = repl(self.exprs[i])
                self.filter = repl(self.filter)

        def _is_string(self, expr_type):
                return expr_type == "char*" or expr_type == "char *"

        def _generate_hash_field(self, i):
                if self._is_string(self.expr_types[i]):
                        return "struct __string_t v%d;\n" % i
                else:
                        return "%s v%d;\n" % (self.expr_types[i], i)

        def _generate_usdt_arg_assignment(self, i):
                expr = self.exprs[i]
                if self.probe_type == "u" and expr[0:3] == "arg":
                        arg_index = int(expr[3])
                        arg_ctype = self.usdt_ctx.get_probe_arg_ctype(
                                self.function, arg_index - 1)
                        return ("        %s %s = 0;\n" +
                                "        bpf_usdt_readarg(%s, ctx, &%s);\n") \
                                % (arg_ctype, expr, expr[3], expr)
                else:
                        return ""

        def _generate_field_assignment(self, i):
                text = self._generate_usdt_arg_assignment(i)
                if self._is_string(self.expr_types[i]):
                        return (text + "        bpf_probe_read(&__key.v%d.s," +
                                " sizeof(__key.v%d.s), (void *)%s);\n") % \
                                (i, i, self.exprs[i])
                else:
                        return text + "        __key.v%d = %s;\n" % \
                               (i, self.exprs[i])

        def _generate_hash_decl(self):
                if self.type == "hist":
                        return "BPF_HISTOGRAM(%s, %s);" % \
                               (self.probe_hash_name, self.expr_types[0])
                else:
                        text = "struct %s_key_t {\n" % self.probe_hash_name
                        for i in range(0, len(self.expr_types)):
                                text += self._generate_hash_field(i)
                        text += "};\n"
                        text += "BPF_HASH(%s, struct %s_key_t, u64);\n" % \
                                (self.probe_hash_name, self.probe_hash_name)
                        return text

        def _generate_key_assignment(self):
                if self.type == "hist":
开发者ID:felipebetancur,项目名称:bcc,代码行数:70,代码来源:argdist.py

示例2: Probe

# 需要导入模块: from bcc import USDT [as 别名]
# 或者: from bcc.USDT import get_probe_arg_ctype [as 别名]

#.........这里部分代码省略.........
                time_str = "u64 timestamp_ns;" if self.time_field else ""
                cpu_str = "int cpu;" if self.print_cpu else ""
                kernel_stack_str = "       int kernel_stack_id;" \
                                   if self.kernel_stack else ""
                user_stack_str = "       int user_stack_id;" \
                                 if self.user_stack else ""

                text = """
struct %s
{
%s
%s
        u32 tgid;
        u32 pid;
        char comm[TASK_COMM_LEN];
%s
%s
%s
};

BPF_PERF_OUTPUT(%s);
%s
"""
                return text % (self.struct_name, time_str, cpu_str, data_fields,
                               kernel_stack_str, user_stack_str,
                               self.events_name, stack_table)

        def _generate_field_assign(self, idx):
                field_type = self.types[idx]
                expr = self.values[idx].strip()
                text = ""
                if self.probe_type == "u" and expr[0:3] == "arg":
                        arg_index = int(expr[3])
                        arg_ctype = self.usdt.get_probe_arg_ctype(
                                self.usdt_name, arg_index - 1)
                        text = ("        %s %s = 0;\n" +
                                "        bpf_usdt_readarg(%s, ctx, &%s);\n") \
                                % (arg_ctype, expr, expr[3], expr)

                if field_type == "s":
                        return text + """
        if (%s != 0) {
                void *__tmp = (void *)%s;
                bpf_probe_read(&__data.v%d, sizeof(__data.v%d), __tmp);
        }
                """ % (expr, expr, idx, idx)
                if field_type in Probe.fmt_types:
                        return text + "        __data.v%d = (%s)%s;\n" % \
                                        (idx, Probe.c_type[field_type], expr)
                self._bail("unrecognized field type %s" % field_type)

        def _generate_usdt_filter_read(self):
            text = ""
            if self.probe_type != "u":
                    return text
            for arg, _ in Probe.aliases_arg.items():
                    if not (arg in self.filter):
                            continue
                    arg_index = int(arg.replace("arg", ""))
                    arg_ctype = self.usdt.get_probe_arg_ctype(
                            self.usdt_name, arg_index - 1)
                    if not arg_ctype:
                            self._bail("Unable to determine type of {} "
                                       "in the filter".format(arg))
                    text += """
        {} {}_filter;
开发者ID:ColinIanKing,项目名称:bcc,代码行数:70,代码来源:trace.py

示例3: Probe

# 需要导入模块: from bcc import USDT [as 别名]
# 或者: from bcc.USDT import get_probe_arg_ctype [as 别名]

#.........这里部分代码省略.........
BPF_PERF_OUTPUT(%s);
%s
"""
        return text % (self.struct_name, data_fields, kernel_stack_str, user_stack_str, self.events_name, stack_table)

    def _generate_field_assign(self, idx):
        field_type = self.types[idx]
        expr = self.values[idx].strip()
        text = ""
        if self.probe_type == "u" and expr[0:3] == "arg":
            text = ("        u64 %s = 0;\n" + "        bpf_usdt_readarg(%s, ctx, &%s);\n") % (expr, expr[3], expr)

        if field_type == "s":
            return (
                text
                + """
        if (%s != 0) {
                bpf_probe_read(&__data.v%d, sizeof(__data.v%d), (void *)%s);
        }
                """
                % (expr, idx, idx, expr)
            )
        if field_type in Probe.fmt_types:
            return text + "        __data.v%d = (%s)%s;\n" % (idx, Probe.c_type[field_type], expr)
        self._bail("unrecognized field type %s" % field_type)

    def _generate_usdt_filter_read(self):
        text = ""
        if self.probe_type == "u":
            for arg, _ in Probe.aliases.items():
                if not (arg.startswith("arg") and (arg in self.filter)):
                    continue
                arg_index = int(arg.replace("arg", ""))
                arg_ctype = self.usdt.get_probe_arg_ctype(self.usdt_name, arg_index)
                if not arg_ctype:
                    self._bail("Unable to determine type of {} " "in the filter".format(arg))
                text += """
        {} {}_filter;
        bpf_usdt_readarg({}, ctx, &{}_filter);
                        """.format(
                    arg_ctype, arg, arg_index, arg
                )
                self.filter = self.filter.replace(arg, "{}_filter".format(arg))
        return text

    def generate_program(self, include_self):
        data_decl = self._generate_data_decl()
        # kprobes don't have built-in pid filters, so we have to add
        # it to the function body:
        if len(self.library) == 0 and Probe.pid != -1:
            pid_filter = (
                """
        if (__pid != %d) { return 0; }
                """
                % Probe.pid
            )
        elif len(self.library) == 0 and Probe.tgid != -1:
            pid_filter = (
                """
        if (__tgid != %d) { return 0; }
                """
                % Probe.tgid
            )
        elif not include_self:
            pid_filter = (
                """
开发者ID:brendangregg,项目名称:bcc,代码行数:70,代码来源:trace.py


注:本文中的bcc.USDT.get_probe_arg_ctype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。