CUBRID Engine  latest
broker_log_replay.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include "cubrid_getopt.h"
#include "cas_common.h"
#include "cas_cci.h"
#include "broker_log_util.h"
#include "porting.h"
#include "error_code.h"
Include dependency graph for broker_log_replay.c:

Go to the source code of this file.

Classes

struct  t_sql_info
 
struct  t_summary_info
 
struct  t_sql_result
 

Macros

#define STAT_MAX_DIFF_TIME   (60000) /* 60 * 1000 : 10 min */
 
#define SORT_BUF_MAX   (4096)
 
#define BIND_STR_BUF_SIZE   (4096)
 
#define SQL_INFO_TITLE_LEN   (128)
 
#define CCI_ERR_FILE_NAME   "replay.err"
 
#define PASS_SQL_FILE_NAME   "skip.sql"
 
#define DEFAULT_DIFF_TIME_LOWER   (0.01) /* 10 millisecond */
 
#define DEFAULT_BREAK_TIME   (0.01) /* 10 millisecond */
 
#define INVALID_PORT_NUM   (-1)
 
#define free_and_init(ptr)
 

Typedefs

typedef enum temp_read_result READ_RESULT
 
typedef struct t_sql_info T_SQL_INFO
 
typedef struct t_summary_info T_SUMMARY_INFO
 
typedef struct t_sql_result T_SQL_RESULT
 

Enumerations

enum  temp_read_result { READ_STOP = -1, READ_CONTINUE = 0, READ_SUCCESS = 1 }
 

Functions

static int log_replay (char *infilename, char *outfilename)
 
static char * get_next_log_line (FILE *infp, T_STRING *linebuf_tstr, const off_t last_offset, int *lineno)
 
static char * get_query_stmt_from_plan (int req)
 
static int log_prepare (FILE *cci_err, FILE *pass_sql, int con, char *sql_log, T_SQL_INFO *sql_info, T_SUMMARY_INFO *summary)
 
static int get_cci_type (char *p)
 
static int log_bind_value (int req, T_STRING *linebuf, char *sql_log, char *output_result, int remain_bind_buf)
 
static int log_execute (int con_h, int req, char *sql_log, double *execute_time)
 
static void get_sql_time_info (char *sql_log, T_SQL_INFO *info)
 
static void update_diff_time_statistics (double diff_time)
 
static int print_temp_result (char *sql_log, T_SQL_INFO *info)
 
static void update_summary_info (T_SUMMARY_INFO *summary, T_SQL_INFO *sql_info)
 
static void print_summary_info (T_SUMMARY_INFO *summary)
 
static void print_result (FILE *outfp, double max_diff_time, double min_diff_time, int tmp_line_len_max)
 
static char * make_sql_info (char *info_buf, char *start_p, int diff_time, int buf_size)
 
static int result_sort_func (const void *arg1, const void *arg2)
 
static READ_RESULT get_temp_file_line (char *read_buf, unsigned int read_buf_size, int *diff_time, char **endp)
 
static int print_result_without_sort (FILE *outfp, int print_diff_time_lower, int read_buf_max)
 
static int print_result_with_sort (FILE *outfp, int print_diff_time_lower, int num_query, int read_buf_max)
 
static int get_args (int argc, char *argv[])
 
static int open_file (char *infilename, char *outfilename, FILE **infp, FILE **outfp, FILE **cci_errfp, FILE **skip_sqlfp)
 
static void close_file (FILE *infp, FILE *outfp, FILE *cci_errfp, FILE *skip_sqlfp)
 
int main (int argc, char *argv[])
 

Variables

static char * host = NULL
 
static int broker_port = INVALID_PORT_NUM
 
static char * dbname = NULL
 
static char * dbuser = NULL
 
static char * dbpasswd = NULL
 
static char from_date [128] = ""
 
static char to_date [128] = ""
 
static char check_date_flag = 0
 
static char rewrite_query_flag = 0
 
static int break_time = 0
 
static double print_result_diff_time_lower = 0
 
static FILE * br_tmpfp = NULL
 
static unsigned int num_slower_queries [STAT_MAX_DIFF_TIME] = { 0 }
 
static unsigned int num_faster_queries [STAT_MAX_DIFF_TIME] = { 0 }
 

Macro Definition Documentation

#define BIND_STR_BUF_SIZE   (4096)

Definition at line 45 of file broker_log_replay.c.

Referenced by log_replay().

#define CCI_ERR_FILE_NAME   "replay.err"

Definition at line 48 of file broker_log_replay.c.

Referenced by open_file().

#define DEFAULT_BREAK_TIME   (0.01) /* 10 millisecond */

Definition at line 52 of file broker_log_replay.c.

Referenced by get_args().

#define DEFAULT_DIFF_TIME_LOWER   (0.01) /* 10 millisecond */

Definition at line 51 of file broker_log_replay.c.

Referenced by get_args().

#define free_and_init (   ptr)
Value:
do { \
if ((ptr)) { \
free ((ptr)); \
(ptr) = NULL; \
} \
} while (0)
#define NULL
Definition: freelistheap.h:34
if(extra_options)
Definition: dynamic_load.c:958

Definition at line 56 of file broker_log_replay.c.

Referenced by get_query_stmt_from_plan(), log_prepare(), log_replay(), print_result_with_sort(), and print_result_without_sort().

#define INVALID_PORT_NUM   (-1)

Definition at line 54 of file broker_log_replay.c.

Referenced by get_args().

#define PASS_SQL_FILE_NAME   "skip.sql"

Definition at line 49 of file broker_log_replay.c.

Referenced by open_file().

#define SORT_BUF_MAX   (4096)

Definition at line 44 of file broker_log_replay.c.

Referenced by print_result().

#define SQL_INFO_TITLE_LEN   (128)

Definition at line 46 of file broker_log_replay.c.

Referenced by print_result_with_sort(), and print_result_without_sort().

#define STAT_MAX_DIFF_TIME   (60000) /* 60 * 1000 : 10 min */

Definition at line 43 of file broker_log_replay.c.

Referenced by print_result(), and update_diff_time_statistics().

Typedef Documentation

Definition at line 70 of file broker_log_replay.c.

typedef struct t_sql_info T_SQL_INFO

Definition at line 72 of file broker_log_replay.c.

typedef struct t_sql_result T_SQL_RESULT

Definition at line 96 of file broker_log_replay.c.

Definition at line 83 of file broker_log_replay.c.

Enumeration Type Documentation

Enumerator
READ_STOP 
READ_CONTINUE 
READ_SUCCESS 

Definition at line 64 of file broker_log_replay.c.

Function Documentation

static void close_file ( FILE *  infp,
FILE *  outfp,
FILE *  cci_errfp,
FILE *  skip_sqlfp 
)
static

Definition at line 1619 of file broker_log_replay.c.

References br_tmpfp, and NULL.

Referenced by log_replay(), and open_file().

Here is the caller graph for this function:

static int get_args ( int  argc,
char *  argv[] 
)
static
static int get_cci_type ( char *  p)
static

Definition at line 621 of file broker_log_replay.c.

Referenced by log_bind_value().

Here is the caller graph for this function:

static char * get_next_log_line ( FILE *  infp,
T_STRING linebuf_tstr,
const off_t  last_offset,
int *  lineno 
)
static

Definition at line 391 of file broker_log_replay.c.

References assert, NULL, strlen, t_string_len(), t_string_str(), and ut_get_line().

Referenced by log_replay().

Here is the caller graph for this function:

static char * get_query_stmt_from_plan ( int  req)
static

Definition at line 431 of file broker_log_replay.c.

References error(), free_and_init, NULL, p, strlen, and trim().

Referenced by log_prepare().

Here is the caller graph for this function:

static void get_sql_time_info ( char *  sql_log,
T_SQL_INFO info 
)
static

Definition at line 921 of file broker_log_replay.c.

References assert, t_sql_info::diff_time, t_sql_info::exec_time, NULL, and t_sql_info::sql_log_time.

Referenced by log_replay().

Here is the caller graph for this function:

static READ_RESULT get_temp_file_line ( char *  read_buf,
unsigned int  read_buf_size,
int *  diff_time,
char **  endp 
)
static

Definition at line 1156 of file broker_log_replay.c.

References br_tmpfp, p, READ_CONTINUE, READ_STOP, READ_SUCCESS, and str_to_int32().

Referenced by print_result_with_sort(), and print_result_without_sort().

Here is the caller graph for this function:

static int log_bind_value ( int  req,
T_STRING linebuf,
char *  sql_log,
char *  output_result,
int  remain_bind_buf 
)
static

Definition at line 747 of file broker_log_replay.c.

References assert, ER_FAILED, get_cci_type(), NO_ERROR, NULL, p, str_to_int32(), and t_string_bind_len().

Referenced by log_replay().

Here is the caller graph for this function:

static int log_execute ( int  con_h,
int  req,
char *  sql_log,
double *  execute_time 
)
static

Definition at line 858 of file broker_log_replay.c.

References assert, break_time, ER_FAILED, mode, NULL, SLEEP_MILISEC, ut_diff_time(), and ut_get_execute_type().

Referenced by log_replay().

Here is the caller graph for this function:

static int log_prepare ( FILE *  cci_err,
FILE *  pass_sql,
int  con,
char *  sql_log,
T_SQL_INFO sql_info,
T_SUMMARY_INFO summary 
)
static
int main ( int  argc,
char *  argv[] 
)

Definition at line 1650 of file broker_log_replay.c.

References assert, dbpasswd, ER_FAILED, get_args(), infilename, log_replay(), and NULL.

static char * make_sql_info ( char *  info_buf,
char *  start_p,
int  diff_time,
int  buf_size 
)
static
static int open_file ( char *  infilename,
char *  outfilename,
FILE **  infp,
FILE **  outfp,
FILE **  cci_errfp,
FILE **  skip_sqlfp 
)
static

Definition at line 1566 of file broker_log_replay.c.

References br_tmpfp, CCI_ERR_FILE_NAME, close_file(), ER_FAILED, error(), NO_ERROR, NULL, and PASS_SQL_FILE_NAME.

Referenced by log_replay().

Here is the caller graph for this function:

static void print_result ( FILE *  outfp,
double  max_diff_time,
double  min_diff_time,
int  tmp_line_len_max 
)
static

Definition at line 1394 of file broker_log_replay.c.

References i, num_faster_queries, num_slower_queries, print_result_with_sort(), print_result_without_sort(), SORT_BUF_MAX, and STAT_MAX_DIFF_TIME.

Referenced by log_replay().

Here is the caller graph for this function:

static int print_result_with_sort ( FILE *  outfp,
int  print_diff_time_lower,
int  num_query,
int  read_buf_max 
)
static
static int print_result_without_sort ( FILE *  outfp,
int  print_diff_time_lower,
int  read_buf_max 
)
static
static int print_temp_result ( char *  sql_log,
T_SQL_INFO info 
)
static

Definition at line 976 of file broker_log_replay.c.

References t_sql_info::bind_str, br_tmpfp, t_sql_info::diff_time, t_sql_info::exec_time, NULL, t_sql_info::rewrite_sql, t_sql_info::sql, t_sql_info::sql_log_time, and strlen.

Referenced by log_replay().

Here is the caller graph for this function:

static int result_sort_func ( const void *  arg1,
const void *  arg2 
)
static

Definition at line 1136 of file broker_log_replay.c.

Referenced by print_result_with_sort().

Here is the caller graph for this function:

static void update_diff_time_statistics ( double  diff_time)
static

Definition at line 938 of file broker_log_replay.c.

References assert, num_faster_queries, num_slower_queries, and STAT_MAX_DIFF_TIME.

Referenced by log_replay().

Here is the caller graph for this function:

static void update_summary_info ( T_SUMMARY_INFO summary,
T_SQL_INFO sql_info 
)
static

Variable Documentation

int break_time = 0
static

Definition at line 145 of file broker_log_replay.c.

Referenced by get_args(), and log_execute().

int broker_port = INVALID_PORT_NUM
static
char check_date_flag = 0
static

Definition at line 141 of file broker_log_replay.c.

Referenced by get_args(), and log_replay().

char* dbpasswd = NULL
static

Definition at line 137 of file broker_log_replay.c.

Referenced by get_args(), log_replay(), main(), and ux_check_connection().

char* dbuser = NULL
static
char from_date[128] = ""
static

Definition at line 139 of file broker_log_replay.c.

Referenced by get_args(), and log_replay().

unsigned int num_faster_queries[STAT_MAX_DIFF_TIME] = { 0 }
static

Definition at line 151 of file broker_log_replay.c.

Referenced by print_result(), and update_diff_time_statistics().

unsigned int num_slower_queries[STAT_MAX_DIFF_TIME] = { 0 }
static

Definition at line 150 of file broker_log_replay.c.

Referenced by print_result(), and update_diff_time_statistics().

double print_result_diff_time_lower = 0
static

Definition at line 146 of file broker_log_replay.c.

Referenced by get_args(), log_replay(), print_summary_info(), and update_summary_info().

char rewrite_query_flag = 0
static

Definition at line 143 of file broker_log_replay.c.

Referenced by get_args(), and log_prepare().

char to_date[128] = ""
static

Definition at line 140 of file broker_log_replay.c.

Referenced by get_args(), and log_replay().