diff options
author | Yabin Cui <yabinc@google.com> | 2017-08-11 14:52:51 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2017-08-14 11:03:53 -0700 |
commit | 80a1e12868bed96aaef78ce5d4abac42e56625ba (patch) | |
tree | 1a10fa3bfd0b73e94b526d9ec7ddba12508fd593 /simpleperf/record_file_reader.cpp | |
parent | c2adeafb3cc0c69643f56cd66781cb5b30cd4ab7 (diff) | |
download | extras-80a1e12868bed96aaef78ce5d4abac42e56625ba.tar.gz |
simpleperf: export more info through report_lib_interface.
Make below changes to better suppport inferno:
1. Save product properties of device in perf.data.
2. Add a python/c api GetFeatureSection. It is used to support
reading record cmd and meta info from perf.data.
3. Remove old api GetNextMetaInfo, because meta info can be
exported by GetFeatureSection more easily.
4. When reading perf.data in record_file_reader.cpp, remove
callchain at and below ip == 0 to avoid caller's effort.
Also move to use android-base/properties.h.
Bug: http://b/64035530
Test: run simpleperf_unit_test and test.py.
Change-Id: Ib6743a09167e2b7cd65a12f17d991bc1ac628588
Diffstat (limited to 'simpleperf/record_file_reader.cpp')
-rw-r--r-- | simpleperf/record_file_reader.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/simpleperf/record_file_reader.cpp b/simpleperf/record_file_reader.cpp index 67f35bea..38a4b2d6 100644 --- a/simpleperf/record_file_reader.cpp +++ b/simpleperf/record_file_reader.cpp @@ -29,6 +29,46 @@ using namespace PerfFileFormat; +namespace PerfFileFormat { + +static const std::map<int, std::string> feature_name_map = { + {FEAT_TRACING_DATA, "tracing_data"}, + {FEAT_BUILD_ID, "build_id"}, + {FEAT_HOSTNAME, "hostname"}, + {FEAT_OSRELEASE, "osrelease"}, + {FEAT_VERSION, "version"}, + {FEAT_ARCH, "arch"}, + {FEAT_NRCPUS, "nrcpus"}, + {FEAT_CPUDESC, "cpudesc"}, + {FEAT_CPUID, "cpuid"}, + {FEAT_TOTAL_MEM, "total_mem"}, + {FEAT_CMDLINE, "cmdline"}, + {FEAT_EVENT_DESC, "event_desc"}, + {FEAT_CPU_TOPOLOGY, "cpu_topology"}, + {FEAT_NUMA_TOPOLOGY, "numa_topology"}, + {FEAT_BRANCH_STACK, "branch_stack"}, + {FEAT_PMU_MAPPINGS, "pmu_mappings"}, + {FEAT_GROUP_DESC, "group_desc"}, + {FEAT_FILE, "file"}, + {FEAT_META_INFO, "meta_info"}, +}; + +std::string GetFeatureName(int feature_id) { + auto it = feature_name_map.find(feature_id); + return it == feature_name_map.end() ? "" : it->second; +} + +int GetFeatureId(const std::string& feature_name) { + for (auto& pair : feature_name_map) { + if (pair.second == feature_name) { + return pair.first; + } + } + return -1; +} + +} // namespace PerfFileFormat + std::unique_ptr<RecordFileReader> RecordFileReader::CreateInstance(const std::string& filename) { std::string mode = std::string("rb") + CLOSE_ON_EXEC_MODE; FILE* fp = fopen(filename.c_str(), mode.c_str()); @@ -203,6 +243,20 @@ bool RecordFileReader::ReadRecord(std::unique_ptr<Record>& record, } if (record->type() == SIMPLE_PERF_RECORD_EVENT_ID) { ProcessEventIdRecord(*static_cast<EventIdRecord*>(record.get())); + } else if (record->type() == PERF_RECORD_SAMPLE) { + SampleRecord* r = static_cast<SampleRecord*>(record.get()); + // Although we have removed ip == 0 callchains when recording dwarf based callgraph, + // stack frame based callgraph can also generate ip == 0 callchains. Remove them here + // to avoid caller's effort. + if (r->sample_type & PERF_SAMPLE_CALLCHAIN) { + size_t i; + for (i = 0; i < r->callchain_data.ip_nr; ++i) { + if (r->callchain_data.ips[i] == 0) { + break; + } + } + r->callchain_data.ip_nr = i; + } } if (sorted) { record_cache_->Push(std::move(record)); |