toos: argdist: support [-t TID] filter
It's helpful to measure argdist in multi-thread case, so we can
distinguish workload is balanced of not.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
diff --git a/tools/argdist.py b/tools/argdist.py
index b810126..83a66f3 100755
--- a/tools/argdist.py
+++ b/tools/argdist.py
@@ -5,6 +5,7 @@
#
# USAGE: argdist [-h] [-p PID] [-z STRING_SIZE] [-i INTERVAL] [-n COUNT] [-v]
# [-c] [-T TOP] [-C specifier] [-H specifier] [-I header]
+# [-t TID]
#
# Licensed under the Apache License, Version 2.0 (the "License")
# Copyright (C) 2016 Sasha Goldshtein.
@@ -55,6 +56,7 @@
u32 __pid = __pid_tgid; // lower 32 bits
u32 __tgid = __pid_tgid >> 32; // upper 32 bits
PID_FILTER
+ TID_FILTER
COLLECT
return 0;
}
@@ -63,6 +65,7 @@
text = text.replace("SIGNATURE",
"" if len(self.signature) == 0 else ", " + self.signature)
text = text.replace("PID_FILTER", self._generate_pid_filter())
+ text = text.replace("TID_FILTER", self._generate_tid_filter())
collect = ""
for pname in self.args_to_probe:
param_hash = self.hashname_prefix + pname
@@ -184,6 +187,7 @@
self.usdt_ctx = None
self.streq_functions = ""
self.pid = tool.args.pid
+ self.tid = tool.args.tid
self.cumulative = tool.args.cumulative or False
self.raw_spec = specifier
self.probe_user_list = set()
@@ -348,6 +352,12 @@
else:
return ""
+ def _generate_tid_filter(self):
+ if self.tid is not None and not self.is_user:
+ return "if (__pid != %d) { return 0; }" % self.tid
+ else:
+ return ""
+
def generate_text(self):
program = ""
probe_text = """
@@ -362,6 +372,7 @@
u32 __pid = __pid_tgid; // lower 32 bits
u32 __tgid = __pid_tgid >> 32; // upper 32 bits
PID_FILTER
+ TID_FILTER
PREFIX
KEY_EXPR
if (!(FILTER)) return 0;
@@ -391,6 +402,8 @@
program = program.replace("SIGNATURE", signature)
program = program.replace("PID_FILTER",
self._generate_pid_filter())
+ program = program.replace("TID_FILTER",
+ self._generate_tid_filter())
decl = self._generate_hash_decl()
key_expr = self._generate_key_assignment()
@@ -602,6 +615,8 @@
epilog=Tool.examples)
parser.add_argument("-p", "--pid", type=int,
help="id of the process to trace (optional)")
+ parser.add_argument("-t", "--tid", type=int,
+ help="id of the thread to trace (optional)")
parser.add_argument("-z", "--string-size", default=80,
type=int,
help="maximum string size to read from char* arguments")