diff --git a/src/libperfctr.c b/src/libperfctr.c index f26d4d588..09b3fe2f8 100644 --- a/src/libperfctr.c +++ b/src/libperfctr.c @@ -69,6 +69,7 @@ static int registered_cpus = 0; static pthread_mutex_t globalLock = PTHREAD_MUTEX_INITIALIZER; static int use_locks = 0; static pthread_mutex_t threadLocks[MAX_NUM_THREADS] = { [ 0 ... (MAX_NUM_THREADS-1)] = PTHREAD_MUTEX_INITIALIZER}; +static int maxRegionNameLength = 100; /* ##### MACROS - LOCAL TO THIS SOURCE FILE ######################### */ @@ -511,13 +512,15 @@ likwid_markerRegisterRegion(const char* regionTag) TimerData timer; int ret = 0; uint64_t tmp = 0x0ULL; - bstring tag = bfromcstralloc(100, regionTag); - LikwidThreadResults* results; - char groupSuffix[10]; - sprintf(groupSuffix, "-%d", groupSet->activeGroup); - bcatcstr(tag, groupSuffix); + LikwidThreadResults* results = NULL; + bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup); int cpu_id = hashTable_get(tag, &results); bdestroy(tag); + if (!results) + { + fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag); + return -EFAULT; + } #ifndef LIKWID_USE_PERFEVENT // Add CPU to access layer if ACCESSMODE is direct or accessdaemon @@ -532,6 +535,7 @@ likwid_markerRegisterRegion(const char* regionTag) int likwid_markerStartRegion(const char* regionTag) { + LikwidThreadResults* results = NULL; if ( ! likwid_init ) { return -EFAULT; @@ -542,13 +546,13 @@ likwid_markerStartRegion(const char* regionTag) return -EFAULT; } - bstring tag = bfromcstralloc(100, regionTag); - LikwidThreadResults* results; - char groupSuffix[10]; - sprintf(groupSuffix, "-%d", groupSet->activeGroup); - bcatcstr(tag, groupSuffix); - + bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup); int cpu_id = hashTable_get(tag, &results); + if (!results) + { + fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag); + return -EFAULT; + } int thread_id = getThreadID(cpu_id); if (results->state == MARKER_STATE_START) { @@ -591,6 +595,7 @@ likwid_markerStopRegion(const char* regionTag) } TimerData timestamp; + LikwidThreadResults* results = NULL; timer_stop(×tamp); double result = 0.0; int cpu_id; @@ -600,17 +605,22 @@ likwid_markerStopRegion(const char* regionTag) return -EFAULT; } int thread_id; - bstring tag = bfromcstr(regionTag); - char groupSuffix[100]; - LikwidThreadResults* results; - sprintf(groupSuffix, "-%d", groupSet->activeGroup); - bcatcstr(tag, groupSuffix); + bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup); if (use_locks == 1) { pthread_mutex_lock(&threadLocks[myCPU]); } cpu_id = hashTable_get(tag, &results); + if (!results) + { + fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag); + if (use_locks == 1) + { + pthread_mutex_unlock(&threadLocks[myCPU]); + } + return -EFAULT; + } thread_id = getThreadID(cpu_id); if (results->state != MARKER_STATE_START) { @@ -682,13 +692,15 @@ likwid_markerGetRegion( int cpu_id; int myCPU = likwid_getProcessorId(); int thread_id; - bstring tag = bfromcstr(regionTag); - char groupSuffix[100]; - LikwidThreadResults* results; - sprintf(groupSuffix, "-%d", groupSet->activeGroup); - bcatcstr(tag, groupSuffix); + LikwidThreadResults* results = NULL; + bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup); cpu_id = hashTable_get(tag, &results); + if (!results) + { + fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag); + return; + } thread_id = getThreadID(myCPU); if (count != NULL) { @@ -715,6 +727,7 @@ likwid_markerGetRegion( int likwid_markerResetRegion(const char* regionTag) { + LikwidThreadResults* results = NULL; if (! likwid_init) { return -EFAULT; @@ -725,13 +738,14 @@ likwid_markerResetRegion(const char* regionTag) { return -EFAULT; } - bstring tag = bfromcstr(regionTag); - char groupSuffix[100]; - LikwidThreadResults* results; - sprintf(groupSuffix, "-%d", groupSet->activeGroup); - bcatcstr(tag, groupSuffix); + bstring tag = bformat("%.*s-%d", 100, regionTag, groupSet->activeGroup); cpu_id = hashTable_get(tag, &results); + if (!results) + { + fprintf(stderr, "ERROR: Failed to get thread data for tag %s\n", regionTag); + return -EFAULT; + } if (results->state != MARKER_STATE_STOP) { fprintf(stderr, "ERROR: Can only reset stopped regions\n"); diff --git a/src/perfmon.c b/src/perfmon.c index de3a2ba8e..7dc0d5372 100644 --- a/src/perfmon.c +++ b/src/perfmon.c @@ -3903,7 +3903,7 @@ perfmon_readMarkerFile(const char* filename) if (strchr(buf,':')) { int regionid = 0, groupid = -1; - char regiontag[100]; + char regiontag[140]; char* ptr = NULL; char* colonptr = NULL; // zero out ALL of regiontag due to replacing %s with %Nc