tools/tracing/rtla/src/utils.c

Source file repositories/reference/linux-study-clean/tools/tracing/rtla/src/utils.c

File Facts

System
Linux kernel
Corpus path
tools/tracing/rtla/src/utils.c
Extension
.c
Size
22513 bytes
Lines
1070
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 (*p == '-') {
			p++;
			end_cpu = atoi(p);
			if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
				goto err;
			while (isdigit(*p))
				p++;
		} else
			end_cpu = cpu;

		if (cpu == end_cpu) {
			debug_msg("cpu_set: adding cpu %d\n", cpu);
			CPU_SET(cpu, set);
		} else {
			for (i = cpu; i <= end_cpu; i++) {
				debug_msg("cpu_set: adding cpu %d\n", i);
				CPU_SET(i, set);
			}
		}

		if (*p == ',')
			p++;
	}

	return 0;
err:
	debug_msg("Error parsing the cpu set %s\n", cpu_list);
	return 1;
}

/*
 * parse_stack_format - parse the stack format
 *
 * Return: the stack format on success, -1 otherwise.
 */
int parse_stack_format(char *arg)
{
	if (!strcmp(arg, "truncate"))
		return STACK_FORMAT_TRUNCATE;
	if (!strcmp(arg, "skip"))
		return STACK_FORMAT_SKIP;
	if (!strcmp(arg, "full"))
		return STACK_FORMAT_FULL;

	debug_msg("Error parsing the stack format %s\n", arg);
	return -1;
}

/*
 * parse_duration - parse duration with s/m/h/d suffix converting it to seconds
 */
long parse_seconds_duration(char *val)
{
	char *end;
	long t;

	t = strtol(val, &end, 10);

	if (end) {
		switch (*end) {
		case 's':
		case 'S':
			break;
		case 'm':
		case 'M':
			t *= 60;
			break;
		case 'h':
		case 'H':
			t *= 60 * 60;
			break;

		case 'd':
		case 'D':
			t *= 24 * 60 * 60;
			break;
		}
	}

	return t;
}

/*
 * match_time_unit - check if str starts with unit followed by end-of-string or ':'
 *
 * This allows the time unit parser to work both in standalone duration strings
 * like "100ms" and in colon-delimited SCHED_DEADLINE specifications like
 * "d:10ms:100ms", while still rejecting malformed input like "100msx".
 */
static bool match_time_unit(const char *str, const char *unit)

Annotation

Implementation Notes