Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyuezhou authored and yonghong-song committed Apr 16, 2021
1 parent c76cd92 commit 0cf8166
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions man/man8/funclatency.8
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Print output every interval seconds.
\-d DURATION
Total duration of trace, in seconds.
.TP
\-l LEVEL
Set the level of nested or recursive functions.
.TP
\-T
Include timestamps on output.
.TP
Expand Down
13 changes: 6 additions & 7 deletions tools/funclatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
# The pattern is a string with optional '*' wildcards, similar to file
# globbing. If you'd prefer to use regular expressions, use the -r option.
#
# Without the '-l' option, only the innermost calls will be recorded.
# Use '-l LEVEL' to record the outermost n levels of nested/recursive functions.
#
# Copyright (c) 2015 Brendan Gregg.
# Copyright (c) 2021 Chenyue Zhou.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 20-Sep-2015 Brendan Gregg Created this.
# 06-Oct-2016 Sasha Goldshtein Added user function support.
# 14-Apr-2021 Chenyue Zhou Added nested or recursive function support.

from __future__ import print_function
from bcc import BPF
Expand Down Expand Up @@ -173,7 +178,7 @@ def bail(error):
if need_key:
pid = '-1' if not library else 'tgid'

if args.level > 1:
if args.level and args.level > 1:
bpf_text = bpf_text.replace('TYPEDEF',
"""
#define STACK_DEPTH %s
Expand Down Expand Up @@ -204,7 +209,6 @@ def bail(error):
}
u32 index = --stack->head;
if (index < STACK_DEPTH) {
/* bound check */
cache->ip = stack->cache[index].ip;
Expand All @@ -219,12 +223,10 @@ def bail(error):
if (index > STACK_DEPTH - 1) {
/* bound check */
return -1;
}
stack->head++;
stack->cache[index].ip = cache->ip;
stack->cache[index].start_ts = cache->start_ts;
Expand Down Expand Up @@ -264,7 +266,6 @@ def bail(error):
func_stack_t *stack = func_stack.lookup(&pid);
if (!stack) {
/* miss start */
return 0;
}
Expand All @@ -274,7 +275,6 @@ def bail(error):
return 0;
}
ip = cache.ip;
start_ts = cache.start_ts;
delta = bpf_ktime_get_ns() - start_ts;
Expand All @@ -290,7 +290,6 @@ def bail(error):
if (stack->head == 0) {
/* empty */
func_stack.delete(&pid);
}
""" % pid)
Expand Down
4 changes: 3 additions & 1 deletion tools/funclatency_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Tracing do_sys_open... Hit Ctrl-C to end.
524288 -> 1048575 : 0 | |
1048576 -> 2097151 : 0 | |
2097152 -> 4194303 : 1 | |

avg = 13746 nsecs, total: 6543360 nsecs, count: 476

Detaching...
Expand Down Expand Up @@ -383,6 +383,8 @@ optional arguments:
-F, --function show a separate histogram per function
-r, --regexp use regular expressions. Default is "*" wildcards
only.
-l LEVEL, --level LEVEL
set the level of nested or recursive functions
-v, --verbose print the BPF program (for debugging purposes)

examples:
Expand Down

0 comments on commit 0cf8166

Please sign in to comment.