Added new fast timer support.

Summary:
This replaces the fast_timers we added in 5.1, using the timers which
are now included in upstream v5.6 for perfschema.

Initializes the timers, selects which one to use, points the global
"my_timer_now" function pointer to the correct timer, puts the stats
for that timer in the global struct "my_timer", and sets the new
SHOW STATUS variable "Timer_in_use" to indicate which was chosen.

Added my_timer_ok mtr test to confirm the timer chosen is not "None".

Added my_timer_good mtr test to confirm the timer chosen is millisecond
precision or better.

All timers are type ulonglong, and are stored in native timer units.

Provides my_timer_now() function pointer to get current time.

Provides my_timer_since(t) function to get time passed since time t,
automatically adjusted for the estimated timer overhead.

Provides my_timer_since_and_update(&t) function to get time passed
since time t, adjusted for the estimated timer overhead.  Also updates
t to the current time, skipping that overhead.  To count the time not
counted here, add my_timer.overhead for each call to this function.

Provides my_timer_to_seconds(t) function to convert native timer units
to seconds (including fractions, in a double) for the current timer.
Also adds _milliseconds and _microseconds versions of this.

Adds a new show variable type "SHOW_TIMER" which stores its value as
a 64-bit unsigned integer, in native timer units, but displays as a
double, in seconds, automatically converting it based on the current
timer's frequency.  Since this conversion is only done for display,
no precision is ever lost in the actual variable, but the variable is
still shown as seconds with a fractional component, just like doubles.

This is the base for all our various stats which require timers.

Test Plan:
Jenkins, including follow-up diff which use these.  All pass.

Reviewers: chip, mcallaghan

Reviewed By: chip
Port v5.1 Extra Stats: Basic Stats

Summary:
Improve InnoDB disk IO performance counters:
This renames variables used for InnoDB IO performance counters, cleans
up some of the code that updates the counters, displays aggregate
performance for all async requests in SHOW INNODB STATUS.

Report InnoDB fsync time in SHOW INNODB STATUS:
Report microseconds waiting for fsync or fdatasync in SHOW INNODB STATUS

Report time for synchronous IO requests in SHOW INNODB STATUS:
Time and report via SHOW INNODB STATUS number of synchronous IO requests
and the average time per call.

Report old IO requests in SHOW INNODB STATUS:
An old request is one that is in the IO request array for more than 2
seconds.

Refactor innodb IO performance counters to use a common struct

Report per-tablespace IO statistics in SHOW INNODB STATUS:
When innodb_file_per_table is used, each table uses a separate tablespace
and this feature then provides per-table IO stats. The results look like:
--------------
TABLESPACE I/O
--------------
write: ./ibdata1 564 requests, 0 old, 71316.88 bytes/r, svc: 0.91 secs, 1.62 msecs/r, 60.60 max msecs, wait: 33.05 secs 58.61 msecs/r, 60.60 max msecs
write: ./ib_logfile0 2098 requests, 0 old, 4458.65 bytes/r, svc: 3.13 secs, 1.49 msecs/r, 296.15 max msecs, wait: 3.58 secs 1.71 msecs/r, 296.15 max msecs

Added counters for number of pending and completed aio operations.

Brought over SHOW INNODB FILE STATUS from 5.0.84 and put the data into
the information_schema.innodb_file_status table.

Sample of the output follows:

+-------------------------------------+-----------+----------+-----+----------+------------------+----------+---------------------+---------------+-----------+---------------------+----------------+
| FILE | OPERATION | REQUESTS | OLD | BYTES | BYTES/R | SVC:SECS | SVC:MSECS/R | SVC:MAX_MSECS | WAIT:SECS | WAIT:MSECS/R | WAIT:MAX_MSECS |
+-------------------------------------+-----------+----------+-----+----------+------------------+----------+---------------------+---------------+-----------+---------------------+----------------+
| /data/mysql/ibdata1 | read | 320 | 0 | 7307264 | 22835.2 | 1.527591 | 4.773721875 | 17 | 1.527591 | 4.773721875 | 17 |
| /data/mysql/ibdata1 | write | 118 | 0 | 17367040 | 147178.305084746 | 0.052502 | 0.444932203389831 | 2 | 0.555864 | 4.71071186440678 | 4 |
| /data/mysql/ib_logfile0 | read | 6 | 0 | 69632 | 11605.3333333333 | 8.6e-05 | 0.0143333333333333 | 0 | 8.6e-05 | 0.0143333333333333 | 0 |
| /data/mysql/ib_logfile0 | write | 7466 | 0 | 9551360 | 1279.31422448433 | 0.046362 | 0.00620975087061345 | 0 | 0.047235 | 0.00632668095365658 | 0 |
| ./db7733/alerts_log.ibd | read | 217 | 0 | 3588096 | 16535.0046082949 | 1.34283 | 6.18815668202765 | 20 | 1.688229 | 7.77985714285714 | 76 |
| ./db7733/api_data.ibd | read | 93 | 0 | 1523712 | 16384 | 0.517229 | 5.56160215053763 | 14 | 0.517229 | 5.56160215053763 | 14 |
| ./db7733/api_data.ibd | write | 4 | 0 | 65536 | 16384 | 0.000575 | 0.14375 | 0 | 0.004231 | 1.05775 | 2 |
+-------------------------------------+-----------+----------+-----+----------+------------------+----------+---------------------+---------------+-----------+---------------------+----------------+

Changes:

Adapts those stats which used doubles for timing to use new my_timer.

Some of this is actually redundant with the new perfschema stuff.
However, I included it all anyway, so they can be compared.

Test Plan: Jenkins, 'arc unit' all tests passed.

Reviewers: rongrong, chip

Reviewed By: rongrong
Port v5.1 Extra Stats: BinLog BaseDirs

Summary:
Add global variables to list directory for binlog files and binlog index file.
The variables are binlog_file_basedir and binlog_index_basedir.

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: mutex and rw-lock

Summary:
Add mutex and rw-lock stats to SHOW STATUS.

Added counters for number of pending and completed aio operations.

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: InnoDB transaction logging

Summary:
Add more details from InnoDB transaction loggging to SHOW STATUS
and SHOW INNODB STATUS.  These are for performance debugging.

Test Plan: Jenkins

Reviewers: chip, jtolmer

Reviewed By: jtolmer
Port v5.1 Extra Stats: More buffer pool stats.

Summary:
Display more buffer pool status in SHOW INNODB STATUS:

For SHOW STATUS display Innodb_buffer_pool_pages_dirty_pct,
Innodb_buffer_pool_pages_flushed_lru, Innodb_buffer_pool_pages_flushed_list,
Innodb_buffer_pool_pages_flushed_page and Innodb_buffer_pool_pages_lru_old.

For SHOW INNODB STATUS display lines that start with
"Read ahead:", "Percent pages dirty:", "Pending writes:" and "Total writes:"

	Innodb_buffer_pool_pages_flushed_lru:
	Number of writes done for pages from the LRU list.

	Innodb_buffer_pool_pages_flushed_list:
	Number of writes done for pages from the flush list.

	Innodb_buffer_pool_pages_flushed_page:
	Number of writes done for other reasons.

	Innodb_buffer_pool_pages_lru_old:
	Number of old pages on the LRU list.

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: Command Timers

Summary:
Adds command, slave_command, pre-exec, parse, and execution timers.

This ports these timers from v5.1 to 5.6, using the new timers.

I also added an mtr test to confirm they are at least partly working.

Test Plan: Jenkins.  All tests, including the new one, pass.

Reviewers: chip

Reviewed By: chip
Port v5.1 Allow innodb_lock_wait_timeout=0

Summary:
Allow innodb_lock_wait_timeout=0, the previous min value was 1.
To see how it is used, read srv0srv.c
Add test innodb.innodb_lock_wait_timeout

Test Plan: Includes mtr test.  It passes.

Reviewers: chip, nizamordulu

Reviewed By: chip
Port v5.1 Extra Stats: records_in_range_seconds

Summary:
Added timer for time spent in innodb records_in_range, using new timers.

Test Plan:
Jenkins, plus:
show status like '%records_in_range_seconds';
Innodb_records_in_range_seconds 0.000000

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: callers of os_file_flush

Summary:
Report on the callers of os_file_flush in SHOW INNODB STATUS.
This is displayed in the TABLESPACE section as 'fsync callers:'
--------------
TABLESPACE I/O
--------------
fsync callers: 4 buffer pool, 1 other, 1 checkpoint, 11 log aio, 1622 log sync, 0 archive

Included range check added in follow-up diff.

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: IO Perf Counters

Summary:
Display more InnoDB IO performance counters in SHOW STATUS.

The counters are:

Innodb_data_fsync_seconds:
	Total seconds for fsync calls

Innodb_data_async_read_requests:
	Number of read requests from background IO threads

Innodb_data_async_read_bytes:
	Number of bytes read by background IO threads

Innodb_data_async_read_svc_seconds:
	Seconds for reads by background IO threads

Same as above, but for writes:
	Innodb_data_async_write_requests
	Innodb_data_async_write_bytes
	Innodb_data_async_write_svc_seconds

Same as above, but for requests not handled by the background IO threads:
	Innodb_data_sync_read_requests
	Innodb_data_sync_read_bytes
	Innodb_data_sync_read_svc_seconds
	Innodb_data_sync_write_requests
	Innodb_data_sync_write_bytes
	Innodb_data_sync_write_svc_seconds

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: Insert Buffer and Adaptive Hash

Summary:
Add insert buffer and adaptive hash stats to SHOW STATUS

Add these to SHOW STATUS:

Innodb_adaptive_hash_hits
	Adaptive hash search hits

Innodb_adaptive_hash_misses
	Adaptive hash search misses

Innodb_ibuf_merges
	Number of secondary index pages updated with merged records

Innodb_ibuf_inserts
	Number of records added to the insert buffer

Innodb_ibuf_delete_marks
	Number of records added to the delete mark buffer

Innodb_ibuf_deletes
	Number of records added to the delete buffer

Innodb_ibuf_size
	Size of the insert buffer in pages

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: Time Master Thread Tasks

Summary:
Add timers for work done by the master thread when active to SHOW STATUS
and SHOW INNODB STATUS.  Uses the new my_timer stuff.

All of this seems totally redundant with the new perfschema stuff.
However, I included it all anyway, so they can be compared.

Add these for SHOW STATUS:

Innodb_checkpoint_seconds
	seconds doing a checkpoint

Innodb_srv_drop_table_seconds
	seconds doing background table drop

Innodb_srv_free_log_seconds
	seconds checking log freespace

Innodb_srv_cache_limit_seconds
	seconds enforcing dict cache limit

Innodb_srv_log_flush_seconds
	seconds flushing logs

Innodb_srv_ibuf_contract_seconds
	seconds merging insert buffer entries

Innodb_srv_purge_seconds
	seconds running trx_purge() to remove deleted rows

Add this for SHOW INNODB STATUS:
-----------------
BACKGROUND THREAD
-----------------
Seconds in background IO: 0.00 insert buffer, 0.00 log flush, 0.00 purge, 0.00 cache limit, 0.00 free log, 0.00 drop table, 0.00 checkpoint

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 SysVar: innodb_deadlock_detect

Summary:
Add innodb_deadlock_detect to disable deadlock detection on row locks.

This is set to 1 by default.

When set to 0, row lock wait timeouts will break deadlocks.

This is done to avoid the performance hit from deadlock detection.

The detection code holds kernel_mutex when making checks which prevents
anything else from making progress.

Test Plan: Follow-up diff includes mtr using this, it passes.  Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: InnoDB Lock Status

Summary:
Add InnoDB lock status details to SHOW [INNODB] STATUS

Add these to SHOW STATUS:

Innodb_row_lock_deadlocks
	Number of transaction aborts from deadlock

Innodb_row_lock_wait_timeouts
	Number of transaction aborts from lock wait

Innodb_purge_pending
	Number of transactions for which purge must be done.
	This is already named 'History list length' in SHOW INNODB STATUS

Added to TRANSACTIONS section in SHOW INNODB STATUS:

	Lock stats: 0 deadlocks, 0 lock wait timeouts

Added the innodb_lock_status mtr test.

Test Plan: Includes mtr test - it passes.  Jenkins.

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: Remove Transactions

Summary:
Disable including transactions in SHOW INNODB STATUS.

Transactions are already visible in information_schema.innodb_trx.

This change removes them from the SHOW INNODB STATUS output in order
to keep the size managable.

It also removes the size limit on the output to avoid truncation.

Test Plan: mtr, Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: Flushed Neighbor Counters

Summary:
Add counters for flushed neighbor pages.

Innodb writes dirty pages from the same extent when one of the pages in
the extent is eligible to be written. This is done to reduce disk seeks.
The pages in the same extent are called neighbor pages.

Counters in SHOW STATUS are exported for this:

Innodb_buffer_pool_neighbors_flushed_from_list
	Number of neighbor pages flushed from the buffer pool flush list.

Innodb_buffer_pool_neighbors_flushed_from_lru
	Number of neighbor pages flushed from the buffer pool LRU list.

This is displayed in SHOW INNODB STATUS:
	Neighbor pages flushed: 644 from list, 0 from LRU

Test Plan: Jenkins.

Reviewers: chip

Reviewed By: chip
Port v5.1 Extra Stats: SHOW ENGINE INNODB TRANSACTION STATUS

Summary:
Add SHOW ENGINE InnoDB TRANSACTION STATUS.

Not all of the locking information is available in
information_schema.innodb_trx so I put in
SHOW InnoDB TRANSACTION STATUS like in 5.0.84.

I also updated the partition_innodb test to use the new
command (it checks some locking information).

Perfschema hard-coded the total number of classes into its test results
files, so they all then fail, since this adds a class of statement.
This updates that hard-coded number in all of these results files.

Test Plan: Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 SHOW STATUS tests

Summary:
Add tests for SHOW STATUS.

Ensures these commands work:
	SHOW STATUS
	SHOW ENGINE INNODB MUTEX
	SHOW ENGINE INNODB STATUS
	SHOW ENGINE INNODB TRANSACTION STATUS

Test Plan: Ran test, it passes.  Jenkins

Reviewers: chip

Reviewed By: chip
Port v5.1 Slow Query Log Changes

Summary:
MySQL 5.6's slow query log outputs the wrong timestamp time.
Instead of the start-of-query time, it outputs the end-of-query time.
This fixes that problem and tests for regressions.

Also adds more attributes to slow query log....
Query_time, Lock_time, Rows_sent and Rows_examined have always been there.
All others are new and improve performance debugging.
The new output is:
	# Query_time: 0  Lock_time: 0  Rows_sent: 0  Rows_examined: 0 \
	Thread_id: 3 Errno: 0 Killed: 0 Bytes_received: 110 \
	Bytes_sent: 134 Read_first: 0 Read_last: 0 Read_key: 2 \
	Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 \
	Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 \
	Sort_scan_count: 0 Created_tmp_disk_tables: 0 \
	Created_tmp_tables: 0 Start:  9:22:58 End:  9:22:58

Also, improves performance by moving some code out of the block in which
the log mutex is locked.

Test Plan: Jenkins (new tests included, pass without --record).

Reviewers: chip

Reviewed By: chip