diff options
author | Daniel Black <grooverdan@users.sourceforge.net> | 2015-10-23 23:23:36 +1100 |
---|---|---|
committer | Daniel Black <grooverdan@users.sourceforge.net> | 2015-10-24 11:45:21 +1100 |
commit | 0b8144a4728e357965b2e3027535148870f0d0fd (patch) | |
tree | 5cd7cb48c7f9986d5bbc8efcb900f00b828d86ae /sql/sql_analyze_stmt.h | |
parent | 8a09280dc17c40c398c4c023108d70395b1ba0b6 (diff) | |
download | mariadb-git-0b8144a4728e357965b2e3027535148870f0d0fd.tar.gz |
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);
}
Diffstat (limited to 'sql/sql_analyze_stmt.h')
-rw-r--r-- | sql/sql_analyze_stmt.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sql/sql_analyze_stmt.h b/sql/sql_analyze_stmt.h index bf800fd1df6..d7634bdfb85 100644 --- a/sql/sql_analyze_stmt.h +++ b/sql/sql_analyze_stmt.h @@ -47,6 +47,14 @@ protected: ulonglong count; ulonglong cycles; 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: Exec_time_tracker() : count(0), cycles(0) {} @@ -59,7 +67,7 @@ public: void stop_tracking() { count++; - cycles += my_timer_cycles()- last_start; + cycles_stop_tracking(); } // interface for getting the time @@ -93,7 +101,7 @@ public: */ void stop_tracking() { - cycles += my_timer_cycles()- last_start; + cycles_stop_tracking(); } }; |