// File format of jit-PID.jump: // // +--------------------------------+ // | PerfJitHeader | // +--------------------------------+ // | PerfJitCodeLoad { | . // | struct PerfJitBase; | . // | uint32_t process_id_; | . // | uint32_t thread_id_; | . // | uint64_t vma_; | . // | uint64_t code_address_; | . // | uint64_t code_size_; | . // | uint64_t code_id_; | . // | } | . // +- -+ . // | method_name'\0' | +--> one jitted method // +- -+ . // | jitted code binary | . // | ... | . // +--------------------------------+ . // | PerfJitCodeDebugInfo { | . // | struct PerfJitBase; | . // | uint64_t address_; | . // | uint64_t entry_count_; | . // | struct PerfJitDebugEntry; | . // | } | . // +--------------------------------+ // | PerfJitCodeLoad | // ... // struct PerfJitHeader {
uint32_t magic_; // Characters "JiTD"
uint32_t version_; // Header version
uint32_t size_; // Total size of header
uint32_t elf_mach_target_; // Elf mach target
uint32_t reserved_; // Reserved, currently not used
uint32_t process_id_; // Process ID of the JIT compiler
uint64_t time_stamp_; // Timestamp when the header is generated
uint64_t flags_; // Currently the flags are only used for choosing clock for timestamp, // we set it to 0 to tell perf that we use CLOCK_MONOTONIC clock. staticconst uint32_t kMagic = 0x4A695444; // "JiTD" staticconst uint32_t kVersion = 1;
};
// Each record starts with such basic information: event type, total size, and timestamp. struct PerfJitBase { enum PerfJitEvent { // A jitted code load event. // In ART JIT, it is used to log a new method is jit compiled and committed to jit-code-cache. // Note that such kLoad event supports code cache GC in ART JIT. // For every kLoad event recorded in jit-PID.dump and every perf sample recorded in perf.data, // each event/sample has time stamp. In case code cache GC happens in ART JIT, and a new // jitted method is committed to the same address of a previously deleted method, // the time stamp information can help profiler to tell whether this sample belongs to the // era of the first jitted method, or does it belong to the period of the second jitted method. // JitCodeCache doesn't have to record any event on 'code delete'.
kLoad = 0,
// A jitted code move event, i,e. a jitted code moved from one address to another address. // It helps profiler to map samples to the right symbol even when the code is moved. // In ART JIT, this event can help log such behavior: // A jitted method is recorded in previous kLoad event, but due to some reason, // it is moved to another address in jit-code-cache.
kMove = 1,
// Logs JIT VM end of life event.
kClose = 3
};
uint32_t event_; // Must be one of the events defined in PerfJitEvent.
uint32_t size_; // Total size of this event record. // For example, for kLoad event, size of the event record is: // sizeof(PerfJitCodeLoad) + method_name.size() + compiled code size.
uint64_t time_stamp_; // Timestamp for the event.
};
// Logs a jitted code load event (kLoad). // In ART JIT, it is used to log a new method is jit compiled and commited to jit-code-cache. struct PerfJitCodeLoad : PerfJitBase {
uint32_t process_id_; // Process ID who performs the jit code load. // In ART JIT, it is the pid of the JIT compiler.
uint32_t thread_id_; // Thread ID who performs the jit code load. // In ART JIT, it is the tid of the JIT compiler.
uint64_t vma_; // Address of the code section. In ART JIT, because code_address_ // uses absolute address, this field is 0.
uint64_t code_address_; // Address where is jitted code is loaded.
uint64_t code_size_; // Size of the jitted code.
uint64_t code_id_; // Unique ID for each jitted code.
};
// This structure is for source line/column mapping. // Currently this feature is not implemented in ART JIT yet. struct PerfJitDebugEntry {
uint64_t address_; // Code address which maps to the line/column in source.
uint32_t line_number_; // Source line number starting at 1.
uint32_t column_; // Column discriminator, default 0. constchar name_[0]; // Followed by null-terminated name or \0xff\0 if same as previous.
};
// Logs debug line information (kDebugInfo). // This structure is for source line/column mapping. // Currently this feature is not implemented in ART JIT yet. struct PerfJitCodeDebugInfo : PerfJitBase {
uint64_t address_; // Starting code address which the debug info describes.
uint64_t entry_count_; // How many instances of PerfJitDebugEntry.
PerfJitDebugEntry entries_[0]; // Followed by entry_count_ instances of PerfJitDebugEntry.
};
void JitLogger::OpenMarkerFile() { int fd = jit_dump_file_->Fd(); // The 'perf inject' tool requires that the jit-PID.dump file // must have a mmap(PROT_READ|PROT_EXEC) record in perf.data.
marker_address_ = mmap(nullptr, MemMap::GetPageSize(), PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0); if (marker_address_ == MAP_FAILED) {
LOG(WARNING) << "Failed to create record in perf.data. JITed code profiling will not work."; return;
}
}
bool res = jit_dump_file_->WriteFully(reinterpret_cast<constchar*>(&header), sizeof(header)); if (!res) {
LOG(WARNING) << "Failed to write profiling log. The 'perf inject' tool will not work.";
}
}
jit_dump_file_.reset(OS::CreateEmptyFile(jitdump_filename.c_str())); if (jit_dump_file_ == nullptr) {
LOG(ERROR) << "Could not create jit dump file at " << jitdump_filename << " Are you on a user build? Perf only works on userdebug/eng builds"; return;
}
OpenMarkerFile();
// Continue to write jit-PID.dump file even above OpenMarkerFile() fails. // Even if that means 'perf inject' tool cannot work, developers can still use other tools // to map the samples in perf.data to the information (symbol,address,code) recorded // in the jit-PID.dump file, and still proceed the jitted code analysis.
WriteJitDumpHeader();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.