From a112514cba8e4844c405e3f1bd341289c4d2a158 Mon Sep 17 00:00:00 2001 From: Derek <“derek0883@gmail.com”> Date: Tue, 31 Jan 2017 18:22:24 -0800 Subject: [PATCH] undo rebase --- tools/argdist.py | 22 ++++++++++------------ tools/cpudist.py | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/argdist.py b/tools/argdist.py index 474af49efea9..f5422d90c827 100755 --- a/tools/argdist.py +++ b/tools/argdist.py @@ -20,7 +20,7 @@ class Probe(object): next_probe_index = 0 streq_index = 0 - aliases = {"$PID": "(bpf_get_current_pid_tgid() >> 32)"} + aliases = {"$PID": "bpf_get_current_pid_tgid()"} def _substitute_aliases(self, expr): if expr is None: @@ -47,9 +47,7 @@ def _generate_entry(self): text = """ int PROBENAME(struct pt_regs *ctx SIGNATURE) { - u64 __pid_tgid = bpf_get_current_pid_tgid(); - u32 __pid = __pid_tgid; // lower 32 bits - u32 __tgid = __pid_tgid >> 32; // upper 32 bits + u32 pid = bpf_get_current_pid_tgid(); PID_FILTER COLLECT return 0; @@ -58,17 +56,19 @@ def _generate_entry(self): text = text.replace("PROBENAME", self.entry_probe_func) text = text.replace("SIGNATURE", "" if len(self.signature) == 0 else ", " + self.signature) - text = text.replace("PID_FILTER", self._generate_pid_filter()) + pid_filter = "" if self.is_user or self.pid is None \ + else "if (pid != %d) { return 0; }" % self.pid + text = text.replace("PID_FILTER", pid_filter) collect = "" for pname in self.args_to_probe: param_hash = self.hashname_prefix + pname if pname == "__latency": collect += """ u64 __time = bpf_ktime_get_ns(); -%s.update(&__pid, &__time); +%s.update(&pid, &__time); """ % param_hash else: - collect += "%s.update(&__pid, &%s);\n" % \ + collect += "%s.update(&pid, &%s);\n" % \ (param_hash, pname) text = text.replace("COLLECT", collect) return text @@ -108,7 +108,7 @@ def _generate_retprobe_prefix(self): # argument we needed to probe using $entry(name), and they all # have values (which isn't necessarily the case if we missed # the method entry probe). - text = "" + text = "u32 __pid = bpf_get_current_pid_tgid();\n" self.param_val_names = {} for pname in self.args_to_probe: val_name = "__%s_val" % pname @@ -345,7 +345,8 @@ def _generate_pid_filter(self): # Kernel probes need to explicitly filter pid, because the # attach interface doesn't support pid filtering if self.pid is not None and not self.is_user: - return "if (__tgid != %d) { return 0; }" % self.pid + return "u32 pid = bpf_get_current_pid_tgid();\n" + \ + "if (pid != %d) { return 0; }" % self.pid else: return "" @@ -359,9 +360,6 @@ def generate_text(self): if self.probe_type == "t" else "int PROBENAME(struct pt_regs *ctx SIGNATURE)") + """ { - u64 __pid_tgid = bpf_get_current_pid_tgid(); - u32 __pid = __pid_tgid; // lower 32 bits - u32 __tgid = __pid_tgid >> 32; // upper 32 bits PID_FILTER PREFIX if (!(FILTER)) return 0; diff --git a/tools/cpudist.py b/tools/cpudist.py index 47658c06fa74..152596f78b71 100755 --- a/tools/cpudist.py +++ b/tools/cpudist.py @@ -12,7 +12,7 @@ # Licensed under the Apache License, Version 2.0 (the "License") from __future__ import print_function -from bcc import BPF +from bcc import BPF, Tracepoint from time import sleep, strftime import argparse