void RecordData::WriteData(int, siginfo_t*, void*) { // Dump from here, the function must not allocate so this is safe.
record_obj_->WriteEntries();
}
void RecordData::WriteEntriesOnExit() { if (record_obj_ == nullptr) return;
// Append the current pid to the file name to avoid multiple processes // writing to the same file.
std::string file(record_obj_->file());
file += "." + std::to_string(getpid());
record_obj_->WriteEntries(file);
}
void RecordData::WriteEntries(const std::string& file) {
std::lock_guard<std::mutex> entries_lock(entries_lock_); if (cur_index_ == 0) {
info_log("No alloc entries to write."); return;
}
int dump_fd = open(file.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NOFOLLOW, 0755); if (dump_fd == -1) {
error_log("Cannot create record alloc file %s: %m", file.c_str()); return;
}
for (size_t i = 0; i < cur_index_; i++) { if (entries_[i].type == memory_trace::UNKNOWN) { // This can happen if an entry was reserved but not filled in due to some // type of error during the operation. continue;
} if (!memory_trace::WriteEntryToFd(dump_fd, entries_[i])) {
error_log("Failed to write record alloc information: %m"); break;
}
}
close(dump_fd);
memory_trace::Entry* entry = &entries_[cur_index_];
entry->type = memory_trace::UNKNOWN; if (++cur_index_ == entries_.size()) {
info_log("Maximum number of records added, all new operations will be dropped.");
} return entry;
}
memory_trace::Entry* RecordData::ReserveEntry() { void* data = pthread_getspecific(key_); if (data == nullptr) {
ThreadData* thread_data = new ThreadData(this);
pthread_setspecific(key_, thread_data);
}
size_t page_index = 0; // Handling the first page is special, handle it separately. if (cur_addr == start_addr) { if (present[0]) {
present_bytes = page_size - (addr & page_size_mask); if (present_bytes >= alloc_size) { // The allocation fits on a single page and that page is present. return alloc_size;
}
}
page_index = 1;
}
for (; page_index < length / page_size; page_index++) { if (present[page_index]) {
present_bytes += page_size;
}
}
cur_addr += length;
if (check_last_page && present[page_index - 1]) { // The page size was already added in, so we need to subtract a bit so // we only include the total bytes on the last page.
uintptr_t leftover_bytes = (addr + alloc_size) & page_size_mask; if (leftover_bytes != 0) {
present_bytes -= page_size - leftover_bytes;
}
}
}
return present_bytes;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-28)
¤
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.