tools/perf/util/expr.c
Source file repositories/reference/linux-study-clean/tools/perf/util/expr.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/expr.c- Extension
.c- Size
- 9876 bytes
- Lines
- 472
- 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
stdbool.hassert.herrno.hstdlib.hstring.hmetricgroup.hdebug.hevlist.hexpr.hsmt.htool_pmu.hutil/expr-bison.hutil/expr-flex.hutil/hashmap.hutil/header.hutil/pmu.hperf/cpumap.hlinux/err.hlinux/kernel.hlinux/zalloc.hctype.hmath.h
Detected Declarations
struct expr_id_datafunction key_hashfunction key_equalfunction ids__freefunction hashmap__for_each_entryfunction ids__insertfunction expr__add_idfunction expr__add_id_valfunction expr__add_id_val_source_countfunction expr__add_reffunction expr__get_idfunction expr__subset_of_idsfunction hashmap__for_each_entryfunction expr__resolve_idfunction expr__del_idfunction expr__ctx_clearfunction hashmap__for_each_entryfunction expr__ctx_freefunction __expr__parsefunction expr__parsefunction expr__find_idsfunction expr_id_data__valuefunction expr_id_data__source_countfunction expr__get_literalfunction expr__has_eventfunction expr__strcmp_cpuid_str
Annotated Snippet
struct expr_id_data {
union {
struct {
double val;
int source_count;
} val;
struct {
double val;
const char *metric_name;
const char *metric_expr;
} ref;
};
enum {
/* Holding a double value. */
EXPR_ID_DATA__VALUE,
/* Reference to another metric. */
EXPR_ID_DATA__REF,
/* A reference but the value has been computed. */
EXPR_ID_DATA__REF_VALUE,
} kind;
};
static size_t key_hash(long key, void *ctx __maybe_unused)
{
const char *str = (const char *)key;
size_t hash = 0;
while (*str != '\0') {
hash *= 31;
hash += *str;
str++;
}
return hash;
}
static bool key_equal(long key1, long key2, void *ctx __maybe_unused)
{
return !strcmp((const char *)key1, (const char *)key2);
}
struct hashmap *ids__new(void)
{
struct hashmap *hash;
hash = hashmap__new(key_hash, key_equal, NULL);
if (IS_ERR(hash))
return NULL;
return hash;
}
void ids__free(struct hashmap *ids)
{
struct hashmap_entry *cur;
size_t bkt;
if (ids == NULL)
return;
hashmap__for_each_entry(ids, cur, bkt) {
zfree(&cur->pkey);
zfree(&cur->pvalue);
}
hashmap__free(ids);
}
int ids__insert(struct hashmap *ids, const char *id)
{
struct expr_id_data *data_ptr = NULL, *old_data = NULL;
char *old_key = NULL;
int ret;
ret = hashmap__set(ids, id, data_ptr, &old_key, &old_data);
if (ret)
free(data_ptr);
free(old_key);
free(old_data);
return ret;
}
struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2)
{
size_t bkt;
struct hashmap_entry *cur;
int ret;
struct expr_id_data *old_data = NULL;
char *old_key = NULL;
if (!ids1)
Annotation
- Immediate include surface: `stdbool.h`, `assert.h`, `errno.h`, `stdlib.h`, `string.h`, `metricgroup.h`, `debug.h`, `evlist.h`.
- Detected declarations: `struct expr_id_data`, `function key_hash`, `function key_equal`, `function ids__free`, `function hashmap__for_each_entry`, `function ids__insert`, `function expr__add_id`, `function expr__add_id_val`, `function expr__add_id_val_source_count`, `function expr__add_ref`.
- 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.