Skip to content

Commit

Permalink
utilities: upcall_monitor: Allow filtering on result.
Browse files Browse the repository at this point in the history
This patch makes it possible to display only succeeded or errored
upcalls.

Signed-off-by: Adrian Moreno <[email protected]>
Signed-off-by: 0-day Robot <[email protected]>
  • Loading branch information
amorenoz authored and ovsrobot committed Jan 17, 2025
1 parent c8a924c commit 338840a
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions utilities/usdt-scripts/upcall_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
# Set maximum packet size to capture, default 64
# -w PCAP_FILE, --pcap PCAP_FILE
# Write upcall packets to specified pcap file.
# -r, --result {error,succeed,both}
# Display only events with the given result,
# default: both
#
# The following is an example of how to use the script on the running
# ovs-vswitchd process with a packet and flow key dump enabled:
Expand Down Expand Up @@ -157,6 +160,7 @@
__sync_fetch_and_add(value, 1);
}
#if <INSTALL_OVS_UPCALL_RECV_PROBE>
int do_trace(struct pt_regs *ctx) {
uint64_t addr;
uint64_t size;
Expand Down Expand Up @@ -198,7 +202,9 @@
events.ringbuf_submit(event, 0);
return 0;
};
#endif
#if <INSTALL_OVS_UPCALL_DROP_PROBE>
struct inflight_upcall {
u32 cpu;
u32 upcall_type;
Expand Down Expand Up @@ -267,6 +273,7 @@
events.ringbuf_submit(event, 0);
return 0;
}
#endif
"""


Expand Down Expand Up @@ -526,6 +533,10 @@ def main():
parser.add_argument("-w", "--pcap", metavar="PCAP_FILE",
help="Write upcall packets to specified pcap file.",
type=str, default=None)
parser.add_argument("-r", "--result",
help="Display only events with the given result, "
"default: both",
choices=["error", "succeed", "both"], default="both")

options = parser.parse_args()

Expand Down Expand Up @@ -560,20 +571,23 @@ def main():
#
# Attach the usdt probe
#
u = USDT(pid=int(options.pid))
try:
u.enable_probe(probe="recv_upcall", fn_name="do_trace")
except USDTException as e:
print("ERROR: {}"
"ovs-vswitchd!".format(
(re.sub('^', ' ' * 7, str(e), flags=re.MULTILINE)).strip().
replace("--with-dtrace or --enable-dtrace",
"--enable-usdt-probes")))
sys.exit(-1)
usdt = []
if options.result in ["succeed", "both"]:
u = USDT(pid=int(options.pid))
try:
u.enable_probe(probe="recv_upcall", fn_name="do_trace")
usdt.append(u)
except USDTException as e:
print("ERROR: {}"
"ovs-vswitchd!".format(
(re.sub('^', ' ' * 7, str(e), flags=re.MULTILINE)).
strip().replace("--with-dtrace or --enable-dtrace",
"--enable-usdt-probes")))
sys.exit(-1)

#
# Uncomment to see how arguments are decoded.
# print(u.get_text())
# print(u.get_text())
#

#
Expand All @@ -583,8 +597,12 @@ def main():
source = source.replace("<MAX_KEY_VAL>", str(options.flow_key_size))
source = source.replace("<BUFFER_PAGE_CNT>",
str(options.buffer_page_count))
source = source.replace("<INSTALL_OVS_UPCALL_RECV_PROBE>", "1"
if options.result in ["succeed", "both"] else "0")
source = source.replace("<INSTALL_OVS_UPCALL_DROP_PROBE>", "1"
if options.result in ["error", "both"] else "0")

b = BPF(text=source, usdt_contexts=[u], debug=options.debug)
b = BPF(text=source, usdt_contexts=usdt, debug=options.debug)

#
# Print header
Expand Down

0 comments on commit 338840a

Please sign in to comment.