You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2447 lines
61 KiB

Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
Added progress reporting for alter table, LOAD DATA INFILE and for aria tables: check table, repair table, analyze table. - The client gets a progress report message that triggers a callback function if requested with mysql_options(MYSQL_PROGRESS_CALLBACK, function) - Added Progress field last to 'show processlist' - Stage, Max_stage and Progress field added to information_schema.progresslist - The 'mysql' client by defaults enables progress reports when the output is a tty. - Added progress_report_time time variable to configure how often progress reports is sent to client Added read only system variable 'in_transaction' which is 1 if we have executed a BEGIN statement. client/client_priv.h: Added OPT_REPORT_PROGRESS client/mysql.cc: Added option --progress-reports (on by default if not batch mode) Progress reports is written to stdout for long running commands include/Makefile.am: Added mysql/service_progress_report.h include/myisamchk.h: Added variables to be able to do progress reporting in Aria and later in MyISAM include/mysql.h: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql.h.pp: Added new mysql_options() parameter: MYSQL_PROGRESS_CALLBACK include/mysql/plugin.h: Added functions for reporting progress. include/mysql/plugin_auth.h.pp: Added functions for reporting progress. include/mysql_com.h: Added CLIENT_PROGRESS mysql_real_connect() flag. include/sql_common.h: Added callback function for reporting progress mysql-test/r/old-mode.result: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. mysql-test/suite/funcs_1/datadict/datadict_priv.inc: Added new column mysql-test/suite/funcs_1/datadict/processlist_priv.inc: Test all new PROCESSLIST columns mysql-test/suite/funcs_1/r/is_columns_is.result: Updated results mysql-test/suite/funcs_1/r/is_columns_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_columns_mysql_embedded.result: Updated results mysql-test/suite/funcs_1/r/is_tables_is_embedded.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_priv_ps.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_no_prot.result: Updated results mysql-test/suite/funcs_1/r/processlist_val_ps.result: Updated results mysql-test/suite/pbxt/r/pbxt_locking.result: Updated results mysql-test/suite/pbxt/r/skip_name_resolve.result: Updated results mysql-test/t/old-mode.test: Ensure that SHOW PROGRESSLIST doesn't have the Progress column in old mode. plugin/handler_socket/handlersocket/Makefile.am: Added -lmysqlservices scripts/mytop.sh: Made 'State' field width dynamic. Added 'Progress' to process list display. sql-common/client.c: Added handling of progress messages. Removed check_license() function. sql/mysql_priv.h: Added opt_progress_report_time sql/mysqld.cc: Added progress_report_time time variable to configure how often progress reports is sent to client sql/protocol.cc: Added net_send_progress_packet() sql/protocol.h: New prototypes sql/set_var.cc: Added variables progress_report_time and in_transaction sql/sql_acl.cc: Safety fix: Made client_capabilities ulonglong sql/sql_class.cc: Added interface functions for progress reporting sql/sql_class.h: Added varibles in THD for progress reporting. Added CF_REPORT_PROGRESS sql/sql_load.cc: Added progress reporting for LOAD DATA INFILE sql/sql_parse.cc: Added CF_REPORT_PROGRESS for top level commands for which it's safe to send progress reports to client sql/sql_show.cc: Added Progress field last to 'show processlist' Stage, Max_stage and Progress field added to information_schema.progresslist sql/sql_table.cc: Added progress reporting for ALTER TABLE Added THD as argument to copy_data_between_tables() storage/maria/ha_maria.cc: Added progress reporting for check table, repair table, analyze table Fixed a bug in start_bulk_insert() that caused alter table to always run with all keys enabled. storage/maria/ma_check.c: Added progress reporting Remember old state before starting repair. This removes some warnings from optimize_table if create-with-sort fails. storage/maria/ma_check_standalone.h: Added dummy reporting function for standalone Aria programs. storage/maria/ma_sort.c: Added progress reporting storage/maria/maria_chk.c: Updated version storage/maria/maria_def.h: Added new prototypes tests/mysql_client_test.c: Added test case for progress reporting
15 years ago
  1. #!/usr/bin/env perl
  2. #
  3. # $Id: mytop,v 1.91 2012/01/18 16:49:12 mgrennan Exp $
  4. =pod
  5. =head1 NAME
  6. mytop - display MariaDB server performance info like `top'
  7. =cut
  8. ## most of the POD is at the bottom of the file
  9. use 5.005;
  10. use strict;
  11. use DBI;
  12. use Getopt::Long;
  13. use Socket;
  14. use List::Util qw(min max);
  15. use File::Basename;
  16. $main::VERSION = "1.91a";
  17. my $path_for_script= dirname($0);
  18. $|=1;
  19. $0 = 'mytop';
  20. my $WIN = ($^O eq 'MSWin32') ? 1 : 0;
  21. ## Test for color support.
  22. eval { require Term::ANSIColor; };
  23. my $HAS_COLOR = $@ ? 0 : 1;
  24. $HAS_COLOR = 0 if $WIN;
  25. ## Test of Time::HiRes support
  26. eval { require Time::HiRes };
  27. my $HAS_TIME = $@ ? 0 : 1;
  28. my $debug = 0;
  29. ## Try to lower our priority (which, who, pri)
  30. setpriority(0,0,10) unless $WIN;
  31. ## Prototypes
  32. sub Clear();
  33. sub GetData();
  34. sub GetQPS();
  35. sub FullQueryInfo($);
  36. sub Explain($);
  37. sub PrintTable(@);
  38. sub PrintHelp();
  39. sub Sum(@);
  40. sub commify($);
  41. sub make_short($);
  42. sub Hashes($);
  43. sub Execute($);
  44. sub StringOrRegex($);
  45. sub GetInnoDBStatus();
  46. sub GetCmdSummary();
  47. sub GetShowVariables();
  48. sub GetShowStatus();
  49. sub cmd_s;
  50. sub cmd_S;
  51. sub cmd_q;
  52. ## Default Config Values
  53. my %config = (
  54. batchmode => 0,
  55. color => 1,
  56. db => 'test',
  57. delay => 5,
  58. filter_user => qr/.?/,
  59. filter_db => qr/.?/,
  60. filter_host => qr/.?/,
  61. filter_state => qr/.?/,
  62. header => 1,
  63. help => 0,
  64. host => 'localhost',
  65. idle => 1,
  66. long => 120,
  67. long_nums => 0,
  68. mode => 'top',
  69. prompt => 0,
  70. pass => '',
  71. port => 3306,
  72. resolve => 0,
  73. slow => 10, # slow query time
  74. socket => '',
  75. sort => 1, # default or reverse sort ("s")
  76. user => 'root',
  77. fullqueries => 0
  78. );
  79. my %qcache = (); ## The query cache--used for full query info support.
  80. my %ucache = (); ## The user cache--used for full killing by user
  81. my %dbcache = (); ## The db cache. This should be merged at some point.
  82. my %statcache = (); ## The show status cache for GetShowStatus()
  83. my (%STATUS, %OLD_STATUS); # header stuff.
  84. my $CLEAR = $WIN ? '': `clear`;
  85. ## Term::ReadKey values
  86. my $RM_RESET = 0;
  87. my $RM_NOBLKRD = 3; ## using 4 traps Ctrl-C :-(
  88. # Add options from .my.cnf first
  89. my $my_print_defaults;
  90. if (!defined($my_print_defaults=my_which("my_print_defaults")))
  91. {
  92. print "Warning: Can't find my_print_defaults. Please add it to your PATH!\n";
  93. exit(1);
  94. }
  95. unshift @ARGV, split "\n", `$my_print_defaults client mytop`;
  96. ## Read the user's config file, if it exists.
  97. my $config = "$ENV{HOME}/.mytop";
  98. if (-e $config)
  99. {
  100. if (open CFG, "<$config")
  101. {
  102. while (<CFG>)
  103. {
  104. next if /^\s*$/; ## skip blanks
  105. next if /^\s*#/; ## skip comments
  106. chomp;
  107. if (/(\S+)\s*=\s*(.*\S)/)
  108. {
  109. $config{lc $1} = $2 if exists $config{lc $1};
  110. }
  111. }
  112. close CFG;
  113. }
  114. }
  115. ## Command-line args.
  116. use vars qw($opt_foo);
  117. Getopt::Long::Configure('no_ignore_case', 'bundling');
  118. GetOptions(
  119. "color!" => \$config{color},
  120. "user|u=s" => \$config{user},
  121. "pass|password|p=s" => \$config{pass},
  122. "database|db|d=s" => \$config{db},
  123. "host|h=s" => \$config{host},
  124. "port|P=i" => \$config{port},
  125. "socket|S=s" => \$config{socket},
  126. "delay|s=i" => \$config{delay},
  127. "batch|batchmode|b" => \$config{batchmode},
  128. "header!" => \$config{header},
  129. "idle|i!" => \$config{idle},
  130. "resolve|r!" => \$config{resolve},
  131. "prompt!" => \$config{prompt},
  132. "long=i" => \$config{long},
  133. "long_nums!" => \$config{long_nums},
  134. "mode|m=s" => \$config{mode},
  135. "slow=i" => \$config{slow},
  136. "sort=s" => \$config{sort},
  137. "fullqueries|L!" => \$config{fullqueries}
  138. );
  139. ## User may have put the port with the host.
  140. if ($config{host} =~ s/:(\d+)$//)
  141. {
  142. $config{port} = $1;
  143. }
  144. ## Don't use Term::ReadKey unless running interactively.
  145. if (not $config{batchmode})
  146. {
  147. require Term::ReadKey;
  148. Term::ReadKey->import();
  149. }
  150. ## User may want to disable color.
  151. if ($HAS_COLOR and not $config{color})
  152. {
  153. $HAS_COLOR = 0;
  154. }
  155. if ($HAS_COLOR)
  156. {
  157. import Term::ANSIColor ':constants';
  158. }
  159. else
  160. {
  161. *RESET = sub { };
  162. *YELLOW = sub { };
  163. *RED = sub { };
  164. *MAGENTA = sub { };
  165. *GREEN = sub { };
  166. *BLUE = sub { };
  167. *WHITE = sub { };
  168. *BOLD = sub { };
  169. }
  170. my $RESET = RESET() || '';
  171. my $YELLOW = YELLOW() || '';
  172. my $RED = RED() || '';
  173. my $MAGENTA = MAGENTA() || '';
  174. my $GREEN = GREEN() || '';
  175. my $BLUE = BLUE() || '';
  176. my $WHITE = WHITE() || '';
  177. my $BOLD = BOLD() || '';
  178. ## Connect
  179. my $dsn;
  180. ## Socket takes precedence.
  181. $dsn ="DBI:mysql:database=$config{db};mysql_read_default_group=mytop;";
  182. if ($config{socket} and -S $config{socket})
  183. {
  184. $dsn .= "mysql_socket=$config{socket}";
  185. }
  186. else
  187. {
  188. $dsn .= "host=$config{host};port=$config{port}";
  189. }
  190. if ($config{prompt})
  191. {
  192. print "Password: ";
  193. ReadMode(2);
  194. chomp($config{pass} = <STDIN>);
  195. ReadMode(0);
  196. print "\n";
  197. }
  198. my $dbh = DBI->connect($dsn, $config{user}, $config{pass},
  199. { PrintError => 0 });
  200. if (not ref $dbh)
  201. {
  202. my $Error = <<EODIE
  203. Cannot connect to MariaDB server. Please check the:
  204. * database you specified "$config{db}" (default is "test")
  205. * username you specified "$config{user}" (default is "root")
  206. * password you specified "$config{pass}" (default is "")
  207. * hostname you specified "$config{host}" (default is "localhost")
  208. * port you specified "$config{port}" (default is 3306)
  209. * socket you specified "$config{socket}" (default is "")
  210. The options my be specified on the command-line or in a ~/.mytop
  211. config file. See the manual (perldoc mytop) for details.
  212. Here's the exact error from DBI. It might help you debug:
  213. $DBI::errstr
  214. EODIE
  215. ;
  216. die $Error;
  217. }
  218. ReadMode($RM_RESET) unless $config{batchmode};
  219. ## Get static data
  220. my $db_version;
  221. my $db_release;
  222. my $server="MySQL";
  223. my $have_query_cache;
  224. my @variables = Hashes("show variables");
  225. foreach (@variables)
  226. {
  227. if ($_->{Variable_name} eq "version")
  228. {
  229. $db_version = $_->{Value};
  230. $db_version =~ /(\d+)/;
  231. $db_release= $1;
  232. $server="MariaDB" if ($db_version =~ /maria/i);
  233. next;
  234. }
  235. if ($_->{Variable_name} eq "have_query_cache")
  236. {
  237. # if ($_->{Value} eq 'YES')
  238. if ($_->{Value} eq 'YES' or $_->{Value} eq 'DEMAND') # http://freshmeat.net/users/jerjones
  239. {
  240. $have_query_cache = 1;
  241. }
  242. else
  243. {
  244. $have_query_cache = 0;
  245. }
  246. next;
  247. }
  248. }
  249. #########################################################################
  250. ##
  251. ## The main loop
  252. ##
  253. #########################################################################
  254. ReadMode($RM_NOBLKRD) unless $config{batchmode};
  255. while (1)
  256. {
  257. my $key;
  258. if ($config{mode} eq 'qps')
  259. {
  260. GetQPS();
  261. $key = ReadKey(1);
  262. next unless $key;
  263. if ($key =~ /t/i)
  264. {
  265. $config{mode} = 'top';
  266. }
  267. if ($key =~ /q/)
  268. {
  269. cmd_q();
  270. }
  271. next;
  272. }
  273. if ($config{mode} eq 'top')
  274. {
  275. GetData();
  276. last if $config{batchmode};
  277. $key = ReadKey($config{delay});
  278. next unless $key;
  279. }
  280. elsif ($config{mode} eq 'cmd')
  281. {
  282. GetCmdSummary();
  283. last if $config{batchmode};
  284. $key = ReadKey($config{delay});
  285. next unless $key;
  286. }
  287. elsif ($config{mode} eq 'innodb')
  288. {
  289. GetInnoDBStatus();
  290. last if $config{batchmode};
  291. $key = ReadKey($config{delay});
  292. next unless $key;
  293. }
  294. elsif ($config{mode} eq 'status')
  295. {
  296. GetShowStatus();
  297. last if $config{batchmode};
  298. $key = ReadKey($config{delay});
  299. next unless $key;
  300. }
  301. ##
  302. ## keystroke command processing (if we get this far)
  303. ##
  304. if ($key eq '!')
  305. {
  306. Execute("stop slave");
  307. Execute("set global sql_slave_skip_counter=1");
  308. Execute("start slave");
  309. }
  310. # t - top
  311. if ($key =~ /t/i)
  312. {
  313. $config{mode} = 'top';
  314. }
  315. ## q - quit
  316. if ($key eq 'q')
  317. {
  318. cmd_q();
  319. }
  320. if ($key eq 'D')
  321. {
  322. require Data::Dumper;
  323. print Data::Dumper::Dumper([\%config]);
  324. ReadKey(0);
  325. }
  326. ## l - change long running hightling
  327. if ($key eq 'l')
  328. {
  329. cmd_l();
  330. next;
  331. }
  332. ## m - mode switch to qps
  333. if ($key eq 'm')
  334. {
  335. $config{mode} = 'qps';
  336. Clear() unless $config{batchmode};
  337. print "Queries Per Second [hit q to exit this mode]\n";
  338. next;
  339. }
  340. ## c - mode switch to command summary
  341. if ($key eq 'c')
  342. {
  343. $config{mode} = 'cmd';
  344. Clear() unless $config{batchmode};
  345. print "Command Summary [hit q to exit this mode]\n";
  346. next;
  347. }
  348. ## C - change Color on and off
  349. if ($key eq 'C')
  350. {
  351. if ( $HAS_COLOR )
  352. {
  353. $HAS_COLOR = 0;
  354. }
  355. else
  356. {
  357. $HAS_COLOR = 1;
  358. }
  359. }
  360. ## s - seconds of delay
  361. if ($key eq 's')
  362. {
  363. cmd_s();
  364. next;
  365. }
  366. if ($key eq 'S')
  367. {
  368. cmd_S();
  369. next;
  370. }
  371. ## R - resolve hostnames
  372. if ($key eq 'R')
  373. {
  374. if ($config{resolve})
  375. {
  376. $config{resolve} = 0;
  377. }
  378. else
  379. {
  380. $config{resolve} = 1;
  381. }
  382. }
  383. ## t - username based filter
  384. if ($key eq 't')
  385. {
  386. ReadMode($RM_RESET);
  387. print RED(), "Which state (blank for all, /.../ for regex): ", RESET();
  388. $config{filter_state} = StringOrRegex(ReadLine(0));
  389. ReadMode($RM_NOBLKRD);
  390. next;
  391. }
  392. ## u - username based filter
  393. if ($key eq 'u')
  394. {
  395. ReadMode($RM_RESET);
  396. print RED(), "Which user (blank for all, /.../ for regex): ", RESET();
  397. $config{filter_user} = StringOrRegex(ReadLine(0));
  398. ReadMode($RM_NOBLKRD);
  399. next;
  400. }
  401. ## d - database name based filter
  402. if ($key eq 'd')
  403. {
  404. ReadMode($RM_RESET);
  405. print RED(), "Which database (blank for all, /.../ for regex): ",
  406. RESET();
  407. $config{filter_db} = StringOrRegex(ReadLine(0));
  408. ReadMode($RM_NOBLKRD);
  409. next;
  410. }
  411. ## h - hostname based filter
  412. if ($key eq 'h')
  413. {
  414. ReadMode($RM_RESET);
  415. print RED(), "Which hostname (blank for all, /.../ for regex): ",
  416. RESET();
  417. $config{filter_host} = StringOrRegex(ReadLine(0));
  418. ReadMode($RM_NOBLKRD);
  419. next;
  420. }
  421. ## E - Show full Replication Error
  422. if ($key eq 'E')
  423. {
  424. my($data) = Hashes('SHOW SLAVE STATUS');
  425. Clear();
  426. print "Error is: $data->{Last_Error}\n";
  427. print RED(), "-- paused. press any key to resume --", RESET();
  428. ReadKey(0);
  429. next;
  430. }
  431. ## F - remove all filters
  432. if ($key eq 'F')
  433. {
  434. $config{filter_host} = qr/.?/;
  435. $config{filter_db} = qr/.?/;
  436. $config{filter_user} = qr/.?/;
  437. $config{filter_state} = qr/.?/;
  438. print RED(), "-- display unfiltered --", RESET();
  439. sleep 1;
  440. next;
  441. }
  442. ## p - pause
  443. if ($key eq 'p')
  444. {
  445. print RED(), "-- paused. press any key to resume --", RESET();
  446. ReadKey(0);
  447. next;
  448. }
  449. ## i - idle toggle
  450. if ($key =~ /i/)
  451. {
  452. if ($config{idle})
  453. {
  454. $config{idle} = 0;
  455. $config{sort} = 1;
  456. print RED(), "-- idle (sleeping) processed filtered --", RESET();
  457. sleep 1;
  458. }
  459. else
  460. {
  461. $config{idle} = 1;
  462. $config{sort} = 0;
  463. print RED(), "-- idle (sleeping) processed unfiltered --", RESET();
  464. sleep 1;
  465. }
  466. }
  467. ## I - InnoDB status
  468. if ($key =~ 'I')
  469. {
  470. $config{mode} = 'innodb';
  471. Clear() unless $config{batchmode};
  472. print "InnoDB Status [hit q to exit this mode]\n";
  473. next;
  474. }
  475. ## o - sort order
  476. if ($key =~ /o/)
  477. {
  478. if ($config{sort})
  479. {
  480. $config{sort} = 0;
  481. print RED(), "-- sort order reversed --", RESET();
  482. sleep 1;
  483. }
  484. else
  485. {
  486. $config{sort} = 1;
  487. print RED(), "-- sort order reversed --", RESET();
  488. sleep 1;
  489. }
  490. }
  491. ## ? - help
  492. if ($key eq '?')
  493. {
  494. Clear();
  495. PrintHelp();
  496. ReadKey(0);
  497. next;
  498. }
  499. ## k - kill
  500. if ($key eq 'k')
  501. {
  502. ReadMode($RM_RESET);
  503. print RED(), "Thread id to kill: ", RESET();
  504. my $id = ReadLine(0);
  505. $id =~ s/\s//g;
  506. if ($id =~ /^\d+$/)
  507. {
  508. Execute("KILL $id");
  509. }
  510. else
  511. {
  512. print RED(), "-- invalid thread id --", RESET();
  513. sleep 1;
  514. }
  515. ReadMode($RM_NOBLKRD);
  516. next;
  517. }
  518. ## K - kill based on a username
  519. if ($key =~ /K/)
  520. {
  521. ReadMode($RM_RESET);
  522. print RED(), "User to kill: ", RESET();
  523. my $user = ReadLine(0);
  524. $user =~ s/\s//g;
  525. if ($user =~ /^\S+$/)
  526. {
  527. for my $pid (keys %ucache)
  528. {
  529. next unless $ucache{$pid} eq $user;
  530. Execute("KILL $pid");
  531. select(undef, undef, undef, 0.2);
  532. }
  533. }
  534. else
  535. {
  536. print RED(), "-- invalid thread id --", RESET();
  537. sleep 1;
  538. }
  539. ReadMode($RM_NOBLKRD);
  540. }
  541. ## f - full info
  542. if ($key =~ /f/)
  543. {
  544. ReadMode($RM_RESET);
  545. print RED(), "Full query for which thread id: ", RESET();
  546. my $id = ReadLine(0);
  547. chomp $id;
  548. FullQueryInfo($id);
  549. ReadMode($RM_NOBLKRD);
  550. print RED(), "-- paused. press any key to resume or (e) to explain --",
  551. RESET();
  552. my $key = ReadKey(0);
  553. if ($key eq 'e')
  554. {
  555. Explain($id);
  556. print RED(), "-- paused. press any key to resume --", RESET();
  557. ReadKey(0);
  558. }
  559. next;
  560. }
  561. ## e - explain
  562. if ($key =~ /e/)
  563. {
  564. ReadMode($RM_RESET);
  565. print RED(), "Explain which query (id): ", RESET();
  566. my $id = ReadLine(0);
  567. chomp $id;
  568. Explain($id);
  569. ReadMode($RM_NOBLKRD);
  570. print RED(), "-- paused. press any key to resume --", RESET();
  571. ReadKey(0);
  572. next;
  573. }
  574. ## r - reset status counters
  575. if ($key =~ /r/)
  576. {
  577. Execute("FLUSH STATUS");
  578. print RED(), "-- counters reset --", RESET();
  579. sleep 1;
  580. next;
  581. }
  582. ## H - header toggle
  583. if ($key eq 'H')
  584. {
  585. if ($config{header})
  586. {
  587. $config{header} = 0;
  588. }
  589. else
  590. {
  591. $config{header}++;
  592. }
  593. }
  594. ## # - magic debug key
  595. if ($key eq '#')
  596. {
  597. $debug = 1;
  598. }
  599. if ($key eq 'V')
  600. {
  601. GetShowVariables();
  602. print RED(), "-- paused. press any key to resume --", RESET();
  603. ReadKey(0);
  604. }
  605. # Switch to show status mode
  606. if ($key eq 'M')
  607. {
  608. $config{mode} = 'status';
  609. }
  610. ## L - full queries toggle
  611. if ($key eq 'L')
  612. {
  613. if ($config{fullqueries})
  614. {
  615. $config{fullqueries} = 0;
  616. print RED(), "-- full queries OFF --", RESET();
  617. sleep 1;
  618. }
  619. else
  620. {
  621. $config{fullqueries} = 1;
  622. print RED(), "-- full queries ON --", RESET();
  623. sleep 1;
  624. }
  625. }
  626. }
  627. ReadMode($RM_RESET) unless $config{batchmode};
  628. exit;
  629. #######################################################################
  630. sub Clear()
  631. {
  632. if (not $WIN)
  633. {
  634. print "$CLEAR"
  635. }
  636. else
  637. {
  638. print "\n" x 90; ## dumb hack for now. Anyone know how to
  639. ## clear the screen in dos window on a Win32
  640. ## system??
  641. }
  642. }
  643. my $last_time;
  644. sub GetData()
  645. {
  646. ## Get terminal info
  647. my $now_time;
  648. %qcache = (); ## recycle memory
  649. %dbcache = ();
  650. my ($width, $height, $wpx, $hpx, $lines_left);
  651. if (not $config{batchmode})
  652. {
  653. ($width, $height, $wpx, $hpx) = GetTerminalSize();
  654. $lines_left = $height - 2;
  655. }
  656. else
  657. {
  658. $height = 999_999; ## I hope you don't have more than that!
  659. $lines_left = 999_999;
  660. $width = 80;
  661. }
  662. ##
  663. ## Header stuff.
  664. ##
  665. if ($config{header})
  666. {
  667. my @recs = "";
  668. if ( $db_release > 4 )
  669. {
  670. @recs = Hashes("show global status");
  671. }
  672. else
  673. {
  674. @recs = Hashes("show status");
  675. }
  676. ## if the server died or we lost connectivity
  677. if (not @recs)
  678. {
  679. ReadMode($RM_RESET);
  680. exit 1;
  681. }
  682. ## get high-res or low-res time
  683. my ($t_delta);
  684. if ($HAS_TIME)
  685. {
  686. $now_time = Time::HiRes::gettimeofday();
  687. }
  688. else
  689. {
  690. $now_time = time;
  691. }
  692. if ($last_time and $last_time != $now_time)
  693. {
  694. $t_delta = $now_time - $last_time;
  695. }
  696. %OLD_STATUS = %STATUS;
  697. # Set some status that may not exist in all versions
  698. $STATUS{Handler_tmp_write}= 0;
  699. $STATUS{Handler_tmp_update}= 0;
  700. $STATUS{Rows_tmp_read}= 0;
  701. foreach my $ref (@recs)
  702. {
  703. my $key = $ref->{Variable_name};
  704. my $val = $ref->{Value};
  705. $STATUS{$key} = $val;
  706. }
  707. ## Compute Key Cache Hit Stats
  708. $STATUS{Key_read_requests} ||= 1; ## can't divide by zero next
  709. my $cache_hits_percent = (100-($STATUS{Key_reads}/$STATUS{Key_read_requests}) * 100);
  710. $cache_hits_percent = sprintf("%2.2f",$cache_hits_percent);
  711. ## Query Cache info for <= Ver. 4.1
  712. ##
  713. ## mysql> show status like 'qcache%';
  714. ## +-------------------------+----------+
  715. ## | Variable_name | Value |
  716. ## +-------------------------+----------+
  717. ## | Qcache_queries_in_cache | 81 |
  718. ## | Qcache_inserts | 4961668 |
  719. ## | Qcache_hits | 1374170 |
  720. ## | Qcache_not_cached | 5656249 |
  721. ## | Qcache_free_memory | 33164800 |
  722. ## | Qcache_free_blocks | 2 |
  723. ## | Qcache_total_blocks | 168 |
  724. ## +-------------------------+----------+
  725. ##
  726. ## Query Cache info for => Ver. 5.0
  727. ##
  728. ## mysql> show status like 'qcache%';
  729. ## +-------------------------+------------+
  730. ## | Variable_name | Value |
  731. ## +-------------------------+------------+
  732. ## | Qcache_free_blocks | 37652 |
  733. ## | Qcache_free_memory | 110289712 |
  734. ## | Qcache_hits | 1460617356 |
  735. ## | Qcache_inserts | 390563495 |
  736. ## | Qcache_lowmem_prunes | 6414172 |
  737. ## | Qcache_not_cached | 93002420 |
  738. ## | Qcache_queries_in_cache | 66558 |
  739. ## | Qcache_total_blocks | 192031 |
  740. ## +-------------------------+------------+
  741. my $query_cache_hits = 0;
  742. my $query_cache_hits_per_sec = 0;
  743. my $now_query_cache_hits_per_sec = 0;
  744. if ($have_query_cache)
  745. {
  746. $query_cache_hits = $STATUS{Qcache_hits};
  747. $query_cache_hits_per_sec = $STATUS{Qcache_hits} / $STATUS{Uptime};
  748. if (defined $last_time and $last_time != $now_time)
  749. {
  750. my $q_delta = $STATUS{Qcache_hits} - $OLD_STATUS{Qcache_hits};
  751. $now_query_cache_hits_per_sec = sprintf "%.2f", $q_delta / $t_delta;
  752. }
  753. }
  754. open L, "</proc/loadavg";
  755. my $l = <L>;
  756. close L;
  757. chomp $l;
  758. $last_time = $now_time;
  759. ## Server Uptime in meaningful terms...
  760. my $time = $STATUS{Uptime};
  761. my ($d,$h,$m,$s) = (0, 0, 0, 0);
  762. $d += int($time / (60*60*24)); $time -= $d * (60*60*24);
  763. $h += int($time / (60*60)); $time -= $h * (60*60);
  764. $m += int($time / (60)); $time -= $m * (60);
  765. $s += int($time);
  766. my $uptime = sprintf("%d+%02d:%02d:%02d", $d, $h, $m, $s);
  767. ## Queries per second...
  768. my $avg_queries_per_sec = sprintf("%.2f", $STATUS{Questions} / $STATUS{Uptime});
  769. my $num_queries = $STATUS{Questions};
  770. my @t = localtime(time);
  771. my $current_time = sprintf "[%02d:%02d:%02d]", $t[2], $t[1], $t[0];
  772. my $host_width = 50;
  773. my $up_width = $width - $host_width - 1;
  774. Clear() unless $config{batchmode};
  775. print RESET();
  776. printf "%-.${host_width}s %${up_width}s\n",
  777. "$server on $config{host} ($db_version)",
  778. "up $uptime $current_time";
  779. # "load $l up $uptime $current_time";
  780. $lines_left--;
  781. printf " Queries: %-6s qps: %4.0f Slow: %7s Se/In/Up/De(%%): %02.0f/%02.0f/%02.0f/%02.0f\n",
  782. make_short( $STATUS{Questions} ), # q total
  783. $STATUS{Questions} / $STATUS{Uptime}, # qps, average
  784. make_short( $STATUS{Slow_queries} ), # slow
  785. # hmm. a Qcache hit is really a select and should be counted.
  786. 100 * ($STATUS{Com_select} + ($STATUS{Qcache_hits}||0) ) / $STATUS{Questions},
  787. 100 * ($STATUS{Com_insert} + $STATUS{Com_replace} ) / $STATUS{Questions},
  788. 100 * ($STATUS{Com_update} ) / $STATUS{Questions},
  789. 100 * $STATUS{Com_delete} / $STATUS{Questions};
  790. $lines_left--;
  791. if ($t_delta)
  792. {
  793. my $q_diff = ( $STATUS{Questions} - $OLD_STATUS{Questions} );
  794. # print("q_diff: $STATUS{Questions} - $OLD_STATUS{Questions} / $t_delta = $q_diff\n");
  795. printf(" Sorts: %5.0f qps now: %4.0f Slow qps: %3.1f Threads: %4.0f (%4.0f/%4.0f) %02.0f/%02.0f/%02.0f/%02.0f\n",
  796. ( $STATUS{Sort_rows} - $OLD_STATUS{Sort_rows} ) / $t_delta,
  797. ( $STATUS{Questions} - $OLD_STATUS{Questions} ) / $t_delta,
  798. ( # slow now (qps)
  799. ($STATUS{Slow_queries} ) ?
  800. ( $STATUS{Slow_queries} - $OLD_STATUS{Slow_queries} ) / $t_delta :
  801. 0
  802. ),
  803. $STATUS{Threads_connected},
  804. $STATUS{Threads_running},
  805. $STATUS{Threads_cached},
  806. (100 * ($STATUS{Com_select} - $OLD_STATUS{Com_select} +
  807. ($STATUS{Qcache_hits}||0) - ($OLD_STATUS{Qcache_hits}||0)
  808. ) ) / ($q_diff ),
  809. (100 * ($STATUS{Com_insert} - $OLD_STATUS{Com_insert} +
  810. $STATUS{Com_replace} - $OLD_STATUS{Com_replace}
  811. ) ) / ($q_diff ),
  812. (100 * ($STATUS{Com_update} - $OLD_STATUS{Com_update}) ) / ($q_diff ),
  813. (100 * ($STATUS{Com_delete} - $OLD_STATUS{Com_delete}) ) / ($q_diff ),
  814. );
  815. }
  816. else
  817. {
  818. print "\n";
  819. }
  820. $lines_left--;
  821. if ($have_query_cache and $STATUS{Com_select} and $query_cache_hits)
  822. {
  823. printf(" Cache Hits: %-5s Hits/s: %4.1f Hits now: %5.1f Ratio: ",
  824. make_short($STATUS{Qcache_hits}), # cache hits
  825. $STATUS{Qcache_hits} / $STATUS{Uptime}, # hits / sec
  826. ($t_delta) ? ($STATUS{Qcache_hits} - $OLD_STATUS{Qcache_hits}) / $t_delta : 0, # Hits Now
  827. );
  828. my($Ratio) = 100 * ($STATUS{Qcache_hits}) / ($STATUS{Qcache_hits} + $STATUS{Com_select} );
  829. if ($HAS_COLOR)
  830. {
  831. print YELLOW() if ($Ratio < 80.0);
  832. print RED() if ($Ratio < 50.0);
  833. print MAGENTA() if ($Ratio < 20.0);
  834. }
  835. printf("%4.1f%% ",$Ratio);
  836. if ($HAS_COLOR)
  837. {
  838. print RESET();
  839. }
  840. print " Ratio now: ";
  841. my($Ratio_now) = ($t_delta) ? # ratio now
  842. 100 * ($STATUS{Qcache_hits} - $OLD_STATUS{Qcache_hits} ) /
  843. ( ($STATUS{Com_select} + $STATUS{Qcache_hits} -
  844. ($OLD_STATUS{Qcache_hits} + $OLD_STATUS{Com_select})
  845. ) || 1) : 0;
  846. if ($HAS_COLOR)
  847. {
  848. print GREEN() if ($Ratio_now >= 80.0);
  849. print YELLOW() if ($Ratio_now < 80.0);
  850. print RED() if ($Ratio_now < 50.0);
  851. print MAGENTA() if ($Ratio_now < 20.0);
  852. }
  853. printf("%4.1f%% \n",$Ratio_now);
  854. if ($HAS_COLOR)
  855. {
  856. print RESET();
  857. }
  858. }
  859. $lines_left--;
  860. if ($t_delta)
  861. {
  862. my $rows_read;
  863. if (defined($STATUS{Rows_read}))
  864. {
  865. $rows_read= $STATUS{Rows_read} - $OLD_STATUS{Rows_read};
  866. }
  867. else
  868. {
  869. $rows_read=
  870. ($STATUS{Handler_read_first}+$STATUS{Handler_read_key}+
  871. $STATUS{Handler_read_next}+$STATUS{Handler_read_prev}+
  872. $STATUS{Handler_read_rnd}+$STATUS{Handler_read_rnd_next} -
  873. $OLD_STATUS{Handler_read_first}-$OLD_STATUS{Handler_read_key}-
  874. $OLD_STATUS{Handler_read_next}-$OLD_STATUS{Handler_read_prev}-
  875. $OLD_STATUS{Handler_read_rnd}-
  876. $OLD_STATUS{Handler_read_rnd_next});
  877. }
  878. printf(" Handler: (R/W/U/D) %5d/%5d/%5d/%5d Tmp: R/W/U: %5d/%5d/%5d\n",
  879. $rows_read/$t_delta,
  880. ($STATUS{Handler_write} - $OLD_STATUS{Handler_write}) /
  881. $t_delta,
  882. ($STATUS{Handler_update} - $OLD_STATUS{Handler_update}) /
  883. $t_delta,
  884. ($STATUS{Handler_delete} - $OLD_STATUS{Handler_delete}) /
  885. $t_delta,
  886. ($STATUS{Rows_tmp_read} - $OLD_STATUS{Rows_tmp_read}) /
  887. $t_delta,
  888. ($STATUS{Handler_tmp_write}
  889. -$OLD_STATUS{Handler_tmp_write})/$t_delta,
  890. ($STATUS{Handler_tmp_update} -
  891. $OLD_STATUS{Handler_tmp_update})/$t_delta);
  892. }
  893. else
  894. {
  895. print "\n";
  896. }
  897. $lines_left--;
  898. printf(" ISAM Key Efficiency: %2.1f%% Bps in/out: %5s/%5s ",
  899. $cache_hits_percent,
  900. make_short($STATUS{Bytes_received} / $STATUS{Uptime} ),
  901. make_short($STATUS{Bytes_sent} / $STATUS{Uptime}));
  902. printf("Now in/out: %5s/%5s",
  903. make_short(($STATUS{Bytes_received} - $OLD_STATUS{Bytes_received}) / $t_delta ),
  904. make_short(($STATUS{Bytes_sent} - $OLD_STATUS{Bytes_sent}) / $t_delta ))
  905. if ($t_delta);
  906. print "\n";
  907. $lines_left--;
  908. my($data) = Hashes('show global variables like "read_only"');
  909. if ($data->{Value} ne "OFF")
  910. {
  911. print RED() if ($HAS_COLOR) ;
  912. print " ReadOnly";
  913. RESET() if ($HAS_COLOR);
  914. }
  915. ($data) = Hashes('SHOW SLAVE STATUS');
  916. if (defined($data->{Master_Host}))
  917. {
  918. if (defined($data->{Seconds_Behind_Master}))
  919. {
  920. if ($HAS_COLOR) {
  921. print GREEN();
  922. print YELLOW() if ($data->{Seconds_Behind_Master} > 60);
  923. print MAGENTA() if ($data->{Seconds_Behind_Master} > 360);
  924. }
  925. }
  926. print " Replication ";
  927. print "Master:$data->{Master_Host} ";
  928. print "IO:$data->{Slave_IO_Running} ";
  929. print "SQL:$data->{Slave_SQL_Running} ";
  930. print RESET() if ($HAS_COLOR);
  931. if (defined($data->{Seconds_Behind_Master}))
  932. {
  933. if ($HAS_COLOR) {
  934. print GREEN();
  935. print YELLOW() if ($data->{Seconds_Behind_Master} > 60);
  936. print MAGENTA() if ($data->{Seconds_Behind_Master} > 360);
  937. }
  938. print "Delay: $data->{Seconds_Behind_Master} sec.";
  939. } else {
  940. my $free = $width - 45;
  941. my $Err = substr $data->{Last_Error},0 ,$free;
  942. printf(" ERR: %-${free}s", $Err) if ( $Err ne "" );
  943. }
  944. print WHITE() if ($HAS_COLOR);
  945. print "\n";
  946. $lines_left--;
  947. }
  948. print "\n";
  949. }
  950. if (not $config{batchmode} and not $config{header})
  951. {
  952. Clear();
  953. print RESET();
  954. }
  955. ##
  956. ## Threads
  957. ##
  958. my @sz = (9, 8, 15, 9, 6, 5, 6, 8);
  959. my $used = scalar(@sz) + Sum(@sz);
  960. my $state= $width <= 80 ? 6 : int(min(6+($width-80)/3, 15));
  961. my $free = $width - $used - ($state - 6);
  962. my $format= "%9s %8s %15s %9s %6s %5s %6s %${state}s %-.${free}s\n";
  963. my $format2;
  964. if ($config{fullqueries})
  965. {
  966. $format2 = "%9d %8.8s %15.15s %9.9s %6d %5.1f %6.6s %${state}.${state}s %-${free}s\n";
  967. } else {
  968. $format2 = "%9d %8.8s %15.15s %9.9s %6d %5.1f %6.6s %${state}.${state}s %-${free}.${free}s\n";
  969. }
  970. print BOLD() if ($HAS_COLOR);
  971. printf $format,
  972. 'Id','User','Host/IP','DB','Time', '%', 'Cmd', 'State', 'Query';
  973. print RESET() if ($HAS_COLOR);
  974. ## Id User Host DB
  975. printf $format,
  976. '--','----','-------','--','----', '-', '---', '-----', '----------';
  977. $lines_left -= 2;
  978. my $proc_cmd = "show full processlist";
  979. my @data = Hashes($proc_cmd);
  980. foreach my $thread (@data)
  981. {
  982. last if not $lines_left;
  983. ## Drop Domain Name, unless it looks like an IP address. If
  984. ## it's an IP, we'll strip the port number because it's rarely
  985. ## interesting.
  986. my $is_ip = 0;
  987. if ($thread->{Host} =~ /^(\d{1,3}\.){3}(\d{1,3})(:\d+)?$/)
  988. {
  989. $thread->{Host} =~ s/:.*$//;
  990. $is_ip = 1;
  991. }
  992. else
  993. {
  994. $thread->{Host} =~ s/^([^.]+).*/$1/;
  995. }
  996. ## Otherwise, look up the IP (if resolve is set) and strip the
  997. ## name
  998. if ($is_ip and $config{resolve})
  999. {
  1000. $thread->{Host} =~ s/:\d+$//;
  1001. # my $host = $thread->{Host};
  1002. my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET);
  1003. # $host =~ s/^([^.]+).*/$1/;
  1004. $thread->{Host} = $host;
  1005. }
  1006. ## Fix possible undefs
  1007. $thread->{db} ||= '';
  1008. $thread->{Info} ||= '';
  1009. $thread->{Time} ||= 0 ;
  1010. $thread->{Id} ||= 0 ;
  1011. $thread->{User} ||= '';
  1012. $thread->{Command} ||= '';
  1013. $thread->{Host} ||= '';
  1014. $thread->{State} ||= "";
  1015. $thread->{Progress} ||= 0;
  1016. ## alter double hyphen comments so they don't break
  1017. ## the query when newlines are removed - http://freshmeat.net/users/jerjones
  1018. $thread->{Info} =~ s~\s--(.*)$~ /* $1 */ ~mg;
  1019. ## Normalize spaces -- mostly disabled for now. This can
  1020. ## break EXPLAIN if you try to explain a mangled query. It
  1021. ## may be re-enabled later as an option.
  1022. ## leading space removal
  1023. $thread->{Info} =~ s/^\s*//;
  1024. if (1)
  1025. {
  1026. ## remove newlines and carriage returns
  1027. $thread->{Info} =~ s/[\n\r]//g;
  1028. ## collpase whitespace
  1029. $thread->{Info} =~ s/\s+/ /g;
  1030. }
  1031. ## stow it in the cache
  1032. $qcache{$thread->{Id}} = $thread->{Info};
  1033. $dbcache{$thread->{Id}} = $thread->{db};
  1034. $ucache{$thread->{Id}} = $thread->{User};
  1035. }
  1036. ## Sort by idle time (closest thing to CPU usage I can think of).
  1037. my @sorted;
  1038. if (not $config{sort})
  1039. {
  1040. @sorted = sort { $a->{Time} <=> $b->{Time} } @data
  1041. }
  1042. else
  1043. {
  1044. @sorted = sort { $b->{Time} <=> $a->{Time} } @data
  1045. }
  1046. foreach my $thread (@sorted)
  1047. {
  1048. # Check to see if we can skip out. We skip out if we know the
  1049. # given line doesn't match.
  1050. next if (($thread->{Command} eq "Sleep")
  1051. and
  1052. (not $config{idle}));
  1053. next if (($thread->{Command} eq "Binlog Dump")
  1054. and
  1055. (not $config{idle}));
  1056. next if (($thread->{Command} eq "Daemon")
  1057. and
  1058. (not $config{idle}));
  1059. next if ($thread->{User} !~ $config{filter_user});
  1060. next if ($thread->{db} !~ $config{filter_db});
  1061. next if ($thread->{Host} !~ $config{filter_host});
  1062. next if ($thread->{State} !~ $config{filter_state});
  1063. # Otherwise, print.
  1064. my $smInfo;
  1065. if ($thread->{Info})
  1066. {
  1067. if ($config{fullqueries})
  1068. {
  1069. $smInfo = $thread->{Info};
  1070. } else {
  1071. $smInfo = substr $thread->{Info}, 0, $free;
  1072. }
  1073. }
  1074. # if ($thread->{State})
  1075. # {
  1076. # $smInfo = substr $thread->{State}, 0, $free;
  1077. # }
  1078. else
  1079. {
  1080. $smInfo = "";
  1081. }
  1082. if ($HAS_COLOR)
  1083. {
  1084. print YELLOW() if $thread->{Command} eq 'Query';
  1085. print WHITE() if $thread->{Command} eq 'Sleep';
  1086. print GREEN() if $thread->{Command} eq 'Connect';
  1087. print BOLD() if $thread->{Time} > $config{slow};
  1088. print MAGENTA() if $thread->{Time} > $config{long};
  1089. }
  1090. printf $format2,
  1091. $thread->{Id}, $thread->{User}, $thread->{Host}, $thread->{db},
  1092. $thread->{Time}, $thread->{Progress}, $thread->{Command}, $thread->{State}, $smInfo;
  1093. print RESET() if $HAS_COLOR;
  1094. $lines_left--;
  1095. last if $lines_left == 0;
  1096. }
  1097. }
  1098. ###########################################################################
  1099. my $questions;
  1100. sub GetQPS()
  1101. {
  1102. my($data) = Hashes('SHOW STATUS LIKE "Questions"');
  1103. my $num = $data->{Value};
  1104. if (not defined $questions) ## first time?
  1105. {
  1106. $questions = $num;
  1107. return;
  1108. }
  1109. my $qps = $num - $questions;
  1110. $questions = $num;
  1111. print "$qps\n";
  1112. }
  1113. ###########################################################################
  1114. sub GetQcacheSummary()
  1115. {
  1116. }
  1117. ###########################################################################
  1118. sub GetInnoDBStatus()
  1119. {
  1120. if (not $config{pager})
  1121. {
  1122. if (not $config{pager} = my_which('less'))
  1123. {
  1124. $config{pager} = my_which('more');
  1125. }
  1126. }
  1127. my @data = Hashes("SHOW INNODB STATUS");
  1128. open P, "|$config{pager}" or die "$!";
  1129. print keys %{$data[0]};
  1130. print $data[0]->{Status},"\n";
  1131. close P;
  1132. }
  1133. ###########################################################################
  1134. my %prev_data;
  1135. sub GetCmdSummary()
  1136. {
  1137. my ($width, $height, $wpx, $hpx, $lines_left);
  1138. if (not $config{batchmode})
  1139. {
  1140. ($width, $height, $wpx, $hpx) = GetTerminalSize();
  1141. $lines_left = $height - 2;
  1142. }
  1143. else
  1144. {
  1145. $height = 999_999; ## I hope you don't have more than that!
  1146. $lines_left = 999_999;
  1147. $width = 80;
  1148. }
  1149. # Variable_name and Value pairs come back...
  1150. my @data = Hashes("SHOW STATUS LIKE 'Com_%'");
  1151. my %cmd_data;
  1152. my %cmd_delta;
  1153. my %cmd_pct;
  1154. my %cmd_delta_pct;
  1155. my $total;
  1156. my $delta_total;
  1157. for my $item (@data)
  1158. {
  1159. next unless $item->{Value};
  1160. $item->{Variable_name} =~ s/^Com_//;
  1161. $item->{Variable_name} =~ s/_/ /g;
  1162. $cmd_data{$item->{Variable_name}} = $item->{Value};
  1163. $total += $item->{Value};
  1164. }
  1165. ## Populate other stats
  1166. for my $item (keys %cmd_data)
  1167. {
  1168. $cmd_delta{$item} = $cmd_data{$item} -
  1169. ($prev_data{$item} || $cmd_data{$item} - 1);
  1170. $delta_total += $cmd_delta{$item};
  1171. $cmd_pct{$item} = int(($cmd_data{$item} / $total) * 100);
  1172. }
  1173. for my $item (keys %cmd_data)
  1174. {
  1175. $cmd_delta_pct{$item} = int(($cmd_delta{$item} / $delta_total) * 100);
  1176. }
  1177. ## Display
  1178. Clear() unless $config{batchmode};
  1179. print RESET();
  1180. printf "%18s %10s %4s | %5s %4s\n", 'Command', 'Total', 'Pct', 'Last', 'Pct';
  1181. printf "%18s %10s %4s | %5s %4s\n", '-------', '-----', '---', '----', '---';
  1182. $lines_left -= 2;
  1183. for my $item (sort { $cmd_data{$b} <=> $cmd_data{$a} } keys %cmd_data)
  1184. {
  1185. printf "%18s %10d %4s | %5d %4s\n",
  1186. $item,
  1187. $cmd_data{$item},
  1188. $cmd_pct{$item} . "%",
  1189. $cmd_delta{$item},
  1190. $cmd_delta_pct{$item} . "%";
  1191. last if not $lines_left;
  1192. $lines_left -= 1;
  1193. }
  1194. %prev_data = %cmd_data;
  1195. }
  1196. ###########################################################################
  1197. sub GetShowVariables()
  1198. {
  1199. if (not $config{pager})
  1200. {
  1201. if (not $config{pager} = my_which('less'))
  1202. {
  1203. $config{pager} = my_which('more');
  1204. }
  1205. }
  1206. my @rows = Hashes("SHOW VARIABLES");
  1207. open P, "|$config{pager}" or die "$!";
  1208. for my $row (@rows)
  1209. {
  1210. my $name = $row->{Variable_name};
  1211. my $value = $row->{Value};
  1212. printf P "%32s: %s\n", $name, $value;
  1213. }
  1214. close P;
  1215. }
  1216. ###########################################################################
  1217. sub GetShowStatus()
  1218. {
  1219. Clear() unless $config{batchmode};
  1220. my @rows = Hashes("SHOW STATUS");
  1221. printf "%32s %10s %10s Toggle idle with 'i'\n", 'Counter', 'Total', 'Change';
  1222. printf "%32s %10s %10s\n", '-------', '-----', '------';
  1223. for my $row (@rows)
  1224. {
  1225. my $name = $row->{Variable_name};
  1226. my $value = $row->{Value};
  1227. my $old = $statcache{$name};
  1228. my $delta = 0;
  1229. next if $name =~ m/^Com_/; ## skip Com_ stats
  1230. next if $value =~ m/^[^0-9]*$/; ## skip non-numeric
  1231. ## TODO: if Qcache is off, we should skip Qcache_ values
  1232. if ($HAS_COLOR and defined $old and $old =~ /^\d/)
  1233. {
  1234. if ($value > $old)
  1235. {
  1236. print YELLOW();
  1237. $delta = $value - $old;
  1238. }
  1239. elsif ($value < $old)
  1240. {
  1241. print RED();
  1242. $delta = $value - $old;
  1243. }
  1244. if (not $config{idle} and $value == $old)
  1245. {
  1246. # filter unchanging stats, maybe
  1247. print RESET();
  1248. next;
  1249. }
  1250. }
  1251. printf "%32s: %10s %10s\n", $name, $value, $delta;
  1252. print RESET() if $HAS_COLOR;
  1253. $statcache{$name} = $value;
  1254. }
  1255. }
  1256. ###########################################################################
  1257. sub FullQueryInfo($)
  1258. {
  1259. my $id = shift;
  1260. if (not exists $qcache{$id} or not defined $qcache{$id})
  1261. {
  1262. print "*** Invalid id. ***\n";
  1263. return;
  1264. }
  1265. my $sql = $qcache{$id};
  1266. print $CLEAR;
  1267. print "Thread $id was executing following query:\n\n";
  1268. print YELLOW(), $sql,"\n\n", RESET();
  1269. }
  1270. ###########################################################################
  1271. sub Explain($)
  1272. {
  1273. my $id = shift;
  1274. if (not exists $qcache{$id} or not defined $qcache{$id})
  1275. {
  1276. print "*** Invalid id. ***\n";
  1277. return;
  1278. }
  1279. my $sql = $qcache{$id};
  1280. my $db = $dbcache{$id};
  1281. Execute("USE $db");
  1282. my @info = Hashes("EXPLAIN $sql");
  1283. print $CLEAR;
  1284. print "EXPLAIN $sql:\n\n";
  1285. PrintTable(@info);
  1286. }
  1287. ###########################################################################
  1288. sub PrintTable(@)
  1289. {
  1290. my $cnt = 1;
  1291. my @cols = qw(table type possible_keys key key_len ref rows Extra);
  1292. for my $row (@_)
  1293. {
  1294. print "*** row $cnt ***\n";
  1295. for my $key (@cols)
  1296. {
  1297. my $val = $row->{$key} || 'NULL';
  1298. printf "%15s: %s\n", $key, $val;
  1299. }
  1300. $cnt++;
  1301. }
  1302. }
  1303. ###########################################################################
  1304. sub StringOrRegex($)
  1305. {
  1306. my $input = shift;
  1307. chomp $input;
  1308. if (defined $input)
  1309. {
  1310. # regex, strip /.../ and use via qr//
  1311. if ($input =~ m{^/} and $input =~ m{/$})
  1312. {
  1313. $input =~ s{^/}{} if $config{filter_user};
  1314. $input =~ s{/$}{} if $config{filter_user};
  1315. $input = qr/$input/;
  1316. }
  1317. # reset to match anything
  1318. elsif ($input eq '')
  1319. {
  1320. $input = qr/.*/;
  1321. }
  1322. # string, build a simple regex
  1323. else
  1324. {
  1325. $input = '^' . $input . '$';
  1326. $input = qr/$input/;
  1327. }
  1328. }
  1329. # reset to match anything
  1330. else
  1331. {
  1332. $input = qr/.*/;
  1333. }
  1334. return $input;
  1335. }
  1336. ###########################################################################
  1337. sub cmd_l
  1338. {
  1339. ReadMode($RM_RESET);
  1340. print RED(), "Seconds for long queries: ", RESET();
  1341. my $secs = ReadLine(0);
  1342. if ($secs =~ /^\s*(\d+)/)
  1343. {
  1344. $config{long} = $1;
  1345. if ($config{long} < 1)
  1346. {
  1347. $config{long} = 1;
  1348. }
  1349. }
  1350. ReadMode($RM_NOBLKRD);
  1351. }
  1352. sub cmd_s
  1353. {
  1354. ReadMode($RM_RESET);
  1355. print RED(), "Seconds of Delay: ", RESET();
  1356. my $secs = ReadLine(0);
  1357. if ($secs =~ /^\s*(\d+)/)
  1358. {
  1359. $config{delay} = $1;
  1360. if ($config{delay} < 1)
  1361. {
  1362. $config{delay} = 1;
  1363. }
  1364. }
  1365. ReadMode($RM_NOBLKRD);
  1366. }
  1367. sub cmd_S
  1368. {
  1369. ReadMode($RM_RESET);
  1370. print RED(), "Seconds for Slow queries: ", RESET();
  1371. my $secs = ReadLine(0);
  1372. if ($secs =~ /^\s*(\d+)/)
  1373. {
  1374. $config{slow} = $1;
  1375. if ($config{slow} < 1)
  1376. {
  1377. $config{slow} = 1;
  1378. }
  1379. }
  1380. ReadMode($RM_NOBLKRD);
  1381. }
  1382. sub cmd_q
  1383. {
  1384. ReadMode($RM_RESET);
  1385. print "\n";
  1386. exit;
  1387. }
  1388. sub trim($)
  1389. {
  1390. my $string = shift;
  1391. $string =~ s/^\s+//;
  1392. $string =~ s/\s+$//;
  1393. return $string;
  1394. }
  1395. ###########################################################################
  1396. sub PrintHelp()
  1397. {
  1398. my $help = qq[
  1399. Help for mytop version $main::VERSION by Jeremy D. Zawodny <${YELLOW}Jeremy\@Zawodny.com${RESET}>
  1400. with updates by Mark Grennan <${YELLOW}mark\@grennan.com${RESET}>
  1401. ? - display this screen
  1402. # - toggle short/long numbers (not yet implemented)
  1403. c - command summary view (based on Com_* counters)
  1404. C - turn color on and off
  1405. d - show only a specific database
  1406. e - explain the query that a thread is running
  1407. E - display current replication error
  1408. f - show full query info for a given thread
  1409. F - unFilter the dispaly
  1410. h - show only a specifc host's connections
  1411. H - toggle the mytop header
  1412. i - toggle the display of idle (sleeping) threads
  1413. I - show innodb status
  1414. k - kill a thread
  1415. p - pause the display
  1416. l - change long running queries hightlighing
  1417. m - switch [mode] to qps (queries/sec) scrolling view
  1418. M - switch [mode] to status
  1419. o - reverse the sort order (toggle)
  1420. q - quit
  1421. r - reset the status counters (via FLUSH STATUS on your server)
  1422. R - change reverse IP lookup
  1423. s - change the delay between screen updates
  1424. S - change slow quiery hightlighting
  1425. t - switch to thread view (default)
  1426. u - show only a specific user
  1427. V - show variables
  1428. : - enter a command (not yet implemented)
  1429. ! - Skip an error that has stopped replications (at your own risk)
  1430. L - show full queries (do not strip to terminal width)
  1431. Base version from ${GREEN}http://www.mysqlfanboy.com/mytop${RESET}
  1432. This version comes as part of the ${GREEN}MariaDB${RESET} distribution.
  1433. ];
  1434. print $help;
  1435. }
  1436. sub Sum(@)
  1437. {
  1438. my $sum;
  1439. while (my $val = shift @_) { $sum += $val; }
  1440. return $sum;
  1441. }
  1442. ## A useful routine from perlfaq
  1443. sub commify($)
  1444. {
  1445. local $_ = shift;
  1446. return 0 unless defined $_;
  1447. 1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
  1448. return $_;
  1449. }
  1450. ## Compact numeric representation (10,000 -> 10.0k)
  1451. sub make_short($)
  1452. {
  1453. my $number = shift;
  1454. return commify($number) if $config{long_nums};
  1455. my $n = 0;
  1456. while ($number > 1_025) { $number /= 1024; $n++; };
  1457. return sprintf "%.1f%s", $number, ('','k','M','G', 'T')[$n];
  1458. }
  1459. ## Run a query and return the records has an array of hashes.
  1460. sub Hashes($)
  1461. {
  1462. my $sql = shift;
  1463. my @records;
  1464. if (my $sth = Execute($sql))
  1465. {
  1466. while (my $ref = $sth->fetchrow_hashref)
  1467. {
  1468. print "record\n" if $debug;
  1469. push @records, $ref;
  1470. }
  1471. }
  1472. return @records;
  1473. }
  1474. ## Execute an SQL query and return the statement handle.
  1475. sub Execute($)
  1476. {
  1477. my $sql = shift;
  1478. my $sth = $dbh->prepare($sql);
  1479. if (not $sth) { ReadMode($RM_RESET); die $DBI::errstr; }
  1480. my $ReturnCode = $sth->execute;
  1481. if (not $ReturnCode)
  1482. {
  1483. if ($debug)
  1484. {
  1485. print "query failed\n";
  1486. sleep 10;
  1487. }
  1488. return undef;
  1489. }
  1490. return $sth;
  1491. }
  1492. ####
  1493. #### my_which is used, because we can't assume that every system has the
  1494. #### which -command. my_which can take only one argument at a time.
  1495. #### Return values: requested system command with the first found path,
  1496. #### or undefined, if not found.
  1497. ####
  1498. sub my_which
  1499. {
  1500. my ($command) = @_;
  1501. my (@paths, $path);
  1502. return $command if (-f $command && -x $command);
  1503. # Check first if this is a source distribution, then if this binary
  1504. # distribution and last in the path
  1505. push @paths, "./extra";
  1506. push @paths, $path_for_script;
  1507. push @paths, split(':', $ENV{'PATH'});
  1508. foreach $path (@paths)
  1509. {
  1510. $path .= "/$command";
  1511. return $path if (-f $path && -x $path);
  1512. }
  1513. return undef();
  1514. }
  1515. =pod
  1516. =head1 SYNOPSIS
  1517. B<mytop> [options]
  1518. =head1 AVAILABILITY
  1519. Base version from B<http://www.mysqlfanboy.com/mytop>.
  1520. This version comes as part of the B<MariaDB> distribution. See B<http://mariadb.org/>.
  1521. And older (the original) version B<mytop> is available from
  1522. http://jeremy.zawodny.com/mysql/mytop/ it B<might> also be on CPAN as
  1523. well.
  1524. =head1 REQUIREMENTS
  1525. In order for B<mytop> to function properly, you must have the
  1526. following:
  1527. * Perl 5.005 or newer
  1528. * Getopt::Long
  1529. * DBI and DBD::mysql
  1530. * Term::ReadKey from CPAN
  1531. Most systems are likely to have all of those installed--except for
  1532. Term::ReadKey. You will need to pick that up from the CPAN. You can
  1533. pick up Term::ReadKey here:
  1534. http://search.cpan.org/search?dist=TermReadKey
  1535. And you obviously need access to a MariaDB server with the necessary
  1536. security to run the I<SHOW PROCESSLIST> and I<SHOW STATUS> commands.
  1537. If you are a Windows user, using ActiveState's Perl, you can use PPM
  1538. (the Perl Package Manager) to install the MariaDB/MySQL and Term::ReadKey
  1539. modules.
  1540. =head2 Optional Color Support
  1541. In additon, if you want a color B<mytop> (recommended), install
  1542. Term::ANSIColor from the CPAN:
  1543. http://search.cpan.org/search?dist=ANSIColor
  1544. Once you do, B<mytop> will automatically use it. However, color is not
  1545. yet working on Windows. Patches welcome. :-)
  1546. =head2 Optional Hi-Res Timing
  1547. If you want B<mytop> to provide more accurate real-time
  1548. queries-per-second statistics, install the Time::HiRes module from
  1549. CPAN. B<mytop> will automatically notice that you have it and use it
  1550. rather than the standard timing mechanism.
  1551. =head2 Platforms
  1552. B<mytop> is known to work on:
  1553. * Linux (2.2.x, 2.4.x)
  1554. * FreeBSD (2.2, 3.x, 4.x)
  1555. * Mac OS X
  1556. * BSDI 4.x
  1557. * Solaris 2.x
  1558. * Windows NT 4.x (ActivePerl)
  1559. If you find that it works on another platform, please let me
  1560. know. Given that it is all Perl code, I expect it to be rather
  1561. portable to Unix and Unix-like systems. Heck, it I<might> even work on
  1562. Win32 systems.
  1563. =head1 DESCRIPTION
  1564. Help is always welcome in improving this software. Feel free to
  1565. contact the author (see L<"AUTHOR"> below) with bug reports, fixes,
  1566. suggestions, and comments. Additionally L<"BUGS"> will provide a list
  1567. of things this software is not able to do yet.
  1568. Having said that, here are the details on how it works and what you can
  1569. do with it.
  1570. =head2 The Basics
  1571. B<mytop> was inspired by the system monitoring tool B<top>. I
  1572. routinely use B<top> on Linux, FreeBSD, and Solaris. You are likely to
  1573. notice features from each of them here.
  1574. B<mytop> will connect to a MariaDB server and periodically run the
  1575. I<SHOW PROCESSLIST> and I<SHOW STATUS> commands and attempt to
  1576. summarize the information from them in a useful format.
  1577. =head2 The Display
  1578. The B<mytop> display screen is really broken into two parts. The top 4
  1579. lines (header) contain summary information about your MariaDB
  1580. server. For example, you might see something like:
  1581. MariaDB on localhost (10.0.13-log) up 1+11:13:00 [23:29:11]
  1582. Queries: 19.3M qps: 160 Slow: 1.0 Se/In/Up/De(%): 00/80/03/17
  1583. qps now: 219 Slow qps: 0.0 Threads: 1 ( 1/ 16) 00/74/00/25
  1584. Key Efficiency: 99.3% Bps in/out: 30.5k/162.8 Now in/out: 32.7k/ 3.3k
  1585. The first line identifies the hostname of the server (localhost) and
  1586. the version of MariaDB it is running. The right had side shows the
  1587. uptime of the MariaDB server process in days+hours:minutes:seconds
  1588. format (much like FreeBSD's top) as well as the current time.
  1589. The second line displays the total number of queries the server has
  1590. processed, the average number of queries per second, the number of
  1591. slow queries, and the percentage of Select, Insert, Update, and Delete
  1592. queries.
  1593. The third real-time values. First is the number of queries per second,
  1594. then the number of slow queries, followed by query precentages (like
  1595. on the previous line).
  1596. And the fourth line displays key buffer efficiency (how often keys are
  1597. read from the buffer rather than disk) and the number of bytes that
  1598. MariaDB has sent and received, both over all and in the last cycle.
  1599. You can toggle the header by hitting B<h> when running B<mytop>.
  1600. The second part of the display lists as many threads as can fit on
  1601. screen. By default they are sorted according to their idle time (least
  1602. idle first). The display looks like:
  1603. Id User Host Dbase Time Cmd Query or State
  1604. -- ---- ---- ----- ---- --- --------------
  1605. 61 jzawodn localhost music 0 Query show processlist
  1606. As you can see, the thread id, username, host from which the user is
  1607. connecting, database to which the user is connected, number of seconds
  1608. of idle time, the command the thread is executing, and the query info
  1609. are all displayed.
  1610. Often times the query info is what you are really interested in, so it
  1611. is good to run B<mytop> in an xterm that is wider than the normal 80
  1612. columns if possible.
  1613. The thread display color-codes the threads if you have installed color
  1614. support. The current color scheme only works well in a window with a
  1615. dark (like black) background. The colors are selected according to the
  1616. C<Command> column of the display:
  1617. Query - Yellow
  1618. Sleep - White
  1619. Connect - Green
  1620. Slow - Bright
  1621. Long - Magenta
  1622. Those are purely arbitrary and will be customizable in a future
  1623. release. If they annoy you just start B<mytop> with the B<--nocolor>
  1624. flag or adjust your config file appropriately.
  1625. =head2 Arguments
  1626. B<mytop> handles long and short command-line arguments. Not all
  1627. options have both long and short formats, however. The long arguments
  1628. have two dashes `--'. Short arguments only have one '-'.
  1629. =over
  1630. =item B<-u> or B<-user> username
  1631. Username to use when logging in to the MariaDB server. Default: ``root''.
  1632. =item B<-p> or B<-pass> or B<-password> password
  1633. Password to use when logging in to the MariaDB server. Default: none.
  1634. =item B<-h> or B<--host> hostname[:port]
  1635. Hostname of the MariaDB server. The hostname may be followed by an
  1636. option port number. Note that the port is specified separate from the
  1637. host when using a config file. Default: ``localhost''.
  1638. =item B<--port> or B<-P> port
  1639. If you're running MariaDB on a non-standard port, use this to specify
  1640. the port number. Default: 3306.
  1641. =item B<-s> or B<--delay> seconds
  1642. How long between display refreshes. Default: 5
  1643. =item B<-d> or B<--db> or B<--database> database
  1644. Use if you'd like B<mytop> to connect to a specific database by
  1645. default. Default: ``test''.
  1646. =item B<-b> or B<--batch> or B<--batchmode>
  1647. In batch mode, mytop runs only once, does not clear the screen, and
  1648. places no limit on the number of lines it will print. This is suitable
  1649. for running periodically (perhaps from cron) to capture the
  1650. information into a file for later viewing. You might use batch mode in
  1651. a CGI script to occasionally display your MariaDB server status on the
  1652. web.
  1653. Default: unset.
  1654. =item B<-S> or B<--socket> /path/to/socket
  1655. If you're running B<mytop> on the same host as MariaDB, you may wish to
  1656. have it use the MariaDB socket directly rather than a standard TCP/IP
  1657. connection. If you do,just specify one.
  1658. Note that specifying a socket will make B<mytop> ignore any host
  1659. and/or port that you might have specified. If the socket does not
  1660. exist (or the file specified is not a socket), this option will be
  1661. ignored and B<mytop> will use the hostname and port number instead.
  1662. Default: none.
  1663. =item B<--header> or B<--noheader>
  1664. Sepcify if you want the header to display or not. You can toggle this
  1665. with the B<h> key while B<mytop> is running.
  1666. Default: header.
  1667. =item B<--color> or B<--nocolor>
  1668. Specify if you want a color display. This has no effect if you don't
  1669. have color support available.
  1670. Default: If you have color support, B<mytop> will try color unless you
  1671. tell it not to.
  1672. =item B<-i> or B<--idle> or B<--noi> or B<--noidle>
  1673. Specify if you want idle (sleeping) threads to appear in the list. If
  1674. sleeping threads are omitted, the default sorting order is reversed so
  1675. that the longest running queries appear at the top of the list.
  1676. Default: idle.
  1677. =item B<--prompt> or B<--noprompt>
  1678. Specify if you want to be prompted to type in your database password.
  1679. This provides a little bit more security since it not only prevents
  1680. the password from viewable in a process list, but also doesn't require
  1681. the password to be stored in plain text in your ~/.mytop config file.
  1682. You will B<only> be prompted if a password has not been specified in
  1683. your config file or through another command line option.
  1684. Default: noprompt.
  1685. =item B<--resolve>
  1686. If you have skip-resolve set on MariaDB (to keep it from doing a reverse
  1687. DNS lookup on each inbound connection), mytop can replace IP addresses
  1688. with hostnames but toggling this option.
  1689. Default: noresolve
  1690. =back
  1691. Command-line arguments will always take precedence over config file
  1692. options. That happens because the config file is read I<BEFORE> the
  1693. command-line arguments are applied.
  1694. =head2 Config File
  1695. Instead of always using bulky command-line parameters, you can also
  1696. use a config files for the default value of your options.
  1697. mytop will first read the [client] and [mytop] sections from your
  1698. my.cnf files. After that it will read the (C<~/.mytop>) file from your
  1699. home directory (if present). These are read I<before> any of your
  1700. command-line arguments are processed, so your command-line arguments
  1701. will override directives in the config file.
  1702. Here is a sample config file C<~/.mytop> which implements the defaults
  1703. described above.
  1704. user=root
  1705. pass=
  1706. host=localhost
  1707. db=test
  1708. delay=5
  1709. port=3306
  1710. slow=10
  1711. socket=
  1712. batchmode=0
  1713. header=1
  1714. color=1
  1715. idle=1
  1716. long=120
  1717. Using a config file will help to ensure that your database password
  1718. isn't visible to users on the command-line. Just make sure that the
  1719. permissions on C<~/.mytop> are such that others cannot read it (unless
  1720. you want them to, of course).
  1721. You may have white space on either side of the C<=> in lines of the
  1722. config file.
  1723. =head2 Shortcut Keys
  1724. The following keys perform various actions while B<mytop> is
  1725. running. Those which have not been implemented are listed as
  1726. such. They are included to give the user idea of what is coming.
  1727. =over
  1728. =item B<?>
  1729. Display help.
  1730. =item B<c>
  1731. Show "command counters" based on the Com_* values in SHOW STATUS.
  1732. This is a new feature. Feedback welcome.
  1733. =item B<C>
  1734. Turn display color on and off. Default is on.
  1735. =item B<d>
  1736. Show only threads connected to a particular database.
  1737. =item B<f>
  1738. Given a thread id, display the entire query that thread was (and still
  1739. may be) running.
  1740. =item B<F>
  1741. Disable all filtering (host, user, and db).
  1742. =item B<h>
  1743. Only show queries from a particular host.
  1744. =item B<H>
  1745. Toggle the header display. You can also specify either C<header=0> or
  1746. C<header=1> in your config file to set the default behavior.
  1747. =item B<i>
  1748. Toggle the display of idle (sleeping) threads. If sleeping threads are
  1749. filtered, the default sorting order is reversed so that the longest
  1750. running queries appear at the top of the list.
  1751. =item B<I>
  1752. Switch to InnoDB Status mode. The output of "SHOW INNODB STATUS" will
  1753. be displayed every cycle. In a future version, this may actually
  1754. summarize that data rather than producing raw output.
  1755. =item B<k>
  1756. Kill a thread.
  1757. =item B<m>
  1758. Toggle modes. Currently this switches from `top' mode to `qps'
  1759. (Queries Per Second Mode). In this mode, mytop will write out one
  1760. integer per second. The number written reflects the number of queries
  1761. executed by the server in the previous one second interval.
  1762. More modes may be added in the future.
  1763. =item B<o>
  1764. Reverse the default sort order.
  1765. =item B<p>
  1766. Pause display.
  1767. =item B<q>
  1768. Quit B<mytop>
  1769. =item B<r>
  1770. Reset the server's status counters via a I<FLUSH STATUS> command.
  1771. =item B<R>
  1772. Togle IP reverse lookup. Default is on.
  1773. =item B<s>
  1774. Change the sleep time (number of seconds between display refreshes).
  1775. =item B<S>
  1776. Set the number of seconds a query will need to run before it is
  1777. considered old and will be highlighted.
  1778. =item B<u>
  1779. Show only threads owned by a giver user.
  1780. =back
  1781. The B<s> key has a command-line counterpart: B<-s>.
  1782. The B<h> key has two command-line counterparts: B<-header> and
  1783. B<-noheader>.
  1784. =head1 BUGS
  1785. This is more of a BUGS + WishList.
  1786. Some performance information is not available when talking to a
  1787. version 3.22.x MySQL server. Additional information (about threads
  1788. mostly) was added to the output of I<SHOW STATUS> in MySQL 3.23.x and
  1789. B<mytop> makes use of it. If the information is not available, you
  1790. will simply see zeros where the real numbers should be.
  1791. Simply running this program will increase your overall counters (such
  1792. as the number of queries run). But you may or may not view that as a
  1793. bug.
  1794. B<mytop> consumes too much CPU time when running (verified on older
  1795. versions of Linux and FreeBSD). It's likely a problem related to
  1796. Term::ReadKey. I haven't had time to investigate yet, so B<mytop> now
  1797. automatically lowers its priority when you run it. You may also think
  1798. about running B<mytop> on another workstation instead of your database
  1799. server. However, C<mytop> on Solaris does B<not> have this problem.
  1800. Newer versions of Linux and FreeBSD seem to have fixed this.
  1801. You can't specify the maximum number of threads to list. If you have
  1802. many threads and a tall xterm, B<mytop> will always try to display as
  1803. many as it can fit.
  1804. The size of most of the columns in the display has a small maximum
  1805. width. If you have fairly long database/user/host names the display
  1806. may appear odd. I have no good idea as to how best to deal with that
  1807. yet. Suggestions are welcome.
  1808. It'd be nice if you could just add B<mytop> configuration directives
  1809. in your C<my.cnf> file instead of having a separate config file.
  1810. You should be able to specify the columns you'd like to see in the
  1811. display and the order in which they appear. If you only have one
  1812. username that connects to your database, it's probably not worth
  1813. having the User column appear, for example.
  1814. =head1 AUTHOR
  1815. mytop was developed and is maintained by Jeremy D. Zawodny
  1816. (Jeremy@Zawodny.com).
  1817. If you wish to e-mail me regarding this software, B<PLEASE> subscribe
  1818. to the B<mytop> mailing list. See the B<mytop> homepage for details.
  1819. =head1 DISCLAIMER
  1820. While I use this software in my job at Yahoo!, I am solely responsible
  1821. for it. Yahoo! does not necessarily support this software in any
  1822. way. It is merely a personal idea which happened to be very useful in
  1823. my job.
  1824. =head1 SEE ALSO
  1825. Please check the MySQL manual if you're not sure where some of the
  1826. output of B<mytop> is coming from.
  1827. =head1 COPYRIGHT
  1828. Copyright (C) 2000-2010, Jeremy D. Zawodny.
  1829. =head1 CREDITS
  1830. Fix a bug. Add a feature. See your name here!
  1831. Many thanks go to these fine folks:
  1832. =over
  1833. =Item Jean Weisbuch
  1834. Added --fullqueries and reading of .my.cnf
  1835. =item Mark Grennan (mark@grennan.com) www.linuxfangoy.com
  1836. Added updates for MySQL 5.x. Added 'S' (slow) highlighting.
  1837. Added 'C' to turn on and off Color. Added 'l' command to change
  1838. color for long running queries. Fixed a few documentation issues.
  1839. Monitors Slave status. Added color to Queue hit ratio.
  1840. Added number of rows sorted per second.
  1841. Created release 1.7.
  1842. =item Sami Ahlroos (sami@avis-net.de)
  1843. Suggested the idle/noidle stuff.
  1844. =item Jan Willamowius (jan@janhh.shnet.org)
  1845. Mirnor bug report. Documentation fixes.
  1846. =item Alex Osipov (alex@acky.net)
  1847. Long command-line options, Unix socket support.
  1848. =item Stephane Enten (tuf@grolier.fr)
  1849. Suggested batch mode.
  1850. =item Richard Ellerbrock (richarde@eskom.co.za)
  1851. Bug reports and usability suggestions.
  1852. =item William R. Mattil (wrm@newton.irngtx.tel.gte.com)
  1853. Bug report about empty passwords not working.
  1854. =item Benjamin Pflugmann (philemon@spin.de)
  1855. Suggested -P command-line flag as well as other changes.
  1856. =item Justin Mecham <justin@aspect.net>
  1857. Suggested setting $0 to `mytop'.
  1858. =item Thorsten Kunz <thorsten.kunz@de.tiscali.com>
  1859. Provided a fix for cases when we try remove the domain name from the
  1860. display even if it is actually an IP address.
  1861. =item Sasha Pachev <sasha@mysql.com>
  1862. Provided the idea of real-time queries per second in the main display.
  1863. =item Paul DuBois <paul@snake.net>
  1864. Pointed out some option-handling bugs.
  1865. =item Mike Wexler <mwexler@tias.com>
  1866. Suggested that we don't mangle (normalize) whitespace in query info by
  1867. default.
  1868. =item Mark Zweifel <markez@yahoo-inc.com>
  1869. Make the --idle command-line argument negatable.
  1870. =item Axel Schwenke <schwenke@jobpilot.de>
  1871. Noticed the inccorect formula for query cache hit percentages in
  1872. version 1.2.
  1873. =item Steven Roussey <sroussey@network54.com>
  1874. Supplied a patch to help filter binary junk in queries so that
  1875. terminals don't freak out.
  1876. =item jon r. luini <falcon@chime.com>
  1877. Supplied a patch that formed the basis for C<-prompt> support. Sean
  1878. Leach <sleach@wiggum.com> submitted a similar patch.
  1879. =item Yogish Baliga <baliga@yahoo-inc.com>
  1880. Supplied a patch that formed the basis for C<-resolve> support.
  1881. =item Per Andreas Buer <perbu@linpro.no>
  1882. Supplied an excellent patch to tidy up the top display. This includes
  1883. showing most values in short form, such as 10k rather than 10000.
  1884. =item Michael "Monty" Widenius <monty@askmonty.org>
  1885. Fixed a couple of minor bugs that gave warnings on startup.
  1886. Added support for MariaDB (show MariaDB at top and % done).
  1887. Cut long server version names to display width.
  1888. Made 'State' length dynamic.
  1889. =back
  1890. See the Changes file on the B<mytop> distribution page for more
  1891. details on what has changed.
  1892. =head1 LICENSE
  1893. B<mytop> is licensed under the GNU General Public License version
  1894. 2. For the full license information, please visit
  1895. http://www.gnu.org/copyleft/gpl.html
  1896. =cut
  1897. __END__