Returns the index of a function. If not found, adds a function proto and returns the function index.
| 102 | // Returns the index of a function. If not found, adds a function proto |
| 103 | // and returns the function index. |
| 104 | uint64 GetIndex(const string& file_path, const string& func_name, |
| 105 | uint64 func_start_line) { |
| 106 | auto key = std::tuple<string, string, uint64>(file_path, func_name, |
| 107 | func_start_line); |
| 108 | auto idx = function_table_.find(key); |
| 109 | if (idx != function_table_.end()) { |
| 110 | return idx->second.id(); |
| 111 | } |
| 112 | pprof::Function* func_pb = &function_table_[key]; |
| 113 | // function index should start from 1. |
| 114 | func_pb->set_id(function_table_.size()); |
| 115 | |
| 116 | string file_base(io::Basename(file_path)); |
| 117 | file_base = file_base.substr(0, file_base.find_last_of(".")); |
| 118 | func_pb->set_name( |
| 119 | string_table_->GetIndex(strings::StrCat(file_base, ":", func_name))); |
| 120 | func_pb->set_filename(string_table_->GetIndex(file_path)); |
| 121 | func_pb->set_start_line(func_start_line); |
| 122 | return func_pb->id(); |
| 123 | } |
| 124 | |
| 125 | const std::map<std::tuple<string, string, uint64>, pprof::Function>& |
| 126 | functions() const { |