Skip to content

Commit

Permalink
MDEV-12345 Performance : replace calls to clock() inside trx_start_lo…
Browse files Browse the repository at this point in the history
…w() by THD::start_utime
  • Loading branch information
vaintroub committed Mar 23, 2017
1 parent 09a2107 commit e5b67a4
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 4 deletions.
9 changes: 9 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4534,6 +4534,15 @@ extern "C" int thd_rpl_is_parallel(const MYSQL_THD thd)
return thd->rgi_slave && thd->rgi_slave->is_parallel_exec;
}


/* Returns high resolution timestamp for the start
of the current query. */
extern "C" unsigned long long thd_start_utime(const MYSQL_THD thd)
{
return thd->start_utime;
}


/*
This function can optionally be called to check if thd_report_wait_for()
needs to be called for waits done by a given transaction.
Expand Down
9 changes: 9 additions & 0 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,15 @@ thd_has_edited_nontrans_tables(
return((ibool) thd_non_transactional_update(thd));
}

/* Return high resolution timestamp for the start of the current query */
UNIV_INTERN
ib_uint64_t
thd_query_start_micro(
const THD* thd) /*!< in: thread handle */
{
return thd_start_utime(thd);
}

/******************************************************************//**
Returns true if the thread is executing a SELECT statement.
@return true if thd is executing SELECT */
Expand Down
9 changes: 9 additions & 0 deletions storage/innobase/handler/ha_innodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ int thd_slave_thread(const MYSQL_THD thd);
*/
int thd_non_transactional_update(const MYSQL_THD thd);

/**
Get high resolution timestamp for the current query start time.
The timestamp is not anchored to any specific point in time,
but can be used for comparison.
@retval timestamp in microseconds precision
*/
unsigned long long thd_start_utime(const MYSQL_THD thd);

/**
Get the user thread's binary logging format
@param thd user thread
Expand Down
7 changes: 7 additions & 0 deletions storage/innobase/include/ha_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ thd_has_edited_nontrans_tables(
/*===========================*/
THD* thd); /*!< in: thread handle */

/**
Get high resolution timestamp for the current query start time.
@retval timestamp in microseconds precision
*/
unsigned long long thd_query_start_micro(const MYSQL_THD thd);

/*************************************************************//**
Prints info of a THD object (== user session thread) to the given file. */
UNIV_INTERN
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ struct trx_t{

time_t start_time; /*!< time the trx state last time became
TRX_STATE_ACTIVE */
clock_t start_time_micro; /*!< start time of transaction in
ib_uint64_t start_time_micro; /*!< start time of transaction in
microseconds */
trx_id_t id; /*!< transaction id */
XID xid; /*!< X/Open XA transaction
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/trx/trx0trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,8 @@ trx_start_low(

trx->start_time = ut_time();

trx->start_time_micro = clock();
trx->start_time_micro =
trx->mysql_thd ? thd_query_start_micro(trx->mysql_thd) : 0;

MONITOR_INC(MONITOR_TRX_ACTIVE);
}
Expand Down
9 changes: 9 additions & 0 deletions storage/xtradb/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,15 @@ thd_has_edited_nontrans_tables(
return((ibool) thd_non_transactional_update(thd));
}

/* Return high resolution timestamp for the start of the current query */
UNIV_INTERN
ib_uint64_t
thd_query_start_micro(
const THD* thd) /*!< in: thread handle */
{
return thd_start_utime(thd);
}

/******************************************************************//**
Returns true if the thread is executing a SELECT statement.
@return true if thd is executing SELECT */
Expand Down
9 changes: 9 additions & 0 deletions storage/xtradb/handler/ha_innodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ int thd_slave_thread(const MYSQL_THD thd);
*/
int thd_non_transactional_update(const MYSQL_THD thd);

/**
Get high resolution timestamp for the current query start time.
The timestamp is not anchored to any specific point in time,
but can be used for comparison.
@retval timestamp in microseconds precision
*/
unsigned long long thd_start_utime(const MYSQL_THD thd);

/**
Get the user thread's binary logging format
@param thd user thread
Expand Down
7 changes: 7 additions & 0 deletions storage/xtradb/include/ha_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ thd_has_edited_nontrans_tables(
/*===========================*/
THD* thd); /*!< in: thread handle */

/**
Get high resolution timestamp for the current query start time.

@retval timestamp in microseconds precision
*/
unsigned long long thd_query_start_micro(const MYSQL_THD thd);

/*************************************************************//**
Prints info of a THD object (== user session thread) to the given file. */
UNIV_INTERN
Expand Down
2 changes: 1 addition & 1 deletion storage/xtradb/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ struct trx_t{

time_t start_time; /*!< time the trx state last time became
TRX_STATE_ACTIVE */
clock_t start_time_micro; /*!< start time of transaction in
ib_uint64_t start_time_micro; /*!< start time of transaction in
microseconds */
trx_id_t id; /*!< transaction id */
XID xid; /*!< X/Open XA transaction
Expand Down
3 changes: 2 additions & 1 deletion storage/xtradb/trx/trx0trx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,8 @@ trx_start_low(

trx->start_time = ut_time();

trx->start_time_micro = clock();
trx->start_time_micro =
trx->mysql_thd ? thd_query_start_micro(trx->mysql_thd) : 0;

MONITOR_INC(MONITOR_TRX_ACTIVE);
}
Expand Down

0 comments on commit e5b67a4

Please sign in to comment.