Skip to content

Commit a928b93

Browse files
Sarbojit2019zma2
andauthored
[Unitrace] code clean-ups (#877)
* [Unitrace] code clean-ups Signed-off-by: Sarbojit Sarkar <sarbojit.sarkar@intel.com> * Fix minor miss alignment issues. Signed-off-by: Sarbojit Sarkar <sarbojit.sarkar@intel.com> * Update chromelogger.h --------- Signed-off-by: Sarbojit Sarkar <sarbojit.sarkar@intel.com> Co-authored-by: Zhiqiang Ma <zhiqiang.ma@intel.com>
1 parent db9bf16 commit a928b93

18 files changed

Lines changed: 930 additions & 930 deletions

tools/unitrace/src/chromelogger.h

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ static std::string EncodeURI(const std::string &input) {
5555

5656
static std::string rank = (utils::GetEnv("PMI_RANK").empty()) ? utils::GetEnv("PMIX_RANK") : utils::GetEnv("PMI_RANK");
5757
#ifdef _WIN32
58-
static uint32_t mpi_rank = rank.empty() ? _getpid() : std::atoi(rank.c_str()); // use pid as a dummy rank id
58+
static uint32_t mpi_rank = rank.empty() ? _getpid() : std::atoi(rank.c_str()); // use pid as a dummy rank id
5959
#else /* _WIN32 */
60-
static uint32_t mpi_rank = rank.empty() ? getpid() : std::atoi(rank.c_str()); // use pid as a dummy rank id
60+
static uint32_t mpi_rank = rank.empty() ? getpid() : std::atoi(rank.c_str()); // use pid as a dummy rank id
6161
#endif /* _WIN32 */
6262

6363
static std::string pmi_hostname = GetHostName();
@@ -80,16 +80,16 @@ static std::mutex device_pid_tid_map_lock_;
8080
struct ZeDevicePidKey {
8181
ze_pci_address_ext_t pci_addr_;
8282
int32_t parent_device_id_;
83-
int32_t device_id_;
84-
int32_t subdevice_id_;
83+
int32_t device_id_;
84+
int32_t subdevice_id_;
8585
int32_t host_pid_;
8686
};
8787

8888
struct ZeDeviceTidKey {
8989
ze_pci_address_ext_t pci_addr_;
9090
int32_t parent_device_id_;
91-
int32_t device_id_;
92-
int32_t subdevice_id_;
91+
int32_t device_id_;
92+
int32_t subdevice_id_;
9393
uint32_t engine_ordinal_;
9494
uint32_t engine_index_;
9595
int32_t host_pid_;
@@ -110,11 +110,11 @@ struct ZeDeviceTidKeyCompare {
110110

111111
static std::map<ZeDeviceTidKey, std::tuple<uint32_t, uint32_t, uint64_t>, ZeDeviceTidKeyCompare> device_tid_map_;
112112

113-
static uint32_t next_device_pid_ = (uint32_t)(~0) - (mpi_rank << 5); // each rank uses no more than 32 devices
114-
static uint32_t next_device_tid_ = (uint32_t)(~0) - (mpi_rank << 5); // the first device thread is the "main" thread which has the same id as the device process id
113+
static uint32_t next_device_pid_ = (uint32_t)(~0) - (mpi_rank << 5); // each rank uses no more than 32 devices
114+
static uint32_t next_device_tid_ = (uint32_t)(~0) - (mpi_rank << 5); // the first device thread is the "main" thread which has the same id as the device process id
115115

116116
static std::tuple<uint32_t, uint32_t> GetDevicePidTid(ze_device_handle_t device, uint32_t engine_ordinal,
117-
uint32_t engine_index, int host_pid, int host_tid) {
117+
uint32_t engine_index, int host_pid, int host_tid) {
118118
if (device_logging_no_thread_) {
119119
// map all threads to the process
120120
host_tid = host_pid;
@@ -129,14 +129,14 @@ static std::tuple<uint32_t, uint32_t> GetDevicePidTid(ze_device_handle_t device,
129129
uint32_t device_pid;
130130
uint32_t device_tid;
131131
const std::lock_guard<std::mutex> lock(device_pid_tid_map_lock_);
132-
132+
133133
ze_pci_ext_properties_t *props;
134134
int32_t device_id;
135135
int32_t parent_device_id;
136136
int32_t subdevice_id;
137137
props = GetZeDevicePciPropertiesAndId(device, &parent_device_id, &device_id, &subdevice_id);
138138
PTI_ASSERT(props != nullptr);
139-
139+
140140
ZeDeviceTidKey tid_key;
141141

142142
memset(&tid_key, 0, sizeof(ZeDeviceTidKey));
@@ -176,7 +176,7 @@ static std::tuple<uint32_t, uint32_t> GetDevicePidTid(ze_device_handle_t device,
176176
std::lock_guard<std::recursive_mutex> lock(logger_lock_);
177177

178178
std::string str = ",\n{\"ph\": \"M\", \"name\": \"process_name\", \"pid\": " + std::to_string(device_pid) +
179-
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
179+
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
180180
if (rank.empty()) {
181181
str += "DEVICE<" + pmi_hostname + ">";
182182
}
@@ -219,7 +219,7 @@ static std::tuple<uint32_t, uint32_t> GetDevicePidTid(ze_device_handle_t device,
219219
std::lock_guard<std::recursive_mutex> lock(logger_lock_);
220220

221221
std::string str = ",\n{\"ph\": \"M\", \"name\": \"thread_name\", \"pid\": " + std::to_string(device_pid) + ", \"tid\": " +
222-
std::to_string(device_tid) + ", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
222+
std::to_string(device_tid) + ", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
223223
if (device_logging_no_thread_) {
224224
if (device_logging_no_engine_) {
225225
str += "L0\"}}";
@@ -229,7 +229,7 @@ static std::tuple<uint32_t, uint32_t> GetDevicePidTid(ze_device_handle_t device,
229229
}
230230
} else {
231231
if (device_logging_no_engine_) {
232-
str += "Thread " + std::to_string(tid_key.host_tid_) + " L0\"}}";
232+
str += "Thread " + std::to_string(tid_key.host_tid_) + " L0\"}}";
233233
} else {
234234
str += "Thread " + std::to_string(tid_key.host_tid_);
235235
str += " " + GetZeEngineName(device, tid_key.engine_ordinal_);
@@ -320,11 +320,11 @@ static std::tuple<uint32_t, uint32_t> ClGetDevicePidTid(cl_device_pci_bus_info_k
320320
device_pid = next_device_pid_--;
321321
auto start_time = UniTimer::GetEpochTimeInUs(UniTimer::GetHostTimestamp());
322322
cl_device_pid_map_.insert({pid_key, std::make_tuple(device_pid, start_time)});
323-
323+
324324
std::lock_guard<std::recursive_mutex> lock(logger_lock_);
325325

326326
std::string str = ",\n{\"ph\": \"M\", \"name\": \"process_name\", \"pid\": " + std::to_string(device_pid) +
327-
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
327+
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
328328
if (rank.empty()) {
329329
str += "DEVICE<" + pmi_hostname + ">";
330330
}
@@ -347,8 +347,8 @@ static std::tuple<uint32_t, uint32_t> ClGetDevicePidTid(cl_device_pci_bus_info_k
347347
snprintf(str2, sizeof(str2), "%x", pid_key.pci_addr_.pci_function);
348348
str += std::string(str2);
349349

350-
str += "\"}}";
351-
350+
str += "\"}}";
351+
352352
logger_->Log(str);
353353
logger_->Flush();
354354
}
@@ -359,8 +359,8 @@ static std::tuple<uint32_t, uint32_t> ClGetDevicePidTid(cl_device_pci_bus_info_k
359359
std::lock_guard<std::recursive_mutex> lock(logger_lock_);
360360

361361
std::string str = ",\n{\"ph\": \"M\", \"name\": \"thread_name\", \"pid\": " + std::to_string(device_pid) +
362-
", \"tid\": " + std::to_string(device_tid) +
363-
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
362+
", \"tid\": " + std::to_string(device_tid) +
363+
", \"ts\": " + std::to_string(start_time) + ", \"args\": {\"name\": \"";
364364
if (device_logging_no_thread_) {
365365
if (device_logging_no_engine_) {
366366
str += "CL\"}}";
@@ -369,21 +369,21 @@ static std::tuple<uint32_t, uint32_t> ClGetDevicePidTid(cl_device_pci_bus_info_k
369369
char str2[128];
370370

371371
snprintf(str2, sizeof(str2), "%p", tid_key.queue_);
372-
str += "CL Queue<" + std::string(str2) + ">\"}}";
372+
str += "CL Queue<" + std::string(str2) + ">\"}}";
373373
}
374374
}
375375
else {
376376
if (device_logging_no_engine_) {
377-
str += "Thread " + std::to_string(tid_key.host_tid_) + " CL\"}}";
377+
str += "Thread " + std::to_string(tid_key.host_tid_) + " CL\"}}";
378378
}
379379
else {
380380
char str2[128];
381381

382382
snprintf(str2, sizeof(str2), "%p", tid_key.queue_);
383-
str += "Thread " + std::to_string(tid_key.host_tid_) + " CL Queue<" + std::string(str2) + ">\"}}";
383+
str += "Thread " + std::to_string(tid_key.host_tid_) + " CL Queue<" + std::string(str2) + ">\"}}";
384384
}
385385
}
386-
386+
387387
logger_->Log(str);
388388
logger_->Flush();
389389
}
@@ -498,7 +498,7 @@ static std::string convertDataToString(IttArgs* args) {
498498
class TraceBuffer;
499499
std::set<TraceBuffer *> *trace_buffers_ = nullptr;
500500

501-
#define BUFFER_SLICE_SIZE_DEFAULT (0x1 << 20)
501+
#define BUFFER_SLICE_SIZE_DEFAULT (0x1 << 20)
502502

503503
class TraceBuffer {
504504
public:
@@ -510,21 +510,21 @@ class TraceBuffer {
510510
}
511511
else {
512512
buffer_capacity_ = std::stoi(szstr);
513-
if (buffer_capacity_ == 0) {
514-
buffer_capacity_ = 1; // at least one event slot
513+
if (buffer_capacity_ == 0) {
514+
buffer_capacity_ = 1; // at least one event slot
515515
flush_immediately_ = true;
516516
}
517517
slice_capacity_ = buffer_capacity_;
518518
}
519519
ZeKernelCommandExecutionRecord *der = (ZeKernelCommandExecutionRecord *)(malloc(sizeof(ZeKernelCommandExecutionRecord) * slice_capacity_));
520520
UniMemory::ExitIfOutOfMemory((void *)(der));
521521

522-
device_event_buffer_.push_back(der);
522+
device_event_buffer_.push_back(der);
523523

524524
HostEventRecord *her = (HostEventRecord *)(malloc(sizeof(HostEventRecord) * slice_capacity_));
525525
UniMemory::ExitIfOutOfMemory((void *)(her));
526526

527-
host_event_buffer_.push_back(her);
527+
host_event_buffer_.push_back(her);
528528
tid_= utils::GetTid();
529529
pid_= utils::GetPid();
530530

@@ -542,7 +542,7 @@ class TraceBuffer {
542542
metrics_enabled_ = false;
543543
}
544544

545-
std::lock_guard<std::recursive_mutex> lock(logger_lock_); // use this lock to protect trace_buffers_
545+
std::lock_guard<std::recursive_mutex> lock(logger_lock_); // use this lock to protect trace_buffers_
546546

547547
if (trace_buffers_ == NULL) {
548548
trace_buffers_ = new std::set<TraceBuffer *>;
@@ -880,7 +880,7 @@ class TraceBuffer {
880880
FlushHostEvent(host_event_buffer_[current_host_event_buffer_slice_][j]);
881881
}
882882
current_host_event_buffer_slice_ = 0;
883-
next_host_event_index_ = 0;
883+
next_host_event_index_ = 0;
884884
host_event_buffer_flushed_ = true;
885885
}
886886

@@ -918,11 +918,11 @@ class TraceBuffer {
918918

919919
private:
920920
int32_t buffer_capacity_;
921-
int32_t slice_capacity_; // each buffer can have multiple slices
922-
int32_t current_device_event_buffer_slice_; // device slice in use
923-
int32_t current_host_event_buffer_slice_; // host slice in use
924-
int32_t next_device_event_index_; // next free device event in in-use slice
925-
int32_t next_host_event_index_; // next free host event in in-use slice
921+
int32_t slice_capacity_; // each buffer can have multiple slices
922+
int32_t current_device_event_buffer_slice_; // device slice in use
923+
int32_t current_host_event_buffer_slice_; // host slice in use
924+
int32_t next_device_event_index_; // next free device event in in-use slice
925+
int32_t next_host_event_index_; // next free host event in in-use slice
926926
uint32_t tid_;
927927
uint32_t pid_;
928928
std::vector<ZeKernelCommandExecutionRecord *> device_event_buffer_;
@@ -947,21 +947,21 @@ class ClTraceBuffer {
947947
slice_capacity_ = BUFFER_SLICE_SIZE_DEFAULT;
948948
} else {
949949
buffer_capacity_ = std::stoi(szstr);
950-
if (buffer_capacity_ == 0){
951-
buffer_capacity_ = 1; // at least one event slot
952-
flush_immediately_ = true;
950+
if (buffer_capacity_ == 0) {
951+
buffer_capacity_ = 1; // at least one event slot
952+
flush_immediately_ = true;
953953
}
954954
slice_capacity_ = buffer_capacity_;
955955
}
956956
ClKernelCommandExecutionRecord *der = (ClKernelCommandExecutionRecord *)(malloc(sizeof(ClKernelCommandExecutionRecord) * slice_capacity_));
957957
UniMemory::ExitIfOutOfMemory((void *)(der));
958958

959-
device_event_buffer_.push_back(der);
959+
device_event_buffer_.push_back(der);
960960

961961
HostEventRecord *her = (HostEventRecord *)(malloc(sizeof(HostEventRecord) * slice_capacity_));
962962
UniMemory::ExitIfOutOfMemory((void *)(her));
963963

964-
host_event_buffer_.push_back(her);
964+
host_event_buffer_.push_back(her);
965965
tid_= utils::GetTid();
966966
pid_= utils::GetPid();
967967

@@ -978,7 +978,7 @@ class ClTraceBuffer {
978978
metrics_enabled_ = false;
979979
}
980980

981-
std::lock_guard<std::recursive_mutex> lock(logger_lock_); // use this lock to protect trace_buffers_
981+
std::lock_guard<std::recursive_mutex> lock(logger_lock_); // use this lock to protect trace_buffers_
982982

983983
if (cl_trace_buffers_ == nullptr) {
984984
cl_trace_buffers_ = new std::set<ClTraceBuffer *>;
@@ -1288,8 +1288,8 @@ class ClTraceBuffer {
12881288
args = args->next;
12891289
free(toFree);
12901290
}
1291-
// reset count to 0
1292-
rec.itt_args_.count = 0;
1291+
// reset count to 0
1292+
rec.itt_args_.count = 0;
12931293
}
12941294

12951295
if (!str_args.empty()) {
@@ -1361,11 +1361,11 @@ class ClTraceBuffer {
13611361

13621362
private:
13631363
int32_t buffer_capacity_;
1364-
int32_t slice_capacity_; // each buffer can have multiple slices
1365-
int32_t current_device_event_buffer_slice_; // device slice in use
1366-
int32_t current_host_event_buffer_slice_; // host slice in use
1367-
int32_t next_device_event_index_; // next free device event in in-use slice
1368-
int32_t next_host_event_index_; // next free host event in in-use slice
1364+
int32_t slice_capacity_; // each buffer can have multiple slices
1365+
int32_t current_device_event_buffer_slice_; // device slice in use
1366+
int32_t current_host_event_buffer_slice_; // host slice in use
1367+
int32_t next_device_event_index_; // next free device event in in-use slice
1368+
int32_t next_host_event_index_; // next free host event in in-use slice
13691369
uint32_t tid_;
13701370
uint32_t pid_;
13711371
std::vector<ClKernelCommandExecutionRecord *> device_event_buffer_;
@@ -1398,7 +1398,7 @@ class ChromeLogger {
13981398
std::string dir = utils::GetEnv("UNITRACE_TraceOutputDir");
13991399
chrome_trace_file_name_ = (dir + '/' + chrome_trace_file_name_);
14001400
}
1401-
1401+
14021402
if (this->CheckOption(TRACE_KERNEL_NAME_FILTER)) {
14031403
if (this->CheckOption(TRACE_K_NAME_FILTER_IN)) {
14041404
filter_in_ = true;
@@ -1538,19 +1538,18 @@ class ChromeLogger {
15381538
if ((metadata_args != nullptr) && (metadata_args->count != 0)) {
15391539
rec->api_type_ = API_TYPE_ITT;
15401540
rec->itt_args_ = *metadata_args;
1541-
}
1542-
else {
1541+
} else {
15431542
// no arguments so set api_type_ to API_TYPE_NONE
15441543
rec->api_type_ = API_TYPE_NONE;
15451544
rec->itt_args_.count = 0;
1546-
}
1545+
}
15471546

15481547
thread_local_buffer_.BufferHostEvent();
15491548
}
15501549
}
15511550

1552-
static void MpiLoggingCallback(const char *name, uint64_t start_ts, uint64_t end_ts,size_t src_size, int src_location, int src_tag,
1553-
size_t dst_size, int dst_location, int dst_tag) {
1551+
static void MpiLoggingCallback(const char *name, uint64_t start_ts, uint64_t end_ts, size_t src_size, int src_location, int src_tag,
1552+
size_t dst_size, int dst_location, int dst_tag) {
15541553
if (!thread_local_buffer_.IsFinalized()) {
15551554
HostEventRecord *rec = thread_local_buffer_.GetHostEvent();
15561555
rec->type_ = EVENT_COMPLETE;
@@ -1632,7 +1631,7 @@ class ChromeLogger {
16321631
cl_device_id device,
16331632
cl_command_queue& queue,
16341633
int tile,
1635-
bool implicit,
1634+
bool implicit,
16361635
const uint64_t id,
16371636
uint64_t started,
16381637
uint64_t ended) {
@@ -1660,7 +1659,7 @@ class ChromeLogger {
16601659
#endif /* BUILD_WITH_OPENCL */
16611660

16621661
static void ChromeCallLoggingCallback(std::vector<uint64_t> *kids, FLOW_DIR flow_dir, API_TRACING_ID api_id,
1663-
uint64_t started, uint64_t ended) {
1662+
uint64_t started, uint64_t ended) {
16641663
if (thread_local_buffer_.IsFinalized()) {
16651664
return;
16661665
}
@@ -1705,7 +1704,7 @@ class ChromeLogger {
17051704
}
17061705

17071706
static void ClChromeCallLoggingCallback(std::vector<uint64_t> *kids, FLOW_DIR flow_dir, API_TRACING_ID api_id,
1708-
uint64_t started, uint64_t ended) {
1707+
uint64_t started, uint64_t ended) {
17091708
if (cl_thread_local_buffer_.IsFinalized()) {
17101709
return;
17111710
}

tools/unitrace/src/itt/itt_collector.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ ITT_EXTERN_C int ITTAPI __itt_event_start(__itt_event event) {
449449
if (!UniController::IsCollectionEnabled()) {
450450
return __itt_error_success;
451451
}
452-
452+
453453
if (!itt_collector->IsCclSummaryOn() && !itt_collector->IsEnableChromeLoggingOn()) {
454454
return __itt_error_success;
455455
}
456456

457457
if ((event < 0) || (event >= num_itt_events)) { // let it race
458-
return __itt_error_no_symbol; // which error code to return?
458+
return __itt_error_no_symbol; // which error code to return?
459459
}
460460

461461
uint64_t start = UniTimer::GetHostTimestamp();
@@ -473,7 +473,7 @@ ITT_EXTERN_C int ITTAPI __itt_event_end(__itt_event event) {
473473
return __itt_error_success;
474474
}
475475
if ((event < 0) || (event >= num_itt_events)) { // let it race
476-
return __itt_error_no_symbol; // which error code to return?
476+
return __itt_error_no_symbol; // which error code to return?
477477
}
478478

479479
auto it = event_desc.find(event);
@@ -494,7 +494,7 @@ ITT_EXTERN_C int ITTAPI __itt_event_end(__itt_event event) {
494494
return __itt_error_success;
495495
}
496496

497-
return __itt_error_no_symbol; // which error code to return?
497+
return __itt_error_no_symbol; // which error code to return?
498498
}
499499

500500

@@ -546,7 +546,7 @@ ITT_EXTERN_C void ITTAPI __itt_marker(const __itt_domain *domain, __itt_id id, _
546546
}
547547
}
548548
}
549-
549+
550550
uint64_t ts = UniTimer::GetHostTimestamp();
551551
itt_collector->Log(marker, ts, ts, nullptr);
552552
}

0 commit comments

Comments
 (0)