tools/tracing/latency/latency-collector.c
Source file repositories/reference/linux-study-clean/tools/tracing/latency/latency-collector.c
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/latency/latency-collector.c- Extension
.c- Size
- 50718 bytes
- Lines
- 2109
- 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
ctype.hstdbool.hstdio.hstdlib.hstring.herr.herrno.hfcntl.hgetopt.hsched.hlinux/unistd.hsignal.hsys/inotify.hunistd.hpthread.htracefs.h
Detected Declarations
struct policystruct ftrace_statestruct entrystruct print_statestruct short_msgstruct sleep_tablestruct queueenum traceoptenum errhandlingfunction write_or_diefunction clock_gettime_or_diefunction sigemptyset_or_diefunction sigaddset_or_diefunction sigaction_or_diefunction open_stdoutfunction cleanup_exitfunction mutex_unlockfunction cond_signalfunction cond_waitfunction cond_broadcastfunction mutex_initfunction mutexattr_initfunction mutexattr_destroyfunction mutexattr_settypefunction condattr_initfunction condattr_destroyfunction condattr_setclockfunction cond_initfunction cond_timedwaitfunction init_printstatefunction init_print_mtxfunction signal_blockingfunction signal_handlerfunction setup_sig_handlerfunction process_signalfunction check_signalsfunction get_time_in_futurefunction time_has_passedfunction mutex_trylock_limitfunction restore_trace_optsfunction restore_filefunction restore_ftracefunction cleanup_exitfunction init_save_statefunction printstate_next_ticketfunction printstate_mark_req_completedfunction printstate_has_new_req_arrivedfunction printstate_cnt_inc
Annotated Snippet
struct policy {
const char *name;
int policy;
int default_pri;
};
static const struct policy policies[] = {
{ "other", SCHED_OTHER, DEFAULT_PRI },
{ "batch", SCHED_BATCH, DEFAULT_PRI },
{ "idle", SCHED_IDLE, DEFAULT_PRI },
{ "rr", SCHED_RR, RT_DEFAULT_PRI },
{ "fifo", SCHED_FIFO, RT_DEFAULT_PRI },
{ NULL, 0, DEFAULT_PRI }
};
/*
* The default tracer will be the first on this list that is supported by the
* currently running Linux kernel.
*/
static const char * const relevant_tracers[] = {
"preemptirqsoff",
"preemptoff",
"irqsoff",
"wakeup",
"wakeup_rt",
"wakeup_dl",
NULL
};
/* This is the list of tracers for which random sleep makes sense */
static const char * const random_tracers[] = {
"preemptirqsoff",
"preemptoff",
"irqsoff",
NULL
};
static const char *current_tracer;
static bool force_tracer;
struct ftrace_state {
char *tracer;
char *thresh;
bool opt[OPTIDX_NR];
bool opt_valid[OPTIDX_NR];
pthread_mutex_t mutex;
};
struct entry {
int ticket;
int ticket_completed_ref;
};
struct print_state {
int ticket_counter;
int ticket_completed;
pthread_mutex_t mutex;
pthread_cond_t cond;
int cnt;
pthread_mutex_t cnt_mutex;
};
struct short_msg {
char buf[160];
int len;
};
static struct print_state printstate;
static struct ftrace_state save_state;
volatile sig_atomic_t signal_flag;
#define PROB_TABLE_MAX_SIZE (1000)
int probabilities[PROB_TABLE_MAX_SIZE];
struct sleep_table {
int *table;
int size;
pthread_mutex_t mutex;
};
static struct sleep_table sleeptable;
#define QUEUE_SIZE (10)
struct queue {
struct entry entries[QUEUE_SIZE];
int next_prod_idx;
int next_cons_idx;
pthread_mutex_t mutex;
Annotation
- Immediate include surface: `ctype.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `err.h`, `errno.h`, `fcntl.h`.
- Detected declarations: `struct policy`, `struct ftrace_state`, `struct entry`, `struct print_state`, `struct short_msg`, `struct sleep_table`, `struct queue`, `enum traceopt`, `enum errhandling`, `function write_or_die`.
- 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.