Skip to content

Commit

Permalink
toos: argdist: support [-t TID] filter
Browse files Browse the repository at this point in the history
It's helpful to measure argdist in multi-thread case, so we can
distinguish workload is balanced of not.

Signed-off-by: zhenwei pi <[email protected]>
  • Loading branch information
pizhenwei authored and yonghong-song committed Sep 8, 2021
1 parent e113312 commit 6677321
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion man/man8/argdist.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SH NAME
argdist \- Trace a function and display a histogram or frequency count of its parameter values. Uses Linux eBPF/bcc.
.SH SYNOPSIS
.B argdist [-h] [-p PID] [-z STRING_SIZE] [-i INTERVAL] [-d DURATION] [-n COUNT] [-v] [-T TOP] [-H specifier] [-C specifier] [-I header]
.B argdist [-h] [-p PID] [-z STRING_SIZE] [-i INTERVAL] [-d DURATION] [-n COUNT] [-v] [-T TOP] [-H specifier] [-C specifier] [-I header] [-t TID]
.SH DESCRIPTION
argdist attaches to function entry and exit points, collects specified parameter
values, and stores them in a histogram or a frequency collection that counts
Expand All @@ -20,6 +20,9 @@ Print usage message.
\-p PID
Trace only functions in the process PID.
.TP
\-t TID
Trace only functions in the thread TID.
.TP
\-z STRING_SIZE
When collecting string arguments (of type char*), collect up to STRING_SIZE
characters. Longer strings will be truncated.
Expand Down
15 changes: 15 additions & 0 deletions tools/argdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -55,6 +56,7 @@ def _generate_entry(self):
u32 __pid = __pid_tgid; // lower 32 bits
u32 __tgid = __pid_tgid >> 32; // upper 32 bits
PID_FILTER
TID_FILTER
COLLECT
return 0;
}
Expand All @@ -63,6 +65,7 @@ def _generate_entry(self):
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
Expand Down Expand Up @@ -184,6 +187,7 @@ def __init__(self, tool, type, specifier):
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()
Expand Down Expand Up @@ -348,6 +352,12 @@ def _generate_pid_filter(self):
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 = """
Expand All @@ -362,6 +372,7 @@ def generate_text(self):
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;
Expand Down Expand Up @@ -391,6 +402,8 @@ def generate_text(self):
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()
Expand Down Expand Up @@ -602,6 +615,8 @@ def __init__(self):
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")
Expand Down
1 change: 1 addition & 0 deletions tools/argdist_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ Trace a function and display a summary of its parameter values.
optional arguments:
-h, --help show this help message and exit
-p PID, --pid PID id of the process to trace (optional)
-t TID, --tid TID id of the thread to trace (optional)
-z STRING_SIZE, --string-size STRING_SIZE
maximum string size to read from char* arguments
-i INTERVAL, --interval INTERVAL
Expand Down

0 comments on commit 6677321

Please sign in to comment.