Saves param 'thread_name' to member 'thread_name_'. If the length of param 'thread_name' is larger than THREAD_NAME_SIZE, we store the front of 'thread_name' + '...' + the last few bytes of thread name, e.g.: "Long Threadname with more te...001afec4)"
| 72 | /// we store the front of 'thread_name' + '...' + the last few bytes |
| 73 | /// of thread name, e.g.: "Long Threadname with more te...001afec4)" |
| 74 | void SetThreadName(const std::string& thread_name) { |
| 75 | const int64_t length = thread_name.length(); |
| 76 | |
| 77 | if (length < THREAD_NAME_SIZE) { |
| 78 | thread_name.copy(thread_name_, length); |
| 79 | } else { |
| 80 | const int64_t tail_length = THREAD_NAME_TAIL_LENGTH; |
| 81 | // 4 is the length of "..." and '\0' |
| 82 | const int64_t front_length = THREAD_NAME_SIZE - tail_length - 4; |
| 83 | // copy 'front_length' sized front of 'thread_name' to 'thread_name_' |
| 84 | thread_name.copy(thread_name_, front_length); |
| 85 | // append "..." |
| 86 | for (int i = 0; i < 3; ++i) thread_name_[front_length + i] = '.'; |
| 87 | // append 'tail_length' sized tail of 'thread_name' to 'thread_name_' |
| 88 | thread_name.copy(thread_name_ + front_length + 3, tail_length, |
| 89 | length - tail_length); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void SetParentInfo(const ThreadDebugInfo* parent) { |
| 94 | if (parent == nullptr) return; |