From 499426dd665b746f5849072e72422470aa943ae0 Mon Sep 17 00:00:00 2001
From: Nikita Malyavin <nikitamalyavin@gmail.com>
Date: Wed, 25 Sep 2024 00:31:19 +0200
Subject: [PATCH] time measures

---
 sql/sql_base.cc | 5 ++++-
 sql/sys_vars.cc | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 716c3450ba6..88ad8a75fa5 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -5009,7 +5009,7 @@ add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx,
   } while ((tables= tables->next_global));
   DBUG_RETURN(FALSE);
 }
-
+extern ulonglong global_time_spent;
 /**
   Extend the table_list to include foreign tables for prelocking.
 
@@ -5046,6 +5046,7 @@ prepare_fk_prelocking_list(THD *thd, Query_tables_list *prelocking_ctx,
   }
 
   *need_prelocking= TRUE;
+  clock_t start= clock();
 
   while ((fk= fk_list_it++))
   {
@@ -5072,6 +5073,8 @@ prepare_fk_prelocking_list(THD *thd, Query_tables_list *prelocking_ctx,
         &prelocking_ctx->query_tables_last,
         table_list->for_insert_data);
   }
+  clock_t measured_time= clock() - start;
+  global_time_spent+= measured_time;
   if (arena)
     thd->restore_active_arena(arena, &backup);
   DBUG_RETURN(FALSE);
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 47e31291e6b..3e02f301e0c 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -7327,3 +7327,9 @@ static Sys_var_enum Sys_block_encryption_mode(
   "AES_ENCRYPT() and AES_DECRYPT() functions",
   SESSION_VAR(block_encryption_mode), CMD_LINE(REQUIRED_ARG),
   block_encryption_mode_values, DEFAULT(0));
+
+ulonglong global_time_spent= 0;
+static Sys_var_ulonglong Sys_time_spent(
+        "time_spent", "",
+        GLOBAL_VAR(global_time_spent), CMD_LINE(NO_ARG),
+        VALID_RANGE(0, ULONGLONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
-- 
2.30.9