summaryrefslogtreecommitdiff
path: root/simpleperf/thread_tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'simpleperf/thread_tree.cpp')
-rw-r--r--simpleperf/thread_tree.cpp53
1 files changed, 23 insertions, 30 deletions
diff --git a/simpleperf/thread_tree.cpp b/simpleperf/thread_tree.cpp
index 17061ce7..3b90d518 100644
--- a/simpleperf/thread_tree.cpp
+++ b/simpleperf/thread_tree.cpp
@@ -46,7 +46,6 @@ void ThreadTree::ForkThread(int pid, int tid, int ppid, int ptid) {
if (child->maps->maps.empty()) {
*child->maps = *parent->maps;
} else {
- CHECK_NE(child->maps, parent->maps);
for (auto& pair : parent->maps->maps) {
InsertMap(*child->maps, *pair.second);
}
@@ -54,39 +53,34 @@ void ThreadTree::ForkThread(int pid, int tid, int ppid, int ptid) {
}
}
-ThreadEntry* ThreadTree::FindThread(int tid) {
- if (auto it = thread_tree_.find(tid); it != thread_tree_.end()) {
- return it->second.get();
- }
- return nullptr;
-}
-
ThreadEntry* ThreadTree::FindThreadOrNew(int pid, int tid) {
auto it = thread_tree_.find(tid);
- if (it != thread_tree_.end() && pid == it->second.get()->pid) {
- return it->second.get();
- }
- if (it != thread_tree_.end()) {
- ExitThread(it->second.get()->pid, tid);
+ if (it == thread_tree_.end()) {
+ return CreateThread(pid, tid);
+ } else {
+ if (pid != it->second.get()->pid) {
+ // TODO: b/22185053.
+ LOG(DEBUG) << "unexpected (pid, tid) pair: expected ("
+ << it->second.get()->pid << ", " << tid << "), actual (" << pid
+ << ", " << tid << ")";
+ }
}
- return CreateThread(pid, tid);
+ return it->second.get();
}
ThreadEntry* ThreadTree::CreateThread(int pid, int tid) {
- const char* comm;
- std::shared_ptr<MapSet> maps;
+ MapSet* maps = nullptr;
if (pid == tid) {
- comm = "unknown";
- maps.reset(new MapSet);
+ maps = new MapSet;
+ map_set_storage_.push_back(std::unique_ptr<MapSet>(maps));
} else {
// Share maps among threads in the same thread group.
ThreadEntry* process = FindThreadOrNew(pid, pid);
- comm = process->comm;
maps = process->maps;
}
ThreadEntry* thread = new ThreadEntry{
pid, tid,
- comm,
+ "unknown",
maps,
};
auto pair = thread_tree_.insert(std::make_pair(tid, std::unique_ptr<ThreadEntry>(thread)));
@@ -94,13 +88,6 @@ ThreadEntry* ThreadTree::CreateThread(int pid, int tid) {
return thread;
}
-void ThreadTree::ExitThread(int pid, int tid) {
- auto it = thread_tree_.find(tid);
- if (it != thread_tree_.end() && pid == it->second.get()->pid) {
- thread_tree_.erase(it);
- }
-}
-
void ThreadTree::AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff,
const std::string& filename) {
// kernel map len can be 0 when record command is not run in supervisor mode.
@@ -273,6 +260,7 @@ const Symbol* ThreadTree::FindKernelSymbol(uint64_t ip) {
void ThreadTree::ClearThreadAndMap() {
thread_tree_.clear();
thread_comm_storage_.clear();
+ map_set_storage_.clear();
kernel_maps_.maps.clear();
map_storage_.clear();
}
@@ -325,9 +313,6 @@ void ThreadTree::Update(const Record& record) {
} else if (record.type() == PERF_RECORD_FORK) {
const ForkRecord& r = *static_cast<const ForkRecord*>(&record);
ForkThread(r.data->pid, r.data->tid, r.data->ppid, r.data->ptid);
- } else if (record.type() == PERF_RECORD_EXIT) {
- const ExitRecord& r = *static_cast<const ExitRecord*>(&record);
- ExitThread(r.data->pid, r.data->tid);
} else if (record.type() == SIMPLE_PERF_RECORD_KERNEL_SYMBOL) {
const auto& r = *static_cast<const KernelSymbolRecord*>(&record);
Dso::SetKallsyms(std::move(r.kallsyms));
@@ -347,4 +332,12 @@ std::vector<Dso*> ThreadTree::GetAllDsos() const {
return result;
}
+std::vector<const ThreadEntry*> ThreadTree::GetAllThreads() const {
+ std::vector<const ThreadEntry*> threads;
+ for (auto& pair : thread_tree_) {
+ threads.push_back(pair.second.get());
+ }
+ return threads;
+}
+
} // namespace simpleperf