diff --git a/openmp/runtime/src/kmp_itt.inl b/openmp/runtime/src/kmp_itt.inl --- a/openmp/runtime/src/kmp_itt.inl +++ b/openmp/runtime/src/kmp_itt.inl @@ -115,7 +115,7 @@ // that the tools more or less standardized on: // "$omp$parallel@[file:][:]" char *buff = NULL; - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 0); buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func, team_size, str_loc.file, str_loc.line, str_loc.col); @@ -155,7 +155,7 @@ if ((frm < KMP_MAX_FRAME_DOMAINS) && (__kmp_itt_region_team_size[frm] != team_size)) { char *buff = NULL; - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 0); buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func, team_size, str_loc.file, str_loc.line, str_loc.col); @@ -212,7 +212,7 @@ // that the tools more or less standardized on: // "$omp$parallel:team_size@[file:][:]" char *buff = NULL; - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 0); buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func, team_size, str_loc.file, str_loc.line, str_loc.col); @@ -234,7 +234,7 @@ return; // something's gone wrong, returning if (__kmp_itt_region_team_size[frm] != team_size) { char *buff = NULL; - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 0); buff = __kmp_str_format("%s$omp$parallel:%d@%s:%d:%d", str_loc.func, team_size, str_loc.file, str_loc.line, str_loc.col); @@ -273,7 +273,7 @@ // Transform compiler-generated region location into the format // that the tools more or less standardized on: // "$omp$frame@[file:][:]" - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 0); if (imbalance) { char *buff_imb = NULL; buff_imb = __kmp_str_format("%s$omp$barrier-imbalance:%d@%s:%d", @@ -364,26 +364,13 @@ __kmp_release_bootstrap_lock(&metadata_lock); } - // Parse line and column from psource string: ";file;func;line;col;;" - char *s_line; - char *s_col; + // Parse line and column from psource string: ";file;func;line;line;;" KMP_DEBUG_ASSERT(loc->psource); -#ifdef __cplusplus - s_line = strchr(CCAST(char *, loc->psource), ';'); -#else - s_line = strchr(loc->psource, ';'); -#endif - KMP_DEBUG_ASSERT(s_line); - s_line = strchr(s_line + 1, ';'); // 2-nd semicolon - KMP_DEBUG_ASSERT(s_line); - s_line = strchr(s_line + 1, ';'); // 3-rd semicolon - KMP_DEBUG_ASSERT(s_line); - s_col = strchr(s_line + 1, ';'); // 4-th semicolon - KMP_DEBUG_ASSERT(s_col); - kmp_uint64 loop_data[5]; - loop_data[0] = atoi(s_line + 1); // read line - loop_data[1] = atoi(s_col + 1); // read column + int line_beg, line_end; + __kmp_str_loc_numbers(loc->psource, &line_beg, &line_end); + loop_data[0] = line_beg; + loop_data[1] = line_end; loop_data[2] = sched_type; loop_data[3] = iterations; loop_data[4] = chunk; @@ -409,12 +396,11 @@ __kmp_release_bootstrap_lock(&metadata_lock); } - kmp_str_loc_t str_loc = __kmp_str_loc_init(loc->psource, 1); + int line_beg, line_end; + __kmp_str_loc_numbers(loc->psource, &line_beg, &line_end); kmp_uint64 single_data[2]; - single_data[0] = str_loc.line; - single_data[1] = str_loc.col; - - __kmp_str_loc_free(&str_loc); + single_data[0] = line_beg; + single_data[1] = line_end; __itt_metadata_add(metadata_domain, __itt_null, string_handle_sngl, __itt_metadata_u64, 2, single_data); diff --git a/openmp/runtime/src/kmp_str.h b/openmp/runtime/src/kmp_str.h --- a/openmp/runtime/src/kmp_str.h +++ b/openmp/runtime/src/kmp_str.h @@ -99,6 +99,7 @@ }; // struct kmp_str_loc typedef struct kmp_str_loc kmp_str_loc_t; kmp_str_loc_t __kmp_str_loc_init(char const *psource, int init_fname); +void __kmp_str_loc_numbers(char const *Psource, int *LineBeg, int *LineEnd); void __kmp_str_loc_free(kmp_str_loc_t *loc); int __kmp_str_eqf(char const *lhs, char const *rhs); diff --git a/openmp/runtime/src/kmp_str.cpp b/openmp/runtime/src/kmp_str.cpp --- a/openmp/runtime/src/kmp_str.cpp +++ b/openmp/runtime/src/kmp_str.cpp @@ -295,6 +295,50 @@ return dir_match && base_match; } // __kmp_str_fname_match +// Get the begin/end construct lines from source location string. +// Function is fast as it does not allocate memory for string duplicate, +// and parses string in place. +void __kmp_str_loc_numbers(char const *Psource, int *LineBeg, int *LineEnd) { + char *Str; + KMP_DEBUG_ASSERT(Psource); + KMP_DEBUG_ASSERT(LineBeg); + KMP_DEBUG_ASSERT(LineEnd); + // Parse Psource string ";file;func;line;line;;" to get line numbers only, + // skipping file and func. + + // Find 1-st semicolon. +#ifdef __cplusplus + Str = strchr(CCAST(char *, Psource), ';'); +#else + Str = strchr(Psource, ';'); +#endif + // Check returned pointer to see if the format of Psource is broken. + if (Str) { + // Find 2-nd semicolon. + Str = strchr(Str + 1, ';'); + } + if (Str) { + // Find 3-rd semicolon. + Str = strchr(Str + 1, ';'); + } + if (Str) { + // Read begin line number. + *LineBeg = atoi(Str + 1); + // Find 4-th semicolon. + Str = strchr(Str + 1, ';'); + } else { + // Broken format of input string, cannot read the number. + *LineBeg = 0; + } + if (Str) { + // Read end line number. + *LineEnd = atoi(Str + 1); + } else { + // Broken format of input string, cannot read the number. + *LineEnd = 0; + } +} + kmp_str_loc_t __kmp_str_loc_init(char const *psource, int init_fname) { kmp_str_loc_t loc;