{"id":15512,"date":"2025-01-07T14:26:31","date_gmt":"2025-01-07T06:26:31","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=15512"},"modified":"2025-03-11T18:19:07","modified_gmt":"2025-03-11T10:19:07","slug":"kundb%e8%af%ad%e5%8f%a5%e4%ba%8b%e4%bb%b6%e8%a1%a8-timer_start-timer_end%e8%bd%ac%e6%8d%a2%e6%88%90%e6%a0%87%e5%87%86%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=15512","title":{"rendered":"Kundb\u8bed\u53e5\u4e8b\u4ef6\u8868 TIMER_START\/TIMER_END\u8f6c\u6362\u6210\u6807\u51c6\u65f6\u95f4"},"content":{"rendered":"<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<hr \/>\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\uff0c\u5982\u4f55\u5c06 <code>\u524d\u8bed\u53e5\u4e8b\u4ef6\u8868events_statements_current<\/code>\u3001<code>\u5386\u53f2\u8bed\u53e5\u4e8b\u4ef6\u8868events_statements_history<\/code>\u4e2d\u7684 <code>TIMER_START<\/code> \u548c <code>TIMER_END<\/code>\u8f6c\u6362\u6210\u6807\u51c6\u65f6\u95f4\u683c\u5f0f\u3002 <\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<hr \/>\n<p>TIMER_START \u548c TIMER_END \u5b57\u6bb5\u8868\u793a\u7684\u662f\u4e8b\u4ef6\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u95f4\u6233\uff0c\u4f46\u8fd9\u4e9b\u65f6\u95f4\u6233\u5e76\u4e0d\u662f\u4ee5\u5e38\u89c1\u7684\u65e5\u671f\u65f6\u95f4\u683c\u5f0f\u5b58\u50a8\u7684\u3002\u76f8\u53cd\uff0c\u5b83\u4eec\u662f\u4ee5\u67d0\u4e2a\u56fa\u5b9a\u65f6\u95f4\u70b9\uff08\u901a\u5e38\u662f\u670d\u52a1\u5668\u542f\u52a8\u65f6\u95f4\uff09\u4e3a\u57fa\u51c6\u7684\u76f8\u5bf9\u65f6\u95f4\u6233\u3002\u56e0\u6b64\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u8f6c\u6362\u624d\u80fd\u5c06\u8fd9\u4e9b\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u6807\u51c6\u7684\u65f6\u95f4\u683c\u5f0f\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5c06 TIMER_START \u8f6c\u6362\u4e3a\u6807\u51c6\u65f6\u95f4\u7684\u6b65\u9aa4\uff1a<\/p>\n<blockquote>\n<p>1.\u83b7\u53d6\u670d\u52a1\u5668\u7684\u542f\u52a8\u65f6\u95f4\uff1a\u4f60\u9700\u8981\u77e5\u9053 MySQL \u670d\u52a1\u5668\u7684\u542f\u52a8\u65f6\u95f4\uff0c\u56e0\u4e3a TIMER_START \u548c TIMER_END \u662f\u76f8\u5bf9\u4e8e\u8fd9\u4e2a\u65f6\u95f4\u7684\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u67e5\u8be2 <code>performance_schema.global_variables<\/code> \u8868\u4e2d\u7684 uptime \u53d8\u91cf\u6765\u83b7\u53d6\u670d\u52a1\u5668\u5df2\u7ecf\u8fd0\u884c\u7684\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\uff0c\u7136\u540e\u518d\u7ed3\u5408\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u6765\u63a8\u7b97\u542f\u52a8\u65f6\u95f4\u3002<br \/>\n2.\u8ba1\u7b97\u7edd\u5bf9\u65f6\u95f4\uff1a\u5c06 TIMER_START \u6216 TIMER_END \u8f6c\u6362\u4e3a\u76f8\u5bf9\u4e8e Unix epoch\uff081970-01-01 00:00:00 UTC\uff09\u7684\u7edd\u5bf9\u65f6\u95f4\u6233\u3002<br \/>\n3.\u683c\u5f0f\u5316\u4e3a\u6807\u51c6\u65f6\u95f4\uff1a\u4f7f\u7528 MySQL \u7684\u65e5\u671f\u65f6\u95f4\u51fd\u6570\u5c06\u7edd\u5bf9\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u53ef\u8bfb\u7684\u65f6\u95f4\u683c\u5f0f\u3002<\/p>\n<\/blockquote>\n<p><strong>\u4e0b\u9762\u63d0\u4f9b\u4e86\u4e24\u79cd\u51fd\u6570\u903b\u8f91<\/strong><\/p>\n<pre><code class=\"language-sql\">select   \nDATE_SUB(now(),INTERVAL(SELECT variable_value FROM performance_schema.global_status WHERE variable_name='UPTIME')-a.TIMER_START*10e-13 second) start_time1,\nDATE_SUB(now(),INTERVAL(SELECT variable_value FROM performance_schema.global_status WHERE variable_name='UPTIME')-a.TIMER_END*10e-13 second) end_time1\nFROM performance_schema.events_statements_history a ;<\/code><\/pre>\n<pre><code class=\"language-sql\">select   \nFROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-(SELECT variable_value FROM performance_schema.global_status WHERE variable_name='UPTIME') + (TIMER_START \/ 1000000000000)) AS start_time2,\nFROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-(SELECT variable_value FROM performance_schema.global_status WHERE variable_name='UPTIME') + (TIMER_END \/ 1000000000000)) AS end_time2\nFROM performance_schema.events_statements_history a ;<\/code><\/pre>\n<p><strong>\u6216\u8005\u53ef\u4ee5\u5199\u4e2afunction<\/strong><\/p>\n<pre><code class=\"language-sql\">create function lkw.f_convert_timer_to_utc(pi_timer bigint) returns timestamp(6) \nDETERMINISTIC \nbegin    \n    declare value_utc_time timestamp(6);    \n    select FROM_UNIXTIME( (unix_timestamp(sysdate()) - variable_value) + pi_timer\/1000000000000 )  from performance_schema.global_status where variable_name = 'Uptime' into value_utc_time;    \n    return value_utc_time; \nend;<\/code><\/pre>\n<p>\u4f7f\u7528\u7684\u65f6\u5019\u76f4\u63a5\u8c03\u7528\u5373\u53ef\uff1a<\/p>\n<pre><code class=\"language-sql\">select \n lkw.f_convert_timer_to_utc(TIMER_START) run_start_time,\n lkw.f_convert_timer_to_utc(TIMER_END) run_end_time\nfrom performance_schema.events_statements_history;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981\u63cf\u8ff0 \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\uff0c\u5982\u4f55\u5c06 \u524d\u8bed\u53e5\u4e8b\u4ef6\u8868events_statements_current\u3001\u5386\u53f2\u8bed\u53e5\u4e8b\u4ef6\u8868 ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=15512\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-15512","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15512"}],"version-history":[{"count":3,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15512\/revisions"}],"predecessor-version":[{"id":16086,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/15512\/revisions\/16086"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}