@@ -397,6 +397,60 @@ static constexpr size_t n_auto = UT_ARR_SIZE(auto_event_names);
397397extern PSI_memory_key auto_event_keys[n_auto];
398398extern PSI_memory_info pfs_info_auto[n_auto];
399399
400+ /* * gcc 5 fails to evalutate costexprs at compile time. */
401+ #if defined(__GNUG__) && (__GNUG__ == 5)
402+
403+ /* * Compute whether a string begins with a given prefix, compile-time.
404+ @param[in] a first string, taken to be zero-terminated
405+ @param[in] b second string (prefix to search for)
406+ @param[in] b_len length in bytes of second string
407+ @param[in] index character index to start comparing at
408+ @return whether b is a prefix of a */
409+ constexpr bool ut_string_begins_with (const char *a, const char *b, size_t b_len,
410+ size_t index = 0 ) {
411+ return (index == b_len || (a[index] == b[index] &&
412+ ut_string_begins_with (a, b, b_len, index + 1 )));
413+ }
414+
415+ /* * Find the length of the filename without its file extension.
416+ @param[in] file filename, with extension but without directory
417+ @param[in] index character index to start scanning for extension
418+ separator at
419+ @return length, in bytes */
420+ constexpr size_t ut_len_without_extension (const char *file, size_t index = 0 ) {
421+ return ((file[index] == ' \0 ' || file[index] == ' .' )
422+ ? index
423+ : ut_len_without_extension (file, index + 1 ));
424+ }
425+
426+ /* * Retrieve a memory key (registered with PFS), given the file name of the
427+ caller.
428+ @param[in] file portion of the filename - basename, with extension
429+ @param[in] len length of the filename to check for
430+ @param[in] index index of first PSI key to check
431+ @return registered memory key or PSI_NOT_INSTRUMENTED if not found */
432+ constexpr PSI_memory_key ut_new_get_key_by_base_file (const char *file,
433+ size_t len,
434+ size_t index = 0 ) {
435+ return ((index == n_auto)
436+ ? PSI_NOT_INSTRUMENTED
437+ : (ut_string_begins_with (auto_event_names[index], file, len)
438+ ? auto_event_keys[index]
439+ : ut_new_get_key_by_base_file (file, len, index + 1 )));
440+ }
441+
442+ /* * Retrieve a memory key (registered with PFS), given the file name of
443+ the caller.
444+ @param[in] file portion of the filename - basename, with extension
445+ @return registered memory key or PSI_NOT_INSTRUMENTED if not found */
446+ constexpr PSI_memory_key ut_new_get_key_by_file (const char *file) {
447+ return (ut_new_get_key_by_base_file (file, ut_len_without_extension (file)));
448+ }
449+
450+ #define UT_NEW_THIS_FILE_PSI_KEY ut_new_get_key_by_file (MY_BASENAME)
451+
452+ #else /* __GNUG__ == 5 */
453+
400454/* * Compute whether a string begins with a given prefix, compile-time.
401455@param[in] a first string, taken to be zero-terminated
402456@param[in] b second string (prefix to search for)
@@ -461,6 +515,8 @@ struct force_constexpr {
461515 ? PSI_NOT_INSTRUMENTED \
462516 : auto_event_keys[UT_NEW_THIS_FILE_PSI_INDEX])
463517
518+ #endif /* __GNUG__ == 5 */
519+
464520#endif /* UNIV_PFS_MEMORY */
465521
466522/* * A structure that holds the necessary data for performance schema
0 commit comments