| 1126 | } |
| 1127 | |
| 1128 | void print_task(std::ostream& os, bthread_t tid, bool enable_trace, |
| 1129 | bool ignore_not_matched = false) { |
| 1130 | TaskMeta* const m = TaskGroup::address_meta(tid); |
| 1131 | if (m == NULL) { |
| 1132 | os << "bthread=" << tid << " : never existed\n"; |
| 1133 | return; |
| 1134 | } |
| 1135 | const uint32_t given_ver = get_version(tid); |
| 1136 | bool matched = false; |
| 1137 | bool stop = false; |
| 1138 | bool interrupted = false; |
| 1139 | bool about_to_quit = false; |
| 1140 | void* (*fn)(void*) = NULL; |
| 1141 | void* arg = NULL; |
| 1142 | bthread_attr_t attr = BTHREAD_ATTR_NORMAL; |
| 1143 | bool has_tls = false; |
| 1144 | int64_t cpuwide_start_ns = 0; |
| 1145 | TaskStatistics stat = {0, 0, 0}; |
| 1146 | TaskStatus status = TASK_STATUS_UNKNOWN; |
| 1147 | bool traced = false; |
| 1148 | pthread_t worker_tid{}; |
| 1149 | { |
| 1150 | BAIDU_SCOPED_LOCK(m->version_lock); |
| 1151 | if (given_ver == *m->version_butex) { |
| 1152 | matched = true; |
| 1153 | stop = m->stop; |
| 1154 | interrupted = m->interrupted; |
| 1155 | about_to_quit = m->about_to_quit; |
| 1156 | fn = m->fn; |
| 1157 | arg = m->arg; |
| 1158 | attr = m->attr; |
| 1159 | has_tls = m->local_storage.keytable; |
| 1160 | cpuwide_start_ns = m->cpuwide_start_ns; |
| 1161 | stat = m->stat; |
| 1162 | status = m->status; |
| 1163 | traced = m->traced; |
| 1164 | worker_tid = m->worker_tid; |
| 1165 | } |
| 1166 | } |
| 1167 | if (!matched) { |
| 1168 | if (!ignore_not_matched) { |
| 1169 | os << "bthread=" << tid << " : not exist now\n"; |
| 1170 | } |
| 1171 | } else { |
| 1172 | os << "bthread=" << tid << " :\nstop=" << stop |
| 1173 | << "\ninterrupted=" << interrupted |
| 1174 | << "\nabout_to_quit=" << about_to_quit |
| 1175 | << "\nfn=" << (void*)fn |
| 1176 | << "\narg=" << (void*)arg |
| 1177 | << "\nattr={stack_type=" << attr.stack_type |
| 1178 | << " flags=" << attr.flags |
| 1179 | << " specified_tag=" << attr.tag |
| 1180 | << " name=" << attr.name |
| 1181 | << " keytable_pool=" << attr.keytable_pool |
| 1182 | << "}\nhas_tls=" << has_tls |
| 1183 | << "\nuptime_ns=" << butil::cpuwide_time_ns() - cpuwide_start_ns |
| 1184 | << "\ncputime_ns=" << stat.cputime_ns |
| 1185 | << "\nnswitch=" << stat.nswitch |
no test coverage detected