Skip to content

Commit

Permalink
[CBRD-24584] Improved to minimize the impact of query execution speed…
Browse files Browse the repository at this point in the history
… when setting sql_trace_slow (#4002)

http://jira.cubrid.org/browse/CBRD-24584
  • Loading branch information
beyondykk9 authored Jan 6, 2023
1 parent ba545ef commit f49cb46
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
49 changes: 49 additions & 0 deletions src/base/perf_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,30 @@ perfmon_server_get_stats (THREAD_ENTRY * thread_p)
return pstat_Global.tran_stats[tran_index];
}

/*
* xperfmon_server_copy_stats_for - Copy recorded server statistics for trace
* on the numbers of fetches, ioreads, and iowrites
* return: none
* to_stats(out): buffer to copy
*/
void
xperfmon_server_copy_stats_for_trace (THREAD_ENTRY * thread_p, UINT64 * to_stats)
{
UINT64 *from_stats;

from_stats = perfmon_server_get_stats (thread_p);

if (from_stats != NULL)
{
to_stats[pstat_Metadata[PSTAT_PB_NUM_FETCHES].start_offset] =
from_stats[pstat_Metadata[PSTAT_PB_NUM_FETCHES].start_offset];
to_stats[pstat_Metadata[PSTAT_PB_NUM_IOREADS].start_offset] =
from_stats[pstat_Metadata[PSTAT_PB_NUM_IOREADS].start_offset];
to_stats[pstat_Metadata[PSTAT_PB_NUM_IOWRITES].start_offset] =
from_stats[pstat_Metadata[PSTAT_PB_NUM_IOWRITES].start_offset];
}
}

/*
* xperfmon_server_copy_stats - Copy recorded server statistics for the current
* transaction index
Expand Down Expand Up @@ -1301,6 +1325,31 @@ perfmon_db_flushed_block_volumes (THREAD_ENTRY * thread_p, int num_volumes)
}
#endif /* SERVER_MODE || SA_MODE */

int
perfmon_calc_diff_stats_for_trace (UINT64 * stats_diff, UINT64 * new_stats, UINT64 * old_stats)
{
int i;
int index[3] = {
pstat_Metadata[PSTAT_PB_NUM_FETCHES].start_offset,
pstat_Metadata[PSTAT_PB_NUM_IOREADS].start_offset,
pstat_Metadata[PSTAT_PB_NUM_IOWRITES].start_offset
};

for (i = 0; i < 3; i++)
{
if (new_stats[index[i]] >= old_stats[index[i]])
{
stats_diff[index[i]] = new_stats[index[i]] - old_stats[index[i]];
}
else
{
stats_diff[index[i]] = 0;
}
}

return NO_ERROR;
}

int
perfmon_calc_diff_stats (UINT64 * stats_diff, UINT64 * new_stats, UINT64 * old_stats)
{
Expand Down
1 change: 1 addition & 0 deletions src/base/perf_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ extern void perfmon_server_dump_stats_to_buffer (const UINT64 * stats, char *buf
extern void perfmon_get_current_times (time_t * cpu_usr_time, time_t * cpu_sys_time, time_t * elapsed_time);

extern int perfmon_calc_diff_stats (UINT64 * stats_diff, UINT64 * new_stats, UINT64 * old_stats);
extern int perfmon_calc_diff_stats_for_trace (UINT64 * stats_diff, UINT64 * new_stats, UINT64 * old_stats);
extern int perfmon_initialize (int num_trans);
extern void perfmon_finalize (void);
extern int perfmon_get_number_of_statistic_values (void);
Expand Down
1 change: 1 addition & 0 deletions src/base/xserver_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ extern void xqmgr_dump_query_cache (THREAD_ENTRY * thread_p, FILE * outfp);

/* server execution statistics */
extern void xperfmon_server_copy_stats (THREAD_ENTRY * thread_p, UINT64 * to_stats);
extern void xperfmon_server_copy_stats_for_trace (THREAD_ENTRY * thread_p, UINT64 * to_stats);
extern void xperfmon_server_copy_global_stats (UINT64 * to_stats);
/* catalog manager interface */

Expand Down
21 changes: 18 additions & 3 deletions src/communication/network_interface_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5141,7 +5141,14 @@ sqmgr_execute_query (THREAD_ENTRY * thread_p, unsigned int rid, char *request, i
css_send_abort_to_client (thread_p->conn_entry, rid);
return;
}
xperfmon_server_copy_stats (thread_p, base_stats);
if (prm_get_bool_value (PRM_ID_SQL_TRACE_EXECUTION_PLAN) == true)
{
xperfmon_server_copy_stats (thread_p, base_stats);
}
else
{
xperfmon_server_copy_stats_for_trace (thread_p, base_stats);
}

tsc_getticks (&start_tick);

Expand Down Expand Up @@ -5384,8 +5391,16 @@ sqmgr_execute_query (THREAD_ENTRY * thread_p, unsigned int rid, char *request, i
goto exit;
}

xperfmon_server_copy_stats (thread_p, current_stats);
perfmon_calc_diff_stats (diff_stats, current_stats, base_stats);
if (prm_get_bool_value (PRM_ID_SQL_TRACE_EXECUTION_PLAN) == true)
{
xperfmon_server_copy_stats (thread_p, current_stats);
perfmon_calc_diff_stats (diff_stats, current_stats, base_stats);
}
else
{
xperfmon_server_copy_stats_for_trace (thread_p, current_stats);
perfmon_calc_diff_stats_for_trace (diff_stats, current_stats, base_stats);
}

if (response_time >= trace_slow_msec)
{
Expand Down

0 comments on commit f49cb46

Please sign in to comment.