tools/perf/util/intel-pt-decoder/intel-pt-log.c
Source file repositories/reference/linux-study-clean/tools/perf/util/intel-pt-decoder/intel-pt-log.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/intel-pt-decoder/intel-pt-log.c- Extension
.c- Size
- 5220 bytes
- Lines
- 268
- 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
stdio.hstdlib.hstdint.hinttypes.hstdarg.hstdbool.hstring.hlinux/zalloc.hlinux/kernel.hintel-pt-log.hintel-pt-insn-decoder.hintel-pt-pkt-decoder.h
Detected Declarations
struct log_buffunction intel_pt_log_enablefunction intel_pt_log_disablefunction intel_pt_log_set_namefunction intel_pt_print_datafunction intel_pt_print_no_datafunction log_buf__writefunction log_buf__closefunction remove_first_linefunction write_linesfunction log_buf__dumpfunction intel_pt_log_dump_buffunction intel_pt_log_openfunction __intel_pt_log_packetfunction __intel_pt_log_insnfunction __intel_pt_log_insn_no_datafunction __intel_pt_log
Annotated Snippet
struct log_buf {
char *buf;
size_t buf_sz;
size_t head;
bool wrapped;
FILE *backend;
};
static FILE *f;
static char log_name[MAX_LOG_NAME];
bool intel_pt_enable_logging;
static bool intel_pt_dump_log_on_error;
static unsigned int intel_pt_log_on_error_size;
static struct log_buf log_buf;
void *intel_pt_log_fp(void)
{
return f;
}
void intel_pt_log_enable(bool dump_log_on_error, unsigned int log_on_error_size)
{
intel_pt_enable_logging = true;
intel_pt_dump_log_on_error = dump_log_on_error;
intel_pt_log_on_error_size = log_on_error_size;
}
void intel_pt_log_disable(void)
{
if (f)
fflush(f);
intel_pt_enable_logging = false;
}
void intel_pt_log_set_name(const char *name)
{
strncpy(log_name, name, MAX_LOG_NAME - 5);
strcat(log_name, ".log");
}
static void intel_pt_print_data(const unsigned char *buf, int len, uint64_t pos,
int indent)
{
int i;
for (i = 0; i < indent; i++)
fprintf(f, " ");
fprintf(f, " %08" PRIx64 ": ", pos);
for (i = 0; i < len; i++)
fprintf(f, " %02x", buf[i]);
for (; i < 16; i++)
fprintf(f, " ");
fprintf(f, " ");
}
static void intel_pt_print_no_data(uint64_t pos, int indent)
{
int i;
for (i = 0; i < indent; i++)
fprintf(f, " ");
fprintf(f, " %08" PRIx64 ": ", pos);
for (i = 0; i < 16; i++)
fprintf(f, " ");
fprintf(f, " ");
}
static ssize_t log_buf__write(void *cookie, const char *buf, size_t size)
{
struct log_buf *b = cookie;
size_t sz = size;
if (!b->buf)
return size;
while (sz) {
size_t space = b->buf_sz - b->head;
size_t n = min(space, sz);
memcpy(b->buf + b->head, buf, n);
sz -= n;
buf += n;
b->head += n;
if (sz && b->head >= b->buf_sz) {
b->head = 0;
b->wrapped = true;
}
}
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdint.h`, `inttypes.h`, `stdarg.h`, `stdbool.h`, `string.h`, `linux/zalloc.h`.
- Detected declarations: `struct log_buf`, `function intel_pt_log_enable`, `function intel_pt_log_disable`, `function intel_pt_log_set_name`, `function intel_pt_print_data`, `function intel_pt_print_no_data`, `function log_buf__write`, `function log_buf__close`, `function remove_first_line`, `function write_lines`.
- 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.