thread_tree.cpp revision 73d8078e6e5ef92b2301386ce96260bd99efacbb
160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui/*
260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * Copyright (C) 2015 The Android Open Source Project
360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui *
460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * Licensed under the Apache License, Version 2.0 (the "License");
560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * you may not use this file except in compliance with the License.
660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * You may obtain a copy of the License at
760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui *
860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui *      http://www.apache.org/licenses/LICENSE-2.0
960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui *
1060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * Unless required by applicable law or agreed to in writing, software
1160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * distributed under the License is distributed on an "AS IS" BASIS,
1260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * See the License for the specific language governing permissions and
1460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui * limitations under the License.
1560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui */
1660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
1760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui#include "thread_tree.h"
1860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
1960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui#include <base/logging.h>
2060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui#include "environment.h"
2173d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui#include "perf_event.h"
2273d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui#include "record.h"
2360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
2460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuibool MapComparator::operator()(const MapEntry* map1, const MapEntry* map2) const {
2560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (map1->start_addr != map2->start_addr) {
2660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return map1->start_addr < map2->start_addr;
2760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
2860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (map1->len != map2->len) {
2960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return map1->len < map2->len;
3060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
3160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (map1->time != map2->time) {
3260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return map1->time < map2->time;
3360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
3460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return false;
3560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
3660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
3760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuivoid ThreadTree::AddThread(int pid, int tid, const std::string& comm) {
3860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto it = thread_tree_.find(tid);
3960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (it == thread_tree_.end()) {
4060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    ThreadEntry* thread = new ThreadEntry{
4160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui        pid, tid,
4260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui        "unknown",                             // comm
4360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui        std::set<MapEntry*, MapComparator>(),  // maps
4460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    };
4560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    auto pair = thread_tree_.insert(std::make_pair(tid, std::unique_ptr<ThreadEntry>(thread)));
4660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    CHECK(pair.second);
4760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    it = pair.first;
4860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
4960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  thread_comm_storage_.push_back(std::unique_ptr<std::string>(new std::string(comm)));
5060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  it->second->comm = thread_comm_storage_.back()->c_str();
5160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
5260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
5360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuivoid ThreadTree::ForkThread(int pid, int tid, int ppid, int ptid) {
5460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  ThreadEntry* parent = FindThreadOrNew(ppid, ptid);
5560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  ThreadEntry* child = FindThreadOrNew(pid, tid);
5660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  child->comm = parent->comm;
5760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  child->maps = parent->maps;
5860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
5960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
6060a0ea96c0fb9e807c899759256df5e20bd904bdYabin CuiThreadEntry* ThreadTree::FindThreadOrNew(int pid, int tid) {
6160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto it = thread_tree_.find(tid);
6260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (it == thread_tree_.end()) {
6360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    AddThread(pid, tid, "unknown");
6460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    it = thread_tree_.find(tid);
6560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  } else {
6660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    CHECK_EQ(pid, it->second.get()->pid) << "tid = " << tid;
6760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
6860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return it->second.get();
6960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
7060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
7160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuistatic void RemoveOverlappedMap(std::set<MapEntry*, MapComparator>* map_set, const MapEntry* map) {
7260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  for (auto it = map_set->begin(); it != map_set->end();) {
7360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    if ((*it)->start_addr >= map->start_addr + map->len) {
7460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      break;
7560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    }
7660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    if ((*it)->start_addr + (*it)->len <= map->start_addr) {
7760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      ++it;
7860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    } else {
7960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      it = map_set->erase(it);
8060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    }
8160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
8260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
8360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
8460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuivoid ThreadTree::AddKernelMap(uint64_t start_addr, uint64_t len, uint64_t pgoff, uint64_t time,
8560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui                              const std::string& filename) {
8660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  // kernel map len can be 0 when record command is not run in supervisor mode.
8760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (len == 0) {
8860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return;
8960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
9060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  DsoEntry* dso = FindKernelDsoOrNew(filename);
9160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  MapEntry* map = new MapEntry{
9260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      start_addr, len, pgoff, time, dso,
9360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  };
9460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  map_storage_.push_back(std::unique_ptr<MapEntry>(map));
9560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  RemoveOverlappedMap(&kernel_map_tree_, map);
9660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto pair = kernel_map_tree_.insert(map);
9760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  CHECK(pair.second);
9860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
9960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
10060a0ea96c0fb9e807c899759256df5e20bd904bdYabin CuiDsoEntry* ThreadTree::FindKernelDsoOrNew(const std::string& filename) {
10160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (filename == DEFAULT_KERNEL_MMAP_NAME) {
10260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    if (kernel_dso_ == nullptr) {
10360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      kernel_dso_ = DsoFactory::GetInstance()->CreateDso(DSO_KERNEL);
10460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    }
10560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return kernel_dso_.get();
10660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
10760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto it = module_dso_tree_.find(filename);
10860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (it == module_dso_tree_.end()) {
10960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    module_dso_tree_[filename] = DsoFactory::GetInstance()->CreateDso(DSO_KERNEL_MODULE, filename);
11060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    it = module_dso_tree_.find(filename);
11160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
11260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return it->second.get();
11360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
11460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
11560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuivoid ThreadTree::AddThreadMap(int pid, int tid, uint64_t start_addr, uint64_t len, uint64_t pgoff,
11660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui                              uint64_t time, const std::string& filename) {
11760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  ThreadEntry* thread = FindThreadOrNew(pid, tid);
11860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  DsoEntry* dso = FindUserDsoOrNew(filename);
11960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  MapEntry* map = new MapEntry{
12060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      start_addr, len, pgoff, time, dso,
12160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  };
12260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  map_storage_.push_back(std::unique_ptr<MapEntry>(map));
12360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  RemoveOverlappedMap(&thread->maps, map);
12460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto pair = thread->maps.insert(map);
12560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  CHECK(pair.second);
12660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
12760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
12860a0ea96c0fb9e807c899759256df5e20bd904bdYabin CuiDsoEntry* ThreadTree::FindUserDsoOrNew(const std::string& filename) {
12960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto it = user_dso_tree_.find(filename);
13060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (it == user_dso_tree_.end()) {
13160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    user_dso_tree_[filename] = DsoFactory::GetInstance()->CreateDso(DSO_ELF_FILE, filename);
13260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    it = user_dso_tree_.find(filename);
13360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
13460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return it->second.get();
13560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
13660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
13760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuistatic bool IsAddrInMap(uint64_t addr, const MapEntry* map) {
13860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return (addr >= map->start_addr && addr < map->start_addr + map->len);
13960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
14060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
14160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuistatic MapEntry* FindMapByAddr(const std::set<MapEntry*, MapComparator>& maps, uint64_t addr) {
14260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  // Construct a map_entry which is strictly after the searched map_entry, based on MapComparator.
14360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  MapEntry find_map = {
14460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      addr,        // start_addr
14560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      ULLONG_MAX,  // len
14660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      0,           // pgoff
14760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      ULLONG_MAX,  // time
14860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui      nullptr,     // dso
14960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  };
15060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  auto it = maps.upper_bound(&find_map);
15160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (it != maps.begin() && IsAddrInMap(addr, *--it)) {
15260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    return *it;
15360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
15460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return nullptr;
15560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
15660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
15760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuiconst MapEntry* ThreadTree::FindMap(const ThreadEntry* thread, uint64_t ip, bool in_kernel) {
15860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  MapEntry* result = nullptr;
15960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (!in_kernel) {
16060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    result = FindMapByAddr(thread->maps, ip);
16160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  } else {
16260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    result = FindMapByAddr(kernel_map_tree_, ip);
16360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
16460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return result != nullptr ? result : &unknown_map_;
16560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
16660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui
16760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cuiconst SymbolEntry* ThreadTree::FindSymbol(const MapEntry* map, uint64_t ip) {
16860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  uint64_t offset_in_file;
16960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (map->dso == kernel_dso_.get()) {
17060a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    offset_in_file = ip;
17160a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  } else {
17260a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    offset_in_file = ip - map->start_addr + map->pgoff;
17360a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
17460a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  const SymbolEntry* symbol = map->dso->FindSymbol(offset_in_file);
17560a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  if (symbol == nullptr) {
17660a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui    symbol = &unknown_symbol_;
17760a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  }
17860a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui  return symbol;
17960a0ea96c0fb9e807c899759256df5e20bd904bdYabin Cui}
18073d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui
18173d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cuivoid BuildThreadTree(const std::vector<std::unique_ptr<Record>>& records, ThreadTree* thread_tree) {
18273d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui  for (auto& record : records) {
18373d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui    if (record->header.type == PERF_RECORD_MMAP) {
18473d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      const MmapRecord& r = *static_cast<const MmapRecord*>(record.get());
18573d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      if ((r.header.misc & PERF_RECORD_MISC_CPUMODE_MASK) == PERF_RECORD_MISC_KERNEL) {
18673d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui        thread_tree->AddKernelMap(r.data.addr, r.data.len, r.data.pgoff, r.sample_id.time_data.time,
18773d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui                                  r.filename);
18873d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      } else {
18973d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui        thread_tree->AddThreadMap(r.data.pid, r.data.tid, r.data.addr, r.data.len, r.data.pgoff,
19073d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui                                  r.sample_id.time_data.time, r.filename);
19173d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      }
19273d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui    } else if (record->header.type == PERF_RECORD_MMAP2) {
19373d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      const Mmap2Record& r = *static_cast<const Mmap2Record*>(record.get());
19473d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      if ((r.header.misc & PERF_RECORD_MISC_CPUMODE_MASK) == PERF_RECORD_MISC_KERNEL) {
19573d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui        thread_tree->AddKernelMap(r.data.addr, r.data.len, r.data.pgoff, r.sample_id.time_data.time,
19673d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui                                  r.filename);
19773d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      } else {
19873d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui        std::string filename =
19973d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui            (r.filename == DEFAULT_EXECNAME_FOR_THREAD_MMAP) ? "[unknown]" : r.filename;
20073d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui        thread_tree->AddThreadMap(r.data.pid, r.data.tid, r.data.addr, r.data.len, r.data.pgoff,
20173d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui                                  r.sample_id.time_data.time, filename);
20273d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      }
20373d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui    } else if (record->header.type == PERF_RECORD_COMM) {
20473d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      const CommRecord& r = *static_cast<const CommRecord*>(record.get());
20573d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      thread_tree->AddThread(r.data.pid, r.data.tid, r.comm);
20673d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui    } else if (record->header.type == PERF_RECORD_FORK) {
20773d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      const ForkRecord& r = *static_cast<const ForkRecord*>(record.get());
20873d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui      thread_tree->ForkThread(r.data.pid, r.data.tid, r.data.ppid, r.data.ptid);
20973d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui    }
21073d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui  }
21173d8078e6e5ef92b2301386ce96260bd99efacbbYabin Cui}
212