Ejemplo n.º 1
0
Archivo: trace.py Proyecto: AoJ/bcc
 def _parse_spec(self, spec):
         parts = spec.split(":")
         # Two special cases: 'func' means 'p::func', 'lib:func' means
         # 'p:lib:func'. Other combinations need to provide an empty
         # value between delimiters, e.g. 'r::func' for a kretprobe on
         # the function func.
         if len(parts) == 1:
                 parts = ["p", "", parts[0]]
         elif len(parts) == 2:
                 parts = ["p", parts[0], parts[1]]
         if len(parts[0]) == 0:
                 self.probe_type = "p"
         elif parts[0] in ["p", "r", "t", "u"]:
                 self.probe_type = parts[0]
         else:
                 self._bail("probe type must be '', 'p', 't', 'r', " +
                            "or 'u', but got '%s'" % parts[0])
         if self.probe_type == "t":
                 self.tp_category = parts[1]
                 self.tp_event = parts[2]
                 self.tp = Tracepoint.enable_tracepoint(
                                 self.tp_category, self.tp_event)
                 self.library = ""       # kernel
                 self.function = "perf_trace_%s" % self.tp_event
         elif self.probe_type == "u":
                 self.library = parts[1]
                 self.usdt_name = parts[2]
                 self.function = ""      # no function, just address
                 # We will discover the USDT provider by matching on
                 # the USDT name in the specified library
                 self._find_usdt_probe()
                 self._enable_usdt_probe()
         else:
                 self.library = parts[1]
                 self.function = parts[2]
Ejemplo n.º 2
0
        def __init__(self, type, specifier, pid):
                self.raw_spec = specifier
                self._validate_specifier()

                spec_and_label = specifier.split('#')
                self.label = spec_and_label[1] \
                             if len(spec_and_label) == 2 else None

                parts = spec_and_label[0].strip().split(':')
                self.type = type    # hist or freq
                self.probe_type = parts[0]
                fparts = parts[2].split('(')
                self.function = fparts[0].strip()
                if self.probe_type == "t":
                        self.library = ""       # kernel
                        self.tp_category = parts[1]
                        self.tp_event = self.function
                        self.tp = Tracepoint.enable_tracepoint(
                                        self.tp_category, self.tp_event)
                        self.function = "perf_trace_" + self.function
                else:
                        self.library = parts[1]
                self.is_user = len(self.library) > 0
                self.signature = fparts[1].strip()[:-1]
                self._parse_signature()

                # If the user didn't specify an expression to probe, we probe
                # the retval in a ret probe, or simply the value "1" otherwise.
                self.is_default_expr = len(parts) < 5
                if not self.is_default_expr:
                        self._parse_expr_types(parts[3])
                        self._parse_exprs(parts[4])
                        if len(self.exprs) != len(self.expr_types):
                                self._bail("mismatched # of exprs and types")
                        if self.type == "hist" and len(self.expr_types) > 1:
                                self._bail("histograms can only have 1 expr")
                else:
                        if not self.probe_type == "r" and self.type == "hist":
                                self._bail("histograms must have expr")
                        self.expr_types = \
                          ["u64" if not self.probe_type == "r" else "int"]
                        self.exprs = \
                          ["1" if not self.probe_type == "r" else "$retval"]
                self.filter = "" if len(parts) != 6 else parts[5]
                self._substitute_exprs()

                # Do we need to attach an entry probe so that we can collect an
                # argument that is required for an exit (return) probe?
                def check(expr):
                        keywords = ["$entry", "$latency"]
                        return any(map(lambda kw: kw in expr, keywords))
                self.entry_probe_required = self.probe_type == "r" and \
                        (any(map(check, self.exprs)) or check(self.filter))

                self.pid = pid
                self.probe_func_name = "%s_probe%d" % \
                        (self.function, Specifier.next_probe_index)
                self.probe_hash_name = "%s_hash%d" % \
                        (self.function, Specifier.next_probe_index)
                Specifier.next_probe_index += 1
Ejemplo n.º 3
0
 def _parse_spec(self, spec):
     parts = spec.split(":")
     # Two special cases: 'func' means 'p::func', 'lib:func' means
     # 'p:lib:func'. Other combinations need to provide an empty
     # value between delimiters, e.g. 'r::func' for a kretprobe on
     # the function func.
     if len(parts) == 1:
         parts = ["p", "", parts[0]]
     elif len(parts) == 2:
         parts = ["p", parts[0], parts[1]]
     if len(parts[0]) == 0:
         self.probe_type = "p"
     elif parts[0] in ["p", "r", "t"]:
         self.probe_type = parts[0]
     else:
         self._bail("expected '', 'p', 't', or 'r', got '%s'" % parts[0])
     if self.probe_type == "t":
         self.tp_category = parts[1]
         self.tp_event = parts[2]
         self.tp = Tracepoint.enable_tracepoint(self.tp_category,
                                                self.tp_event)
         self.library = ""  # kernel
         self.function = "perf_trace_%s" % self.tp_event
     else:
         self.library = parts[1]
         self.function = parts[2]
Ejemplo n.º 4
0
 def _parse_spec(self, spec):
         parts = spec.split(":")
         # Two special cases: 'func' means 'p::func', 'lib:func' means
         # 'p:lib:func'. Other combinations need to provide an empty
         # value between delimiters, e.g. 'r::func' for a kretprobe on
         # the function func.
         if len(parts) == 1:
                 parts = ["p", "", parts[0]]
         elif len(parts) == 2:
                 parts = ["p", parts[0], parts[1]]
         if len(parts[0]) == 0:
                 self.probe_type = "p"
         elif parts[0] in ["p", "r", "t", "u"]:
                 self.probe_type = parts[0]
         else:
                 self._bail("probe type must be '', 'p', 't', 'r', " +
                            "or 'u', but got '%s'" % parts[0])
         if self.probe_type == "t":
                 self.tp_category = parts[1]
                 self.tp_event = parts[2]
                 self.tp = Tracepoint.enable_tracepoint(
                                 self.tp_category, self.tp_event)
                 self.library = ""       # kernel
                 self.function = "perf_trace_%s" % self.tp_event
         elif self.probe_type == "u":
                 self.library = parts[1]
                 self.usdt_name = parts[2]
                 self.function = ""      # no function, just address
                 # We will discover the USDT provider by matching on
                 # the USDT name in the specified library
                 self._find_usdt_probe()
                 self._enable_usdt_probe()
         else:
                 self.library = parts[1]
                 self.function = parts[2]
Ejemplo n.º 5
0
    def __init__(self, type, specifier, pid):
        self.raw_spec = specifier
        self._validate_specifier()

        spec_and_label = specifier.split('#')
        self.label = spec_and_label[1] \
                     if len(spec_and_label) == 2 else None

        parts = spec_and_label[0].strip().split(':')
        self.type = type  # hist or freq
        self.probe_type = parts[0]
        fparts = parts[2].split('(')
        self.function = fparts[0].strip()
        if self.probe_type == "t":
            self.library = ""  # kernel
            self.tp_category = parts[1]
            self.tp_event = self.function
            self.tp = Tracepoint.enable_tracepoint(self.tp_category,
                                                   self.tp_event)
            self.function = "perf_trace_" + self.function
        else:
            self.library = parts[1]
        self.is_user = len(self.library) > 0
        self.signature = fparts[1].strip()[:-1]
        self._parse_signature()

        # If the user didn't specify an expression to probe, we probe
        # the retval in a ret probe, or simply the value "1" otherwise.
        self.is_default_expr = len(parts) < 5
        if not self.is_default_expr:
            self._parse_expr_types(parts[3])
            self._parse_exprs(parts[4])
            if len(self.exprs) != len(self.expr_types):
                self._bail("mismatched # of exprs and types")
            if self.type == "hist" and len(self.expr_types) > 1:
                self._bail("histograms can only have 1 expr")
        else:
            if not self.probe_type == "r" and self.type == "hist":
                self._bail("histograms must have expr")
            self.expr_types = \
              ["u64" if not self.probe_type == "r" else "int"]
            self.exprs = \
              ["1" if not self.probe_type == "r" else "$retval"]
        self.filter = "" if len(parts) != 6 else parts[5]
        self._substitute_exprs()

        # Do we need to attach an entry probe so that we can collect an
        # argument that is required for an exit (return) probe?
        def check(expr):
            keywords = ["$entry", "$latency"]
            return any(map(lambda kw: kw in expr, keywords))
        self.entry_probe_required = self.probe_type == "r" and \
                (any(map(check, self.exprs)) or check(self.filter))

        self.pid = pid
        self.probe_func_name = "%s_probe%d" % \
                (self.function, Specifier.next_probe_index)
        self.probe_hash_name = "%s_hash%d" % \
                (self.function, Specifier.next_probe_index)
        Specifier.next_probe_index += 1
Ejemplo n.º 6
0
 def _parse_spec(self, spec):
         parts = spec.split(":")
         # Two special cases: 'func' means 'p::func', 'lib:func' means
         # 'p:lib:func'. Other combinations need to provide an empty
         # value between delimiters, e.g. 'r::func' for a kretprobe on
         # the function func.
         if len(parts) == 1:
                 parts = ["p", "", parts[0]]
         elif len(parts) == 2:
                 parts = ["p", parts[0], parts[1]]
         if len(parts[0]) == 0:
                 self.probe_type = "p"
         elif parts[0] in ["p", "r", "t"]:
                 self.probe_type = parts[0]
         else:
                 self._bail("expected '', 'p', 't', or 'r', got '%s'" %
                            parts[0])
         if self.probe_type == "t":
                 self.tp_category = parts[1]
                 self.tp_event = parts[2]
                 self.tp = Tracepoint.enable_tracepoint(
                                 self.tp_category, self.tp_event)
                 self.library = ""       # kernel
                 self.function = "perf_trace_%s" % self.tp_event
         else:
                 self.library = parts[1]
                 self.function = parts[2]