summaryrefslogtreecommitdiff
path: root/simpleperf/sample_tree.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-07-01 10:00:52 -0700
committerYabin Cui <yabinc@google.com>2015-07-01 14:58:48 -0700
commitecb9a302b52b034610efb85bd73cb473e7c4ddb2 (patch)
tree8327580f42acfc10f0a19c0ed0f4b1bf5536ea56 /simpleperf/sample_tree.cpp
parentb36f72ec4b30b7926c03c42b1f1feb089f462160 (diff)
downloadextras-ecb9a302b52b034610efb85bd73cb473e7c4ddb2.tar.gz
Simpleperf: support callgraph option in report command.
Bug: 19483574 Change-Id: I7c5558a71ea15650c1d3e7afa268b3fbc11543d7
Diffstat (limited to 'simpleperf/sample_tree.cpp')
-rw-r--r--simpleperf/sample_tree.cpp64
1 files changed, 19 insertions, 45 deletions
diff --git a/simpleperf/sample_tree.cpp b/simpleperf/sample_tree.cpp
index d07a8d29..3f0e5b3f 100644
--- a/simpleperf/sample_tree.cpp
+++ b/simpleperf/sample_tree.cpp
@@ -166,20 +166,8 @@ SampleEntry* SampleTree::AddSample(int pid, int tid, uint64_t ip, uint64_t time,
const MapEntry* map = FindMap(thread, ip, in_kernel);
const SymbolEntry* symbol = FindSymbol(map, ip);
- SampleEntry value = {
- ip, time, period,
- 0, // accumulated_period
- 1, // sample_count
- thread,
- thread->comm, // thead_comm
- map, symbol,
- BranchFromEntry{
- 0, // ip
- nullptr, // map
- nullptr, // symbol
- 0, // flags
- },
- };
+ SampleEntry value(ip, time, period, 0, 1, thread, map, symbol);
+
return InsertSample(value);
}
@@ -197,20 +185,12 @@ void SampleTree::AddBranchSample(int pid, int tid, uint64_t from_ip, uint64_t to
}
const SymbolEntry* to_symbol = FindSymbol(to_map, to_ip);
- SampleEntry value = {to_ip, // ip
- time, period,
- 0, // accumulated_period
- 1, // sample_count
- thread,
- thread->comm, // thread_comm
- to_map, // map
- to_symbol, // symbol
- BranchFromEntry{
- from_ip, // ip
- from_map, // map
- from_symbol, // symbol
- branch_flags, // flags
- }};
+ SampleEntry value(to_ip, time, period, 0, 1, thread, to_map, to_symbol);
+ value.branch_from.ip = from_ip;
+ value.branch_from.map = from_map;
+ value.branch_from.symbol = from_symbol;
+ value.branch_from.flags = branch_flags;
+
InsertSample(value);
}
@@ -221,21 +201,8 @@ SampleEntry* SampleTree::AddCallChainSample(int pid, int tid, uint64_t ip, uint6
const MapEntry* map = FindMap(thread, ip, in_kernel);
const SymbolEntry* symbol = FindSymbol(map, ip);
- SampleEntry value = {
- ip, time,
- 0, // period
- period, // accumulated_period
- 0, // sample_count
- thread,
- thread->comm, // thread_comm
- map, symbol,
- BranchFromEntry{
- 0, // ip
- nullptr, // map
- nullptr, // symbol
- 0, // flags
- },
- };
+ SampleEntry value(ip, time, 0, period, 0, thread, map, symbol);
+
auto it = sample_tree_.find(&value);
if (it != sample_tree_.end()) {
SampleEntry* sample = *it;
@@ -265,8 +232,8 @@ SampleEntry* SampleTree::InsertSample(SampleEntry& value) {
return result;
}
-SampleEntry* SampleTree::AllocateSample(const SampleEntry& value) {
- SampleEntry* sample = new SampleEntry(value);
+SampleEntry* SampleTree::AllocateSample(SampleEntry& value) {
+ SampleEntry* sample = new SampleEntry(std::move(value));
sample_storage_.push_back(std::unique_ptr<SampleEntry>(sample));
return sample;
}
@@ -285,10 +252,17 @@ const SymbolEntry* SampleTree::FindSymbol(const MapEntry* map, uint64_t ip) {
return symbol;
}
+void SampleTree::InsertCallChainForSample(SampleEntry* sample,
+ const std::vector<SampleEntry*>& callchain,
+ uint64_t period) {
+ sample->callchain.AddCallChain(callchain, period);
+}
+
void SampleTree::VisitAllSamples(std::function<void(const SampleEntry&)> callback) {
if (sorted_sample_tree_.size() != sample_tree_.size()) {
sorted_sample_tree_.clear();
for (auto& sample : sample_tree_) {
+ sample->callchain.SortByPeriod();
sorted_sample_tree_.insert(sample);
}
}