tools/perf/util/time-utils.c
Source file repositories/reference/linux-study-clean/tools/perf/util/time-utils.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/time-utils.c- Extension
.c- Size
- 11158 bytes
- Lines
- 560
- 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
stdlib.hstring.hlinux/string.hsys/time.hlinux/time64.htime.herrno.hinttypes.hmath.hlinux/ctype.hdebug.htime-utils.hsession.hevlist.h
Detected Declarations
function parse_nsec_timefunction parse_timestr_sec_nsecfunction split_start_endfunction perf_time__parse_strfunction perf_time__parse_strsfunction parse_percentfunction set_percent_timefunction percent_slash_splitfunction percent_dash_splitfunction percent_comma_splitfunction one_percent_convertfunction perf_time__percent_parse_strfunction perf_time__skip_samplefunction perf_time__ranges_skip_samplefunction perf_time__parse_for_ranges_reltimefunction perf_time__parse_for_rangesfunction timestamp__scnprintf_usecfunction timestamp__scnprintf_nsecfunction fetch_current_timestamp
Annotated Snippet
while (*p && !isspace(*p)) {
if (*p++ == ',') {
rc = -EINVAL;
goto out;
}
}
/* Split and parse */
if (*p)
*p++ = 0;
rc = perf_time__parse_str(ptime + i, arg);
if (rc < 0)
goto out;
}
/* Parse the last piece */
rc = perf_time__parse_str(ptime + i, p);
if (rc < 0)
goto out;
/* Check there is no overlap */
for (i = 0; i < num - 1; i++) {
if (ptime[i].end >= ptime[i + 1].start) {
rc = -EINVAL;
goto out;
}
}
rc = num;
out:
free(str);
return rc;
}
static int parse_percent(double *pcnt, char *str)
{
char *c, *endptr;
double d;
c = strchr(str, '%');
if (c)
*c = '\0';
else
return -1;
d = strtod(str, &endptr);
if (endptr != str + strlen(str))
return -1;
*pcnt = d / 100.0;
return 0;
}
static int set_percent_time(struct perf_time_interval *ptime, double start_pcnt,
double end_pcnt, u64 start, u64 end)
{
u64 total = end - start;
if (start_pcnt < 0.0 || start_pcnt > 1.0 ||
end_pcnt < 0.0 || end_pcnt > 1.0) {
return -1;
}
ptime->start = start + round(start_pcnt * total);
ptime->end = start + round(end_pcnt * total);
if (ptime->end > ptime->start && ptime->end != end)
ptime->end -= 1;
return 0;
}
static int percent_slash_split(char *str, struct perf_time_interval *ptime,
u64 start, u64 end)
{
char *p, *end_str;
double pcnt, start_pcnt, end_pcnt;
int i;
/*
* Example:
* 10%/2: select the second 10% slice and the third 10% slice
*/
/* We can modify this string since the original one is copied */
p = strchr(str, '/');
if (!p)
return -1;
*p = '\0';
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `linux/string.h`, `sys/time.h`, `linux/time64.h`, `time.h`, `errno.h`, `inttypes.h`.
- Detected declarations: `function parse_nsec_time`, `function parse_timestr_sec_nsec`, `function split_start_end`, `function perf_time__parse_str`, `function perf_time__parse_strs`, `function parse_percent`, `function set_percent_time`, `function percent_slash_split`, `function percent_dash_split`, `function percent_comma_split`.
- 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.