update
authorchenyue.zhou <chenyue.zhou@upai.com>
Wed, 14 Apr 2021 17:37:07 +0000 (13:37 -0400)
committeryonghong-song <ys114321@gmail.com>
Fri, 16 Apr 2021 19:20:42 +0000 (12:20 -0700)
man/man8/funclatency.8
tools/funclatency.py
tools/funclatency_example.txt

index b82626cf8d8d4e6503cad1dc73a736019cf2f3e9..3eef805b256b3faead52592a4e23f6a3cc2a7865 100644 (file)
@@ -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
index f9fa2906f70c609dac9d663cef37a44aee9fb3e5..823fc61956238a66aac1550020664c82f3495414 100755 (executable)
 # 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
@@ -173,7 +178,7 @@ else:
 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
@@ -204,7 +209,6 @@ static inline int stack_pop(func_stack_t *stack, func_cache_t *cache) {
     }
 
     u32 index = --stack->head;
-
     if (index < STACK_DEPTH) {
         /* bound check */
         cache->ip       = stack->cache[index].ip;
@@ -219,12 +223,10 @@ static inline int stack_push(func_stack_t *stack, func_cache_t *cache) {
 
     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;
 
@@ -264,7 +266,6 @@ static inline int stack_push(func_stack_t *stack, func_cache_t *cache) {
     func_stack_t *stack = func_stack.lookup(&pid);
     if (!stack) {
         /* miss start */
-
         return 0;
     }
 
@@ -274,7 +275,6 @@ static inline int stack_push(func_stack_t *stack, func_cache_t *cache) {
 
         return 0;
     }
-
     ip       = cache.ip;
     start_ts = cache.start_ts;
     delta    = bpf_ktime_get_ns() - start_ts;
@@ -290,7 +290,6 @@ static inline int stack_push(func_stack_t *stack, func_cache_t *cache) {
 
     if (stack->head == 0) {
         /* empty */
-
         func_stack.delete(&pid);
     }
             """ % pid)
index e2effbecbc8649da16152afc0c378e5ece2c1078..d76387c81bb96d455942f76929d09ccff029f811 100644 (file)
@@ -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...
@@ -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: