--- mysql-5.0.75-clean/innobase/lock/lock0lock.c 2008-12-30 01:27:41.000000000 +0100 +++ mysql-5.0.75/innobase/lock/lock0lock.c 2008-12-30 02:25:38.000000000 +0100 @@ -363,6 +363,7 @@ /* Flags for recursive deadlock search */ #define LOCK_VICTIM_IS_START 1 #define LOCK_VICTIM_IS_OTHER 2 +#define trx_deadlock_counter 0 /************************************************************************ Checks if a lock request results in a deadlock. */ @@ -3206,6 +3207,7 @@ } lock_deadlock_found = TRUE; + srv_trx_deadlock_counter++; fputs("*** WE ROLL BACK TRANSACTION (2)\n", lock_latest_err_file); @@ -3368,7 +3370,8 @@ } lock_deadlock_found = TRUE; - + srv_trx_deadlock_counter++; + /* Let us choose the transaction of wait_lock as a victim to try to avoid deadlocking our recursion starting point transaction */ @@ -4238,6 +4241,11 @@ innobase_mysql_prepare_print_arbitrary_thd(); lock_mutex_enter_kernel(); + fprintf(file, + "------------------------\n" + "AMOUNT OF DEADLOCKS: %d\n" + "------------------------\n", srv_trx_deadlock_counter); + if (lock_deadlock_found) { fputs( "------------------------\n" --- mysql-5.0.75-clean/sql/ha_innodb.cc 2008-12-30 01:27:41.000000000 +0100 +++ mysql-5.0.75/sql/ha_innodb.cc 2008-12-30 02:20:33.000000000 +0100 @@ -324,6 +324,8 @@ (char*) &export_vars.innodb_rows_read, SHOW_LONG}, {"rows_updated", (char*) &export_vars.innodb_rows_updated, SHOW_LONG}, + {"trx_deadlocks", + (char*) &export_vars.innodb_trx_deadlocks, SHOW_LONG}, {NullS, NullS, SHOW_LONG}}; /* General functions */ --- mysql-5.0.75-clean/innobase/include/srv0srv.h 2008-12-30 01:27:41.000000000 +0100 +++ mysql-5.0.75/innobase/include/srv0srv.h 2008-12-30 02:29:12.000000000 +0100 @@ -563,6 +563,7 @@ ulint innodb_rows_inserted; ulint innodb_rows_updated; ulint innodb_rows_deleted; + ulint innodb_trx_deadlocks; }; /* The server system struct */ --- mysql-5.0.75-clean/innobase/srv/srv0srv.c 2008-12-30 01:27:41.000000000 +0100 +++ mysql-5.0.75/innobase/srv/srv0srv.c 2008-12-30 02:14:43.000000000 +0100 @@ -1,4 +1,4 @@ -/****************************************************** + /****************************************************** The database server main program NOTE: SQL Server 7 uses something which the documentation @@ -187,6 +187,9 @@ ulong srv_max_buf_pool_modified_pct = 90; +/* counting amount of deadlocks */ +ulint srv_trx_deadlock_counter = 0; + /* variable counts amount of data read in total (in bytes) */ ulint srv_data_read = 0; @@ -1836,6 +1839,7 @@ export_vars.innodb_rows_inserted= srv_n_rows_inserted; export_vars.innodb_rows_updated= srv_n_rows_updated; export_vars.innodb_rows_deleted= srv_n_rows_deleted; + export_vars.innodb_trx_deadlocks= srv_trx_deadlock_counter; mutex_exit(&srv_innodb_monitor_mutex); } --- mysql-5.0.75-clean/sql/ha_innodb.cc 2008-12-30 01:27:41.000000000 +0100 +++ mysql-5.0.75/sql/ha_innodb.cc 2008-12-30 02:20:33.000000000 +0100 @@ -324,6 +324,8 @@ (char*) &export_vars.innodb_rows_read, SHOW_LONG}, {"rows_updated", (char*) &export_vars.innodb_rows_updated, SHOW_LONG}, + {"trx_deadlocks", + (char*) &export_vars.innodb_trx_deadlocks, SHOW_LONG}, {NullS, NullS, SHOW_LONG}}; /* General functions */