#ifndef PROFILE_H #define PROFILE_H #include "types.h" struct debug_map; /* A range word stores the absolute PC in its low 24 bits and the * instruction count minus one in its high byte. Hosted text ends below * 16 MiB. The interpreter uses an escape followed by a full PC for a * single instruction outside this range. */ #define PROFILE_PC_BITS 24 #define PROFILE_PC_MASK ((1u << PROFILE_PC_BITS) - 1) #define PROFILE_PC_ESCAPE U32_MAX /* State of one hosted execution profile. */ struct profile; /* Start an instruction profile. Write folded stacks and PC counts if prefix * is set. Write ordered PC ranges if trace is set. Report each invocation * of function if set. The image and debug map stay valid until close. */ struct profile *profile_open( const char *program, const u8 *memory, u32 base, u32 bytes, const struct debug_map *debug, const char *prefix, const char *trace, const char *function ); /* Read ranges in execution order. Keep the last range's transfer pending * until the next PC is known. */ void profile_record(struct profile *profile, const u32 *ranges, const u32 *end); /* Write reports and free the profile. If the final instruction had a known * continuation, next_pc is its target, including zero for a hosted return. */ bool profile_close(struct profile *profile, u32 next_pc, bool continued); #endif