@@ -134,6 +134,26 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table)
134
134
#define RUSAGE_USEC (tv ) ((tv).tv_sec*1000 *1000 + (tv).tv_usec)
135
135
#define RUSAGE_DIFF_USEC (tv1, tv2 ) (RUSAGE_USEC((tv1))-RUSAGE_USEC((tv2)))
136
136
137
+ #ifdef _WIN32
138
+ static ULONGLONG FileTimeToQuadWord (FILETIME *ft)
139
+ {
140
+ // Overlay FILETIME onto a ULONGLONG.
141
+ union {
142
+ ULONGLONG qwTime;
143
+ FILETIME ft;
144
+ } u;
145
+
146
+ u.ft = *ft;
147
+ return u.qwTime ;
148
+ }
149
+
150
+
151
+ // Get time difference between to FILETIME objects in seconds.
152
+ static double GetTimeDiffInSeconds (FILETIME *a, FILETIME *b)
153
+ {
154
+ return ((FileTimeToQuadWord (a) - FileTimeToQuadWord (b)) / 1e7 );
155
+ }
156
+ #endif
137
157
138
158
PROF_MEASUREMENT::PROF_MEASUREMENT (QUERY_PROFILE *profile_arg, const char
139
159
*status_arg)
@@ -224,6 +244,12 @@ void PROF_MEASUREMENT::collect()
224
244
time_usecs= (double ) my_getsystime () / 10.0 ; /* 1 sec was 1e7, now is 1e6 */
225
245
#ifdef HAVE_GETRUSAGE
226
246
getrusage (RUSAGE_SELF, &rusage);
247
+ #elif defined(_WIN32)
248
+ FILETIME ftDummy;
249
+ // NOTE: Get{Process|Thread}Times has a granularity of the clock interval,
250
+ // which is typically ~15ms. So intervals shorter than that will not be
251
+ // measurable by this function.
252
+ GetProcessTimes (GetCurrentProcess (), &ftDummy, &ftDummy, &ftKernel, &ftUser);
227
253
#endif
228
254
}
229
255
@@ -589,6 +615,23 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
589
615
(1000.0 *1000 ),
590
616
&cpu_stime_decimal);
591
617
618
+ table->field [4 ]->store_decimal (&cpu_utime_decimal);
619
+ table->field [5 ]->store_decimal (&cpu_stime_decimal);
620
+ table->field [4 ]->set_notnull ();
621
+ table->field [5 ]->set_notnull ();
622
+ #elif defined(_WIN32)
623
+ my_decimal cpu_utime_decimal, cpu_stime_decimal;
624
+
625
+ double2my_decimal (E_DEC_FATAL_ERROR,
626
+ GetTimeDiffInSeconds (&entry->ftUser ,
627
+ &previous->ftUser ),
628
+ &cpu_utime_decimal);
629
+ double2my_decimal (E_DEC_FATAL_ERROR,
630
+ GetTimeDiffInSeconds (&entry->ftKernel ,
631
+ &previous->ftKernel ),
632
+ &cpu_stime_decimal);
633
+
634
+ // Store the result.
592
635
table->field [4 ]->store_decimal (&cpu_utime_decimal);
593
636
table->field [5 ]->store_decimal (&cpu_stime_decimal);
594
637
table->field [4 ]->set_notnull ();
0 commit comments