tools/perf/tests/mem.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/mem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/mem.c- Extension
.c- Size
- 1449 bytes
- Lines
- 64
- 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
util/map_symbol.hutil/mem-events.hutil/mem-info.hutil/symbol.hlinux/perf_event.hutil/debug.htests.hstring.h
Detected Declarations
function checkfunction test__mem
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "util/map_symbol.h"
#include "util/mem-events.h"
#include "util/mem-info.h"
#include "util/symbol.h"
#include "linux/perf_event.h"
#include "util/debug.h"
#include "tests.h"
#include <string.h>
static int check(union perf_mem_data_src data_src,
const char *string)
{
char out[100];
char failure[100];
struct mem_info *mi = mem_info__new();
int n;
TEST_ASSERT_VAL("Memory allocation failed", mi);
*mem_info__data_src(mi) = data_src;
n = perf_mem__snp_scnprintf(out, sizeof out, mi);
n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, mi);
mem_info__put(mi);
scnprintf(failure, sizeof failure, "unexpected %s", out);
TEST_ASSERT_VAL(failure, !strcmp(string, out));
return 0;
}
static int test__mem(struct test_suite *text __maybe_unused, int subtest __maybe_unused)
{
int ret = 0;
union perf_mem_data_src src;
memset(&src, 0, sizeof(src));
src.mem_lvl = PERF_MEM_LVL_HIT;
src.mem_lvl_num = 4;
ret |= check(src, "N/AL4 hit");
src.mem_remote = 1;
ret |= check(src, "N/ARemote L4 hit");
src.mem_lvl = PERF_MEM_LVL_MISS;
src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
src.mem_remote = 0;
ret |= check(src, "N/APMEM miss");
src.mem_remote = 1;
ret |= check(src, "N/ARemote PMEM miss");
src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
ret |= check(src , "FwdRemote RAM miss");
return ret;
}
DEFINE_SUITE("Test data source output", mem);
Annotation
- Immediate include surface: `util/map_symbol.h`, `util/mem-events.h`, `util/mem-info.h`, `util/symbol.h`, `linux/perf_event.h`, `util/debug.h`, `tests.h`, `string.h`.
- Detected declarations: `function check`, `function test__mem`.
- 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.