tools/tracing/rtla/src/trace.c
Source file repositories/reference/linux-study-clean/tools/tracing/rtla/src/trace.c
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/rtla/src/trace.c- Extension
.c- Size
- 13475 bytes
- Lines
- 598
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/sendfile.htracefs.hstdlib.hunistd.herrno.htrace.hutils.h
Detected Declarations
function enable_tracer_by_namefunction disable_tracerfunction destroy_instancefunction save_trace_to_filefunction collect_registered_eventsfunction collect_missed_eventsfunction trace_instance_destroyfunction trace_instance_initfunction trace_instance_startfunction trace_instance_stopfunction trace_events_freefunction trace_event_add_filterfunction trace_event_add_triggerfunction trace_event_disable_filterfunction trace_event_save_histfunction trace_event_disable_triggerfunction trace_events_disablefunction trace_event_enable_filterfunction trace_event_enable_triggerfunction trace_events_enablefunction trace_events_destroyfunction trace_set_buffer_size
Annotated Snippet
if (n_read < 0) {
if (errno == EINTR)
continue;
err_msg("Error reading trace file: %s\n", strerror(errno));
goto out_close;
}
if (n_read == 0)
break;
n_written = 0;
while (n_written < n_read) {
const ssize_t w = write(out_fd, buffer + n_written, n_read - n_written);
if (w < 0) {
if (errno == EINTR)
continue;
err_msg("Error writing trace file: %s\n", strerror(errno));
goto out_close;
}
n_written += w;
}
}
retval = 0;
out_close:
close(out_fd);
out_close_in:
close(in_fd);
return retval;
}
/*
* collect_registered_events - call the existing callback function for the event
*
* If an event has a registered callback function, call it.
* Otherwise, ignore the event.
*/
int
collect_registered_events(struct tep_event *event, struct tep_record *record,
int cpu, void *context)
{
struct trace_instance *trace = context;
struct trace_seq *s = trace->seq;
trace->processed_events++;
if (!event->handler)
return 0;
event->handler(s, record, event, context);
return 0;
}
/*
* collect_missed_events - record number of missed events
*
* If rtla cannot keep up with events generated by tracer, events are going
* to fall out of the ring buffer.
* Collect how many events were missed so it can be reported to the user.
*/
static int
collect_missed_events(struct tep_event *event, struct tep_record *record,
int cpu, void *context)
{
struct trace_instance *trace = context;
if (trace->missed_events == UINT64_MAX)
return 0;
if (record->missed_events > 0)
trace->missed_events += record->missed_events;
else
/* Events missed but no data on how many */
trace->missed_events = UINT64_MAX;
return 0;
}
/*
* trace_instance_destroy - destroy and free a rtla trace instance
*/
void trace_instance_destroy(struct trace_instance *trace)
{
if (trace->inst) {
disable_tracer(trace->inst);
destroy_instance(trace->inst);
trace->inst = NULL;
}
Annotation
- Immediate include surface: `sys/sendfile.h`, `tracefs.h`, `stdlib.h`, `unistd.h`, `errno.h`, `trace.h`, `utils.h`.
- Detected declarations: `function enable_tracer_by_name`, `function disable_tracer`, `function destroy_instance`, `function save_trace_to_file`, `function collect_registered_events`, `function collect_missed_events`, `function trace_instance_destroy`, `function trace_instance_init`, `function trace_instance_start`, `function trace_instance_stop`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.