"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge patch series "Add 'trace wipe'"

Jerome Forissier <jerome.forissier@linaro.org> says:

This short series adds the 'trace wipe' command which clears the trace
buffer, allowing to re-start a capture from scratch.

Link: https://lore.kernel.org/r/cover.1734093566.git.jerome.forissier@linaro.org

+81 -14
+5
cmd/trace.c
··· 100 100 case 's': 101 101 trace_print_stats(); 102 102 break; 103 + case 'w': 104 + if (trace_wipe()) 105 + return CMD_RET_FAILURE; 106 + break; 103 107 default: 104 108 return CMD_RET_USAGE; 105 109 } ··· 113 117 "stats - display tracing statistics\n" 114 118 "trace pause - pause tracing\n" 115 119 "trace resume - resume tracing\n" 120 + "trace wipe - wipe traces\n" 116 121 "trace funclist [<addr> <size>] - dump function list into buffer\n" 117 122 "trace calls [<addr> <size>] " 118 123 "- dump function call trace into buffer"
+11
doc/develop/trace.rst
··· 163 163 u-boot-1 [000] 3.116466: funcgraph_entry: 0.063 us | memset(); 164 164 u-boot-1 [000] 3.116539: funcgraph_exit: 0.143 us | } 165 165 166 + The `trace wipe` command may be used to clear the trace buffer. It leaves 167 + tracing in its current enable state. This command is convenient when tracing a 168 + single command, for example: 169 + 170 + .. code-block:: console 171 + 172 + => trace pause; trace wipe 173 + => trace resume; dhcp; trace pause 174 + => trace stats 175 + ... 176 + 166 177 Flame graph 167 178 ----------- 168 179
+2
include/trace.h
··· 100 100 101 101 int trace_early_init(void); 102 102 103 + int trace_wipe(void); 104 + 103 105 /** 104 106 * Init the trace system 105 107 *
+33 -14
lib/trace.c
··· 351 351 return gd->mon_len / FUNC_SITE_SIZE; 352 352 } 353 353 354 - /** 355 - * trace_init() - initialize the tracing system and enable it 356 - * 357 - * @buff: Pointer to trace buffer 358 - * @buff_size: Size of trace buffer 359 - * Return: 0 if ok 360 - */ 361 - int notrace trace_init(void *buff, size_t buff_size) 354 + static int notrace trace_init_(void *buff, size_t buff_size, bool copy_early, 355 + bool enable) 362 356 { 363 357 int func_count = get_func_count(); 364 358 size_t needed; ··· 368 362 return func_count; 369 363 trace_save_gd(); 370 364 371 - if (!was_disabled) { 365 + if (copy_early) { 372 366 #ifdef CONFIG_TRACE_EARLY 373 367 ulong used, count; 374 368 char *end; ··· 394 388 } 395 389 puts("\n"); 396 390 memcpy(buff, hdr, used); 397 - #else 398 - puts("trace: already enabled\n"); 399 - return -EALREADY; 400 391 #endif 401 392 } 402 393 hdr = (struct trace_hdr *)buff; ··· 419 410 hdr->ftrace_size = (buff_size - needed) / sizeof(*hdr->ftrace); 420 411 hdr->depth_limit = CONFIG_TRACE_CALL_DEPTH_LIMIT; 421 412 422 - puts("trace: enabled\n"); 423 - trace_enabled = 1; 413 + printf("trace: initialized, %senabled\n", enable ? "" : "not "); 414 + trace_enabled = enable; 424 415 trace_inited = 1; 425 416 426 417 return 0; 418 + } 419 + 420 + /** 421 + * trace_init() - initialize the tracing system and enable it 422 + * 423 + * @buff: Pointer to trace buffer 424 + * @buff_size: Size of trace buffer 425 + * Return: 0 if ok 426 + */ 427 + int notrace trace_init(void *buff, size_t buff_size) 428 + { 429 + /* If traces are enabled already, we may have early traces to copy */ 430 + return trace_init_(buff, buff_size, trace_enabled, true); 431 + } 432 + 433 + /** 434 + * trace_wipe() - clear accumulated traced data 435 + * 436 + * May be called with tracing enabled or disabled. 437 + */ 438 + int notrace trace_wipe(void) 439 + { 440 + bool was_enabled = trace_enabled; 441 + 442 + if (trace_enabled) 443 + trace_enabled = 0; 444 + return trace_init_(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE, 445 + false, was_enabled); 427 446 } 428 447 429 448 #ifdef CONFIG_TRACE_EARLY
+30
test/py/tests/test_trace.py
··· 70 70 return fname, int(dm_f_time[0]) 71 71 72 72 73 + def wipe_and_collect_trace(cons): 74 + """Pause and wipe traces, return the number of calls (should be zero) 75 + 76 + Args: 77 + cons (ConsoleBase): U-Boot console 78 + 79 + Returns: 80 + int: the number of traced function calls reported by 'trace stats' 81 + """ 82 + cons.run_command('trace pause') 83 + cons.run_command('trace wipe') 84 + out = cons.run_command('trace stats') 85 + 86 + # The output is something like this: 87 + # 117,221 function sites 88 + # 0 function calls 89 + # 0 untracked function calls 90 + # 0 traced function calls 91 + 92 + # Get a dict of values from the output 93 + lines = [line.split(maxsplit=1) for line in out.splitlines() if line] 94 + vals = {key: val.replace(',', '') for val, key in lines} 95 + 96 + return int(vals['traced function calls']) 97 + 98 + 73 99 def check_function(cons, fname, proftool, map_fname, trace_dat): 74 100 """Check that the 'function' output works 75 101 ··· 304 330 # This allows for CI being slow to run 305 331 diff = abs(fg_time - dm_f_time) 306 332 assert diff / dm_f_time < 0.3 333 + 334 + # Check that the trace buffer can be wiped 335 + numcalls = wipe_and_collect_trace(cons) 336 + assert numcalls == 0