List:Internals« Previous MessageNext Message »
From:Alex Budovski Date:December 30 2009 8:12am
Subject:SHOW PROFILE CPU port for Windows.
View as plain text  
Hello,

Here is a small patch that ports SHOW PROFILE CPU to Windows.

Please let me know what you think.


Thanks,

Alex.


# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: abudovski@strippedgyoewb
# target_branch: lp:mysql-server/5.4
# testament_sha1: 0b0c6ed2acdaf32a27146f16836651cf5bad3ffd
# timestamp: 2009-12-23 11:41:55 +1100
# base_revision_id: k.long@stripped
# 
# Begin patch
=== modified file 'sql/sql_profile.cc'
--- sql/sql_profile.cc	2009-02-13 16:41:47 +0000
+++ sql/sql_profile.cc	2009-12-23 00:32:41 +0000
@@ -134,6 +134,20 @@
 #define RUSAGE_USEC(tv)  ((tv).tv_sec*1000*1000 + (tv).tv_usec)
 #define RUSAGE_DIFF_USEC(tv1, tv2) (RUSAGE_USEC((tv1))-RUSAGE_USEC((tv2)))
 
+#ifdef __WIN__
+// Adapted from "Programming Applications for Microsoft Windows".
+inline ULONGLONG FileTimeToQuadWord(FILETIME *ft)
+{
+  return (Int64ShllMod32(ft->dwHighDateTime, 32) | ft->dwLowDateTime);
+}
+
+
+// Get time difference between to FILETIME objects in seconds.
+inline double GetTimeDiffInSeconds(FILETIME *a, FILETIME *b)
+{
+  return ((FileTimeToQuadWord(a) - FileTimeToQuadWord(b)) / 1e7);
+}
+#endif
 
 PROF_MEASUREMENT::PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char
                                    *status_arg)
@@ -224,6 +238,9 @@
   time_usecs= (double) my_getsystime() / 10.0;  /* 1 sec was 1e7, now is 1e6 */
 #ifdef HAVE_GETRUSAGE
   getrusage(RUSAGE_SELF, &rusage);
+#elif defined(__WIN__)
+  FILETIME ftDummy;
+  GetProcessTimes(GetCurrentProcess(), &ftDummy, &ftDummy, &ftKernel, &ftUser);
 #endif
 }
 
@@ -593,6 +610,23 @@
       table->field[5]->store_decimal(&cpu_stime_decimal);
       table->field[4]->set_notnull();
       table->field[5]->set_notnull();
+#elif defined(__WIN__)
+      my_decimal cpu_utime_decimal, cpu_stime_decimal;
+
+      double2my_decimal(E_DEC_FATAL_ERROR,
+                        GetTimeDiffInSeconds(&entry->ftUser,
+                                             &previous->ftUser),
+                        &cpu_utime_decimal);
+      double2my_decimal(E_DEC_FATAL_ERROR,
+                        GetTimeDiffInSeconds(&entry->ftKernel,
+                                             &previous->ftKernel),
+                        &cpu_stime_decimal);
+
+      // Store the result.
+      table->field[4]->store_decimal(&cpu_utime_decimal);
+      table->field[5]->store_decimal(&cpu_stime_decimal);
+      table->field[4]->set_notnull();
+      table->field[5]->set_notnull();
 #else
       /* TODO: Add CPU-usage info for non-BSD systems */
 #endif

=== modified file 'sql/sql_profile.h'
--- sql/sql_profile.h	2007-12-14 13:57:37 +0000
+++ sql/sql_profile.h	2009-12-23 00:32:41 +0000
@@ -186,6 +186,8 @@
   char *status;
 #ifdef HAVE_GETRUSAGE
   struct rusage rusage;
+#elif defined(__WIN__)
+  FILETIME ftKernel, ftUser;
 #endif
 
   char *function;

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWcRrVisAArZ/gFAQBABZd///
f+/+ir////5gBvfe63oADI3YAAAOjDUhpGTTQNMQZGgBoGgAZAANNABqmU09QyaBoPSaPUAZAADQ
AAA0ANIkzU0yA0A00AAAGmgAAAABKmRTyImNT0RptQeppppoaAaDQyADTR6gBw00wQyGmmRkwgGm
gDCaNMmABA0EkggAJkCYjFPITEHpU/KG0jKD1P0ppoeTapDegD8yDHYOjSYFJyZzjw+UMSQVggOE
ngL9EJCIq2hVWIlI3Qyg26iu2EUKjM7dNmojNUTU0l5nARUJMDI+tkPLKVXm+yMnZ3kgiIiBCKh0
aMbZRSxfaNdK2tNE6EFVjUeXtFQNYm4ZecHBU8pVa5x6T5SFHwweo0DAf/NBI6kgjCmhCupSpSjQ
q11B0kjR2dc0nzXdRUwXaNgofwEFVLGIB9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/nPg5Dh5zskbQLLUTU5WTc6NBkGHnhSQXabib2kAyD0sT1B/BeLsOtW
KU4mvSRMrBNy5P2jVjnOczuXvnDrSb+Cw/CDKV6CreaTSnTgdJJl71qkb1CbPhedtYHVrFIqyBBB
x4tNm+vIDOFB2TLt/JPDqL/7cNq2oKRHmmWju0pFp5gMJmOCzo8zAnWqM7jq7HQqQUbC9kFRPyUh
Vl9jiw2GQ+GgjtP3qP1qEdCPEkLjevyNnJioYcwMM3aoswFAQjAXfIGMowMAwwo+UYrEmeSfApc7
uTe+jPy7mQugvPagoSIpgrTIWf1OJ9JsJKbFoH61SblonXl5Hj4ylpW2qxPgBucvNMHUvCW+dDmI
gwzKZGtyeo0Ht5iJxM+ooJ2sqFKwGscpXNlPYr5j+jfMBhWMbBKhAwatqfBFJUj3Jk4JeD1G/id6
nGEf3YrAyXrjx4BPFUB6yWygb17LJjrNgrLBujEVFpp7D8wMRETViT86+LLeAygjf2Max4skXzAa
VSYd7zFk+WacMDQdIEUdhHzN1Ynb6HhzcimgnY946gYrd3m81NLMO1czlCUaRzGP1UzcZPcOWRV8
EDjwEUhOOLvBamZp7jgPcMxWD2YoUUVkOSfWcVt1SYucMd2HqdIRilFwKCimYMIRSCDYE9q2FRy6
xavDSOZEEUfIPHwR8WLhbmJ2DHInhSWi9FSujuX+OxBSaLP1TLoGznnSY4G1ZiYpWn9KTMkUCOcu
ydZ3xykoHbhaokLzyAcjVJSOOZnPmcnuQONavNxDyNsVnhxzKvZBwMGD+LuSKcKEhiNasVg=
Thread
SHOW PROFILE CPU port for Windows.Alex Budovski30 Dec
  • Re: SHOW PROFILE CPU port for Windows.Lenz Grimmer4 Jan
    • Re: SHOW PROFILE CPU port for Windows.Alex Budovski5 Jan
    • Re: SHOW PROFILE CPU port for Windows.Reggie Burnett3 Feb
      • Re: SHOW PROFILE CPU port for Windows.Lenz Grimmer3 Feb