/* * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include "EventSerialNumber.h" #include #include #include #include #include #include namespace Profiler { struct MappedObject { NonnullRefPtr file; ELF::Image elf; }; extern HashMap> g_mapped_object_cache; class LibraryMetadata { public: struct Library { FlatPtr base; size_t size; String name; MappedObject* object { nullptr }; // This is loaded lazily because we only need it in disassembly view mutable OwnPtr debug_info; String symbolicate(FlatPtr, u32* offset) const; const Debug::DebugInfo& load_debug_info(FlatPtr base_address) const; }; void handle_mmap(FlatPtr base, size_t size, const String& name); const Library* library_containing(FlatPtr) const; private: mutable HashMap> m_libraries; }; struct Thread { pid_t tid; EventSerialNumber start_valid; EventSerialNumber end_valid; bool valid_at(EventSerialNumber serial) const { return serial >= start_valid && (end_valid == EventSerialNumber {} || serial <= end_valid); } }; struct Process { pid_t pid {}; String executable; String basename; HashMap> threads {}; LibraryMetadata library_metadata {}; EventSerialNumber start_valid; EventSerialNumber end_valid; Thread* find_thread(pid_t tid, EventSerialNumber serial); void handle_thread_create(pid_t tid, EventSerialNumber serial); void handle_thread_exit(pid_t tid, EventSerialNumber serial); bool valid_at(EventSerialNumber serial) const { return serial >= start_valid && (end_valid == EventSerialNumber {} || serial <= end_valid); } }; }