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.

Dependency Surface

Detected Declarations

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

Implementation Notes