@@ -32,6 +32,9 @@ using namespace tbox;
32
32
33
33
// ! 统计
34
34
struct Stat {
35
+ uint64_t name_index = 0 ;
36
+ uint64_t module_index = 0 ;
37
+
35
38
size_t times = 0 ; // ! 次数
36
39
uint64_t dur_acc_us = 0 ; // ! 累积时长
37
40
uint64_t dur_min_us = std::numeric_limits<uint64_t >::max(); // ! 最小时长
@@ -212,20 +215,15 @@ int main(int argc, char **argv)
212
215
// ! 第一次遍历记录文件
213
216
ReadAllRecordFiles (records_dir, record_file_name_vec,
214
217
[&] (uint64_t start_ts_us, uint64_t duration_us, uint64_t name_index, uint64_t module_index, uint64_t thread_index) {
215
- std::string name = " unknown-name" , thread = " unknown-thread" , module = " unknown-module" ;
216
-
217
- if (name_index < name_vec.size ())
218
- name = name_vec[name_index];
219
-
220
- if (thread_index < thread_vec.size ())
221
- thread = thread_vec[thread_index];
222
-
223
- if (module_index < module_vec.size ())
224
- module = module_vec[module_index];
218
+ auto &name = name_vec.at (name_index);
219
+ auto &module = module_vec.at (module_index);
220
+ auto &thread = thread_vec.at (thread_index);
225
221
226
222
writer.writeRecorder (name, module, thread, start_ts_us, duration_us);
227
223
228
224
auto &stat = stat_vec.at (name_index);
225
+ stat.name_index = name_index;
226
+ stat.module_index = module_index;
229
227
++stat.times ;
230
228
stat.dur_acc_us += duration_us;
231
229
if (stat.dur_max_us < duration_us) {
@@ -252,25 +250,19 @@ int main(int argc, char **argv)
252
250
if (duration_us < stat.dur_warn_line_us )
253
251
return ;
254
252
255
- std::string name = " unknown-name" , module = " unknown-module" ;
256
-
257
- if (name_index < name_vec.size ())
258
- name = name_vec[name_index];
259
-
260
- if (module_index < module_vec.size ())
261
- module = module_vec[module_index];
253
+ auto &name = name_vec.at (name_index);
254
+ auto &module = module_vec.at (module_index);
262
255
263
256
++stat.dur_warn_count ;
264
257
writer.writeRecorder (name, module, " WARN" , start_ts_us, duration_us);
265
258
}
266
259
);
267
260
268
261
// ! 标记出最大时间点
269
- auto size = name_vec.size ();
270
- for (size_t i = 0 ; i < size; ++i) {
271
- auto &name = name_vec.at (i);
272
- auto &stat = stat_vec.at (i);
273
- writer.writeRecorder (name, " " , " MAX" , stat.dur_max_ts_us , stat.dur_max_us );
262
+ for (auto &stat : stat_vec) {
263
+ auto &name = name_vec.at (stat.name_index );
264
+ auto &module = module_vec.at (stat.module_index );
265
+ writer.writeRecorder (name, module, " MAX" , stat.dur_max_ts_us , stat.dur_max_us );
274
266
}
275
267
276
268
writer.writeFooter ();
0 commit comments