| 1 |
/* |
| 2 |
Copyright (c) 2019, Percona LLC. |
| 3 |
All rights reserved. |
| 4 |
|
| 5 |
Redistribution and use in source and binary forms, with or without |
| 6 |
modification, are permitted provided that the following conditions are met: |
| 7 |
|
| 8 |
* Redistributions of source code must retain the above copyright notice, this |
| 9 |
list of conditions and the following disclaimer. |
| 10 |
|
| 11 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 12 |
this list of conditions and the following disclaimer in the documentation |
| 13 |
and/or other materials provided with the distribution. |
| 14 |
|
| 15 |
* Neither the name of the copyright holder nor the names of its |
| 16 |
contributors may be used to endorse or promote products derived from |
| 17 |
this software without specific prior written permission. |
| 18 |
|
| 19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 |
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 |
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 |
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 |
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
|
| 31 |
// Package event aggregates MySQL log and Perfomance Schema events into query |
| 32 |
// classes and calculates basic statistics for class metrics like max Query_time. |
| 33 |
// Event aggregation into query classes is the foundation of MySQL log file and |
| 34 |
// Performance Schema analysis. |
| 35 |
// |
| 36 |
// An event is a query like "SELECT col FROM t WHERE id = 1", some metrics like |
| 37 |
// Query_time (slow log) or SUM_TIMER_WAIT (Performance Schema), and other |
| 38 |
// metadata like default database, timestamp, etc. Events are grouped into query |
| 39 |
// classes by fingerprinting the query (see percona.com/go-mysql/query/), then |
| 40 |
// checksumming the fingerprint which yields a 16-character hexadecimal value |
| 41 |
// called the class ID. As events are added to a class, metric values are saved. |
| 42 |
// When there are no more events, the class is finalized to compute the statistics |
| 43 |
// for all metrics. |
| 44 |
// |
| 45 |
// There are two types of classes: global and per-query. A global class contains |
| 46 |
// all events added to it, regardless of fingerprint or class ID. This is used, |
| 47 |
// for example, to aggregate all events in a log file. A per-query class contains |
| 48 |
// events with the same fingerprint and class ID. This is only enforced by |
| 49 |
// convention, so be careful not to mix events from different classes. This is |
| 50 |
// used, for example, to aggregate unique queries in a log file, then sort the |
| 51 |
// classes by some metric, like max Query_time, to find the slowest query |
| 52 |
// relative to a global class for the same set of events. |
| 53 |
package event |