tools/perf/tests/dlfilter-test.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/dlfilter-test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/dlfilter-test.c- Extension
.c- Size
- 10376 bytes
- Lines
- 442
- 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
linux/compiler.hlinux/kernel.hlinux/string.hlinux/perf_event.hinternal/lib.hsubcmd/exec-cmd.hsys/types.hsys/stat.hfcntl.hstdlib.hunistd.hinttypes.hlibgen.hstring.herrno.hdebug.htool.hevent.hheader.hmachine.hdso.hmap.hsymbol.hsynthetic-events.hutil.hdlfilter.htests.hutil/sample.h
Detected Declarations
struct test_datafunction test_resultfunction processfunction __printffunction have_gccfunction write_attrfunction write_commfunction write_mmapfunction write_samplefunction close_fdfunction write_progfunction get_dlfilters_pathfunction check_filter_descfunction get_ip_addrfunction do_run_perf_scriptfunction run_perf_scriptfunction test__dlfilter_testfunction unlink_pathfunction test_data__freefunction test__dlfilter_verfunction test__dlfilter
Annotated Snippet
struct test_data {
struct perf_tool tool;
struct machine *machine;
int fd;
u64 foo;
u64 bar;
u64 ip;
u64 addr;
char name[DLFILTER_TEST_NAME_MAX];
char desc[DLFILTER_TEST_NAME_MAX];
char perf[PATH_MAX];
char perf_data_file_name[PATH_MAX];
char c_file_name[PATH_MAX];
char prog_file_name[PATH_MAX];
char dlfilters[PATH_MAX];
};
static int test_result(const char *msg, int ret)
{
pr_debug("%s\n", msg);
return ret;
}
static int process(const struct perf_tool *tool, union perf_event *event,
struct perf_sample *sample __maybe_unused,
struct machine *machine __maybe_unused)
{
struct test_data *td = container_of(tool, struct test_data, tool);
int fd = td->fd;
if (writen(fd, event, event->header.size) != event->header.size)
return -1;
return 0;
}
#define MAXCMD 4096
#define REDIRECT_TO_DEV_NULL " >/dev/null 2>&1"
static __printf(1, 2) int system_cmd(const char *fmt, ...)
{
char cmd[MAXCMD + sizeof(REDIRECT_TO_DEV_NULL)];
int ret;
va_list args;
va_start(args, fmt);
ret = vsnprintf(cmd, MAXCMD, fmt, args);
va_end(args);
if (ret <= 0 || ret >= MAXCMD)
return -1;
if (verbose <= 0)
strcat(cmd, REDIRECT_TO_DEV_NULL);
pr_debug("Command: %s\n", cmd);
ret = system(cmd);
if (ret)
pr_debug("Failed with return value %d\n", ret);
return ret;
}
static bool have_gcc(void)
{
pr_debug("Checking for gcc\n");
return !system_cmd("gcc --version");
}
static int write_attr(struct test_data *td, u64 sample_type, u64 *id)
{
struct perf_event_attr attr = {
.size = sizeof(attr),
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
.sample_type = sample_type,
.sample_period = 1,
};
return perf_event__synthesize_attr(&td->tool, &attr, 1, id, process);
}
static int write_comm(int fd, pid_t pid, pid_t tid, const char *comm_str)
{
struct perf_record_comm comm;
ssize_t sz = sizeof(comm);
comm.header.type = PERF_RECORD_COMM;
comm.header.misc = PERF_RECORD_MISC_USER;
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/kernel.h`, `linux/string.h`, `linux/perf_event.h`, `internal/lib.h`, `subcmd/exec-cmd.h`, `sys/types.h`, `sys/stat.h`.
- Detected declarations: `struct test_data`, `function test_result`, `function process`, `function __printf`, `function have_gcc`, `function write_attr`, `function write_comm`, `function write_mmap`, `function write_sample`, `function close_fd`.
- 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.