simpleperf: change interface of read_apk.h.
1. Remove GetBuildIdFromApkFile and ParseSymbolsFromApkFile, because
their function can be supported using ApkInspector::FindElfInApkByName
and read_elf.h.
2. Remove ApkInspector::FindOffsetInApkByName, instead the caller can
use ApkInspector::FindElfInApkByName directly.
3. In ApkInspector::embedded_elf_cache_, add map for entry_name. So
the EmbeddedElfs added by cmd_record.cpp can be used by OfflineUnwinder.
Also support reading min executable virtual address from embedded elfs
in ElfDso.
Also avoid segfault reading build id of elf files with broken section
table, and add test.
Bug: none.
Test: run simpleperf_unit_test.
Change-Id: I2e4f51a5e348138cbf7445ec6dd42dbd6ae1b03d
diff --git a/simpleperf/read_apk.h b/simpleperf/read_apk.h
index 26c266c..484bafe 100644
--- a/simpleperf/read_apk.h
+++ b/simpleperf/read_apk.h
@@ -19,10 +19,10 @@
#include <stdint.h>
-#include <map>
#include <memory>
#include <string>
#include <tuple>
+#include <unordered_map>
#include "read_elf.h"
@@ -68,38 +68,27 @@
// APK inspector helper class
class ApkInspector {
public:
- // Given an APK/ZIP/JAR file and an offset into that file, if the
- // corresponding region of the APK corresponds to an uncompressed
- // ELF file, then return pertinent info on the ELF.
- static bool FindOffsetInApkByName(const std::string& apk_path,
- const std::string& elf_filename,
- uint64_t* offset, uint32_t* uncompressed_length);
static EmbeddedElf* FindElfInApkByOffset(const std::string& apk_path, uint64_t file_offset);
- static std::unique_ptr<EmbeddedElf> FindElfInApkByName(const std::string& apk_path,
- const std::string& elf_filename);
+ static EmbeddedElf* FindElfInApkByName(const std::string& apk_path,
+ const std::string& entry_name);
private:
static std::unique_ptr<EmbeddedElf> FindElfInApkByOffsetWithoutCache(const std::string& apk_path,
uint64_t file_offset);
+ static std::unique_ptr<EmbeddedElf> FindElfInApkByNameWithoutCache(
+ const std::string& apk_path, const std::string& entry_name);
- // First component of pair is APK file path, second is offset into APK.
- typedef std::pair<std::string, uint64_t> ApkOffset;
-
- static std::map<ApkOffset, std::unique_ptr<EmbeddedElf>> embedded_elf_cache_;
+ struct ApkNode {
+ // Map from entry_offset to EmbeddedElf.
+ std::unordered_map<uint64_t, std::unique_ptr<EmbeddedElf>> offset_map;
+ // Map from entry_name to EmbeddedElf.
+ std::unordered_map<std::string, EmbeddedElf*> name_map;
+ };
+ static std::unordered_map<std::string, ApkNode> embedded_elf_cache_;
};
-// Export for test only.
bool IsValidApkPath(const std::string& apk_path);
-
std::string GetUrlInApk(const std::string& apk_path, const std::string& elf_filename);
std::tuple<bool, std::string, std::string> SplitUrlInApk(const std::string& path);
-ElfStatus GetBuildIdFromApkFile(const std::string& apk_path, const std::string& elf_filename,
- BuildId* build_id);
-
-ElfStatus ParseSymbolsFromApkFile(const std::string& apk_path, const std::string& elf_filename,
- const BuildId& expected_build_id,
- const std::function<void(const ElfFileSymbol&)>& callback);
-
-
#endif // SIMPLE_PERF_READ_APK_H_