summaryrefslogtreecommitdiff
path: root/simpleperf/record_file_reader.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2019-07-18 17:27:48 -0700
committerYabin Cui <yabinc@google.com>2019-07-18 17:27:48 -0700
commitb5df73ebe26992d6631abbea9e7b351f2687060d (patch)
tree403cd300c89aa312c3ef65fe953821f9d8bd2161 /simpleperf/record_file_reader.cpp
parent168d61edebe6221617680ec5d11c6180bb80dbc6 (diff)
downloadextras-b5df73ebe26992d6631abbea9e7b351f2687060d.tar.gz
simpleperf: set scoped arch and event types in RecordFileReader.
To record on device and report on host, simpleperf keeps arch type and event types in perf.data. Currently, RecordFileReader needs its users to read and set the arch type and event types properly. This patch changes to let RecordFileReader set arch type and event types. It avoids repeating the effort in users of RecordFileReader. Bug: none Test: run simpleperf_unit_test. Test: run simpleperf record on device, and report it on host. Change-Id: Ief637ca6e2c3acfbf74b6447ef7ff0679439ca1d
Diffstat (limited to 'simpleperf/record_file_reader.cpp')
-rw-r--r--simpleperf/record_file_reader.cpp42
1 files changed, 28 insertions, 14 deletions
diff --git a/simpleperf/record_file_reader.cpp b/simpleperf/record_file_reader.cpp
index 4e246b91..d57d3d8d 100644
--- a/simpleperf/record_file_reader.cpp
+++ b/simpleperf/record_file_reader.cpp
@@ -78,9 +78,10 @@ std::unique_ptr<RecordFileReader> RecordFileReader::CreateInstance(const std::st
}
auto reader = std::unique_ptr<RecordFileReader>(new RecordFileReader(filename, fp));
if (!reader->ReadHeader() || !reader->ReadAttrSection() ||
- !reader->ReadFeatureSectionDescriptors()) {
+ !reader->ReadFeatureSectionDescriptors() || !reader->ReadMetaInfoFeature()) {
return nullptr;
}
+ reader->UseRecordingEnvironment();
return reader;
}
@@ -205,6 +206,17 @@ bool RecordFileReader::ReadIdsForAttr(const FileAttr& attr, std::vector<uint64_t
return true;
}
+void RecordFileReader::UseRecordingEnvironment() {
+ std::string arch = ReadFeatureString(FEAT_ARCH);
+ if (!arch.empty()) {
+ scoped_arch_.reset(new ScopedCurrentArch(GetArchType(arch)));
+ }
+ auto& meta_info = GetMetaInfoFeature();
+ if (auto it = meta_info.find("event_type_info"); it != meta_info.end()) {
+ scoped_event_types_.reset(new ScopedEventTypes(it->second));
+ }
+}
+
bool RecordFileReader::ReadDataSection(
const std::function<bool(std::unique_ptr<Record>)>& callback) {
std::unique_ptr<Record> record;
@@ -471,19 +483,21 @@ bool RecordFileReader::ReadFileFeature(size_t& read_pos,
return true;
}
-bool RecordFileReader::ReadMetaInfoFeature(std::unordered_map<std::string, std::string>* info_map) {
- std::vector<char> buf;
- if (!ReadFeatureSection(FEAT_META_INFO, &buf)) {
- return false;
- }
- const char* p = buf.data();
- const char* end = buf.data() + buf.size();
- while (p < end) {
- const char* key = p;
- const char* value = key + strlen(key) + 1;
- CHECK(value < end);
- (*info_map)[p] = value;
- p = value + strlen(value) + 1;
+bool RecordFileReader::ReadMetaInfoFeature() {
+ if (feature_section_descriptors_.count(FEAT_META_INFO)) {
+ std::vector<char> buf;
+ if (!ReadFeatureSection(FEAT_META_INFO, &buf)) {
+ return false;
+ }
+ const char* p = buf.data();
+ const char* end = buf.data() + buf.size();
+ while (p < end) {
+ const char* key = p;
+ const char* value = key + strlen(key) + 1;
+ CHECK(value < end);
+ meta_info_[p] = value;
+ p = value + strlen(value) + 1;
+ }
}
return true;
}