--- mysql-5.6.6.orig/include/my_sys.h   2012-04-09 20:05:16.000000000 +0800
+++ mysql-5.6.6.thread-mem-usage/include/my_sys.h       2012-04-26 21:13:58.000000000 +0800
@@ -150,6 +150,13 @@
 #define GETDATE_GMT            8
 #define GETDATE_FIXEDLENGTH    16
 
+/* Thread MEmory Usage By P.Linux */
+typedef void (*MALLOC_CB) (size_t size); 
+typedef void (*FREE_CB) (size_t size); 
+extern void set_malloc_cb(MALLOC_CB func);
+extern void set_free_cb(FREE_CB func); 
+/* End */
+
        /* defines when allocating data */
 extern void *my_malloc(size_t Size,myf MyFlags);
 extern void *my_multi_malloc(myf MyFlags, ...);
--- mysql-5.6.6.orig/mysys/my_malloc.c  2012-04-09 20:05:16.000000000 +0800
+++ mysql-5.6.6.thread-mem-usage/mysys/my_malloc.c      2012-04-27 10:15:58.000000000 +0800
@@ -17,6 +17,34 @@
 #include "mysys_err.h"
 #include <m_string.h>
 
+/* Thread Memory Usage By P.Linux */
+MALLOC_CB malloc_cb_func= NULL;
+FREE_CB free_cb_func= NULL;
+
+void static_add_malloc(size_t size)
+{
+  if (malloc_cb_func)
+    malloc_cb_func(size);
+}
+
+void set_malloc_cb(MALLOC_CB func)
+{
+  malloc_cb_func= func;
+}
+
+void static_del_free(size_t size)
+{
+  if (free_cb_func)
+    free_cb_func(size);
+}
+
+void set_free_cb(FREE_CB func)
+{
+  free_cb_func= func;
+}
+/* End */
+
+
 /**
   Allocate a sized block of memory.
 
@@ -56,6 +84,9 @@
   }
   else if (my_flags & MY_ZEROFILL)
     memset(point, 0, size);
+  /* Thread Memory Usage By P.Linux */
+  static_add_malloc(malloc_usable_size(point)); 
+  /* End */
   DBUG_PRINT("exit",("ptr: %p", point));
   DBUG_RETURN(point);
 }
@@ -127,6 +158,9 @@
 {
   DBUG_ENTER("my_free");
   DBUG_PRINT("my",("ptr: %p", ptr));
+  /* Thread Memory Usage By P.Linux */
+  static_del_free(malloc_usable_size(ptr)); 
+  /* End */
   free(ptr);
   DBUG_VOID_RETURN;
 }
--- mysql-5.6.6.orig/sql/sql_class.h    2012-04-09 20:05:16.000000000 +0800
+++ mysql-5.6.6.thread-mem-usage/sql/sql_class.h        2012-04-27 18:37:22.000000000 +0800
@@ -3954,9 +3954,12 @@
    */
   LEX_STRING invoker_user;
   LEX_STRING invoker_host;
+public:
+  /* Thread Mem Usage By P.Linux */
+  size_t malloc_size;
+  /* End*/
 };
 
-
 /** A short cut for thd->get_stmt_da()->set_ok_status(). */
 
 inline void
--- mysql-5.6.6.orig/sql/sql_show.cc    2012-04-09 20:05:16.000000000 +0800
+++ mysql-5.6.6.thread-mem-usage/sql/sql_show.cc        2012-04-26 23:37:35.000000000 +0800
@@ -2243,6 +2243,13 @@
       }
       mysql_mutex_unlock(&tmp->LOCK_thd_data);
 
+      /* Thread Memory Usage By P.Linux */
+      if (1) 
+      {
+        table->field[8]->store((longlong) (tmp->malloc_size + sizeof(THD)), TRUE);
+        table->field[8]->set_notnull();
+      }
+      /* End */
       if (schema_table_store_record(thd, table))
       {
         mysql_mutex_unlock(&LOCK_thread_count);
@@ -7766,6 +7773,7 @@
   {"STATE", 64, MYSQL_TYPE_STRING, 0, 1, "State", SKIP_OPEN_TABLE},
   {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info",
    SKIP_OPEN_TABLE},
+  {"MEM_USAGE", 7, MYSQL_TYPE_LONG, 0, 0, "Mem_Usage", SKIP_OPEN_TABLE},
   {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 };
 
--- mysql-5.6.6.orig/sql/mysqld.cc      2012-04-09 20:05:16.000000000 +0800
+++ mysql-5.6.6.thread-mem-usage/sql/mysqld.cc  2012-04-27 18:42:56.000000000 +0800
@@ -4741,6 +4741,26 @@
 }
 #endif//DBUG_OFF
 
+
+/* Thread Mem Usage By P.Linux */
+extern "C"
+void my_malloc_cb_func(size_t size)
+{
+  THD *thd= current_thd;
+  if (thd)
+    thd->malloc_size+= size;
+}
+
+extern "C"
+void my_free_cb_func(size_t size)
+{
+  THD *thd= current_thd;
+  if (thd)
+    thd->malloc_size-= size;
+}
+/* End */
+
+
 #ifdef __WIN__
 int win_main(int argc, char **argv)
 #else
@@ -4775,6 +4795,11 @@
   remaining_argc= argc;
   remaining_argv= argv;
 
+  /* Thread Memory Usage By P.Linux */
+  set_malloc_cb(my_malloc_cb_func);
+  set_free_cb(my_free_cb_func);
+  /* End */
+
   /* Must be initialized early for comparison of options name */
   system_charset_info= &my_charset_utf8_general_ci;
 