tools/perf/util/values.c
Source file repositories/reference/linux-study-clean/tools/perf/util/values.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/values.c- Extension
.c- Size
- 7407 bytes
- Lines
- 290
- 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
inttypes.hstdio.hstdlib.hstring.herrno.hlinux/zalloc.hvalues.hdebug.hevsel.h
Detected Declarations
function perf_read_values_initfunction perf_read_values_destroyfunction perf_read_values__enlarge_threadsfunction perf_read_values__findnew_threadfunction perf_read_values__enlarge_countersfunction perf_read_values__findnew_counterfunction perf_read_values_add_valuefunction perf_read_values__display_prettyfunction perf_read_values__display_rawfunction perf_read_values_display
Annotated Snippet
if (!value) {
pr_debug("failed to enlarge read_values ->values array");
goto out_free_counters;
}
for (int j = values->counters_max; j < counters_max; j++)
value[j] = 0;
values->value[i] = value;
}
values->counters_max = counters_max;
values->counters = new_counters;
return 0;
out_free_counters:
free(new_counters);
out_enomem:
return -ENOMEM;
}
static int perf_read_values__findnew_counter(struct perf_read_values *values,
struct evsel *evsel)
{
int i;
for (i = 0; i < values->num_counters; i++)
if (values->counters[i] == evsel)
return i;
if (values->num_counters == values->counters_max) {
int err = perf_read_values__enlarge_counters(values);
if (err)
return err;
}
i = values->num_counters++;
values->counters[i] = evsel;
return i;
}
int perf_read_values_add_value(struct perf_read_values *values,
u32 pid, u32 tid,
struct evsel *evsel, u64 value)
{
int tindex, cindex;
tindex = perf_read_values__findnew_thread(values, pid, tid);
if (tindex < 0)
return tindex;
cindex = perf_read_values__findnew_counter(values, evsel);
if (cindex < 0)
return cindex;
values->value[tindex][cindex] += value;
return 0;
}
static void perf_read_values__display_pretty(FILE *fp,
struct perf_read_values *values)
{
int i, j;
int pidwidth, tidwidth;
int *counterwidth;
counterwidth = malloc(values->num_counters * sizeof(*counterwidth));
if (!counterwidth) {
fprintf(fp, "INTERNAL ERROR: Failed to allocate counterwidth array\n");
return;
}
tidwidth = 3;
pidwidth = 3;
for (j = 0; j < values->num_counters; j++)
counterwidth[j] = strlen(evsel__name(values->counters[j]));
for (i = 0; i < values->threads; i++) {
int width;
width = snprintf(NULL, 0, "%d", values->pid[i]);
if (width > pidwidth)
pidwidth = width;
width = snprintf(NULL, 0, "%d", values->tid[i]);
if (width > tidwidth)
tidwidth = width;
for (j = 0; j < values->num_counters; j++) {
width = snprintf(NULL, 0, "%" PRIu64, values->value[i][j]);
if (width > counterwidth[j])
counterwidth[j] = width;
}
Annotation
- Immediate include surface: `inttypes.h`, `stdio.h`, `stdlib.h`, `string.h`, `errno.h`, `linux/zalloc.h`, `values.h`, `debug.h`.
- Detected declarations: `function perf_read_values_init`, `function perf_read_values_destroy`, `function perf_read_values__enlarge_threads`, `function perf_read_values__findnew_thread`, `function perf_read_values__enlarge_counters`, `function perf_read_values__findnew_counter`, `function perf_read_values_add_value`, `function perf_read_values__display_pretty`, `function perf_read_values__display_raw`, `function perf_read_values_display`.
- 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.