tools/perf/builtin-ftrace.c
Source file repositories/reference/linux-study-clean/tools/perf/builtin-ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/builtin-ftrace.c- Extension
.c- Size
- 48681 bytes
- Lines
- 2026
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
builtin.herrno.hunistd.hsignal.hstdlib.hfcntl.hinttypes.hmath.hpoll.hctype.hlinux/capability.hlinux/err.hlinux/string.hlinux/zalloc.hsys/stat.hdebug.hsubcmd/pager.hsubcmd/parse-options.hapi/io.hapi/fs/tracing_path.hevlist.htarget.hcpumap.hhashmap.hthread_map.hstrfilter.hutil/cap.hutil/config.hutil/ftrace.hutil/stat.hutil/units.hutil/parse-sublevel-options.h
Detected Declarations
struct ftrace_profile_dataenum perf_ftrace_profile_sort_keyenum perf_ftrace_subcommandfunction sig_handlerfunction ftrace__workload_exec_failed_signalfunction check_ftrace_capablefunction is_ftrace_supportedfunction get_tracing_filefunction __write_tracing_filefunction write_tracing_filefunction append_tracing_filefunction read_tracing_file_to_stdoutfunction read_tracing_file_by_linefunction write_tracing_file_intfunction write_tracing_option_filefunction reset_tracing_optionsfunction reset_tracing_filesfunction init_tracing_instancefunction init_tracing_instancefunction set_tracing_pidfunction set_tracing_cpumaskfunction set_tracing_cpufunction set_tracing_func_stack_tracefunction set_tracing_func_irqinfofunction reset_tracing_cpufunction __set_tracing_filterfunction list_for_each_entryfunction set_tracing_filtersfunction reset_tracing_filtersfunction set_tracing_depthfunction set_tracing_percpu_buffer_sizefunction set_tracing_trace_inheritfunction set_tracing_sleep_timefunction set_tracing_funcgraph_argsfunction set_tracing_funcgraph_retvalfunction set_tracing_funcgraph_retaddrfunction set_tracing_funcgraph_irqsfunction set_tracing_funcgraph_verbosefunction set_tracing_funcgraph_tailfunction set_tracing_threshfunction set_tracing_optionsfunction select_tracerfunction __cmd_ftracefunction make_histogramfunction display_histogramfunction prepare_func_latencyfunction start_func_latencyfunction stop_func_latency
Annotated Snippet
struct ftrace_profile_data {
struct stats st;
};
static int add_func_duration(struct perf_ftrace *ftrace, char *func, double time_ns)
{
struct ftrace_profile_data *prof = NULL;
if (!hashmap__find(ftrace->profile_hash, func, &prof)) {
char *key = strdup(func);
if (key == NULL)
return -ENOMEM;
prof = zalloc(sizeof(*prof));
if (prof == NULL) {
free(key);
return -ENOMEM;
}
init_stats(&prof->st);
hashmap__add(ftrace->profile_hash, key, prof);
}
update_stats(&prof->st, time_ns);
return 0;
}
/*
* The ftrace function_graph text output normally looks like below:
*
* CPU DURATION FUNCTION
*
* 0) | syscall_trace_enter.isra.0() {
* 0) | __audit_syscall_entry() {
* 0) | auditd_test_task() {
* 0) 0.271 us | __rcu_read_lock();
* 0) 0.275 us | __rcu_read_unlock();
* 0) 1.254 us | } /\* auditd_test_task *\/
* 0) 0.279 us | ktime_get_coarse_real_ts64();
* 0) 2.227 us | } /\* __audit_syscall_entry *\/
* 0) 2.713 us | } /\* syscall_trace_enter.isra.0 *\/
*
* Parse the line and get the duration and function name.
*/
static int parse_func_duration(struct perf_ftrace *ftrace, char *line, size_t len)
{
char *p;
char *func;
double duration;
/* skip CPU */
p = strchr(line, ')');
if (p == NULL)
return 0;
/* get duration */
p = skip_spaces(p + 1);
/* no duration? */
if (p == NULL || *p == '|')
return 0;
/* skip markers like '*' or '!' for longer than ms */
if (!isdigit(*p))
p++;
duration = strtod(p, &p);
if (strncmp(p, " us", 3)) {
pr_debug("non-usec time found.. ignoring\n");
return 0;
}
/*
* profile stat keeps the max and min values as integer,
* convert to nsec time so that we can have accurate max.
*/
duration *= 1000;
/* skip to the pipe */
while (p < line + len && *p != '|')
p++;
if (*p++ != '|')
return -EINVAL;
/* get function name */
func = skip_spaces(p);
Annotation
- Immediate include surface: `builtin.h`, `errno.h`, `unistd.h`, `signal.h`, `stdlib.h`, `fcntl.h`, `inttypes.h`, `math.h`.
- Detected declarations: `struct ftrace_profile_data`, `enum perf_ftrace_profile_sort_key`, `enum perf_ftrace_subcommand`, `function sig_handler`, `function ftrace__workload_exec_failed_signal`, `function check_ftrace_capable`, `function is_ftrace_supported`, `function get_tracing_file`, `function __write_tracing_file`, `function write_tracing_file`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.