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 *line_beg, int *line_end); 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,38 @@ 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 *line_beg, int *line_end) { + char *str; + KMP_DEBUG_ASSERT(psource); + KMP_DEBUG_ASSERT(line_beg); + KMP_DEBUG_ASSERT(line_end); + // Parse psource string: ";file;func;line;line;;" to get line and col only, + // skipping file and func. +#ifdef __cplusplus + str = strchr(CCAST(char *, psource), ';'); // find 1-st semicolon +#else + str = strchr(psource, ';'); // find 1-st semicolon +#endif + // check returned pointer just in case the format of psource is broken + if (str) + str = strchr(str + 1, ';'); // find 2-nd semicolon + if (str) + str = strchr(str + 1, ';'); // find 3-rd semicolon + if (str) { + *line_beg = atoi(str + 1); // read begin line number + str = strchr(str + 1, ';'); // find 4-th semicolon + } else { + *line_beg = 0; // broken format of input string, cannot read number + } + if (str) + *line_end = atoi(str + 1); // read column number + else + *line_end = 0; // broken format of input string, cannot read number +} // kmp_str_loc_numbers + kmp_str_loc_t __kmp_str_loc_init(char const *psource, int init_fname) { kmp_str_loc_t loc;