mirror of
https://github.com/MariaDB/server.git
synced 2025-08-09 22:24:09 +03:00
MDEV-8981: Analyze stmt - cycles can overflow
A 64bit counter can overflow within the time of a query so lets take it that the measurement is the small value rather than an order 1e12 millisecond query. tested with: int main() { ulonglong start = ULONGLONG_MAX - 30; ulonglong end = 600; ulonglong cycles = 10000; cycles += end - start; if (unlikely(end < start)) cycles += ULONGLONG_MAX; printf("cycles %llu\n", cycles); }
This commit is contained in:
@@ -47,6 +47,14 @@ protected:
|
|||||||
ulonglong count;
|
ulonglong count;
|
||||||
ulonglong cycles;
|
ulonglong cycles;
|
||||||
ulonglong last_start;
|
ulonglong last_start;
|
||||||
|
|
||||||
|
void cycles_stop_tracking()
|
||||||
|
{
|
||||||
|
ulonglong end= my_timer_cycles();
|
||||||
|
cycles += end - last_start;
|
||||||
|
if (unlikely(end < last_start))
|
||||||
|
cycles += ULONGLONG_MAX;
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
Exec_time_tracker() : count(0), cycles(0) {}
|
Exec_time_tracker() : count(0), cycles(0) {}
|
||||||
|
|
||||||
@@ -59,7 +67,7 @@ public:
|
|||||||
void stop_tracking()
|
void stop_tracking()
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
cycles += my_timer_cycles()- last_start;
|
cycles_stop_tracking();
|
||||||
}
|
}
|
||||||
|
|
||||||
// interface for getting the time
|
// interface for getting the time
|
||||||
@@ -93,7 +101,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void stop_tracking()
|
void stop_tracking()
|
||||||
{
|
{
|
||||||
cycles += my_timer_cycles()- last_start;
|
cycles_stop_tracking();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user