List:Commits« Previous MessageNext Message »
From:Marc Alff Date:May 24 2010 7:13am
Subject:bzr commit into mysql-next-mr branch (marc.alff:3146)
View as plain text  
#At file:///Users/malff/OLD_BZR_TREE/mysql-next-mr-bench/ based on revid:alik@stripped

 3146 Marc Alff	2010-05-24
      prototyping

    added:
      storage/perfschema/unittest/pfs_benchmark-t.cc
    modified:
      storage/perfschema/unittest/CMakeLists.txt
=== modified file 'storage/perfschema/unittest/CMakeLists.txt'
--- a/storage/perfschema/unittest/CMakeLists.txt	2010-01-14 18:42:28 +0000
+++ b/storage/perfschema/unittest/CMakeLists.txt	2010-05-24 07:13:14 +0000
@@ -35,6 +35,7 @@ SET(tests
  pfs_instr
  pfs_instr-oom
  pfs
+ pfs_benchmark
 )
 FOREACH(testname ${tests})
   PFS_ADD_TEST(${testname})

=== added file 'storage/perfschema/unittest/pfs_benchmark-t.cc'
--- a/storage/perfschema/unittest/pfs_benchmark-t.cc	1970-01-01 00:00:00 +0000
+++ b/storage/perfschema/unittest/pfs_benchmark-t.cc	2010-05-24 07:13:14 +0000
@@ -0,0 +1,194 @@
+/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include "my_global.h"
+#include "my_pthread.h"
+#include "pfs_timer.h"
+#include "pfs_server.h"
+#include "pfs_events_waits.h"
+#include "pfs_instr_class.h"
+#include "mysql/psi/psi.h"
+#include "mysql/psi/mysql_thread.h"
+#include "my_sys.h"
+#include "tap.h"
+
+static PFS_mutex_class *bench_mutex_class= NULL;
+static mysql_mutex_t bench_mutex;
+static PSI_mutex_key bench_mutex_key;
+PSI_mutex_info all_bench_mutexes[]=
+{
+  { & bench_mutex_key, "benchmark", 0}
+};
+static PSI_thread_key key_thread_main;
+static PSI_thread_info all_bench_threads[]=
+{
+  { & key_thread_main, "main", 0}
+};
+
+static void setup()
+{
+  PFS_global_param param;
+  param.m_enabled= true;
+  param.m_mutex_class_sizing= 10;
+  param.m_rwlock_class_sizing= 10;
+  param.m_cond_class_sizing= 10;
+  param.m_thread_class_sizing= 10;
+  param.m_table_share_sizing= 10;
+  param.m_file_class_sizing= 10;
+  param.m_mutex_sizing= 10;
+  param.m_rwlock_sizing= 10;
+  param.m_cond_sizing= 10;
+  param.m_thread_sizing= 10;
+  param.m_table_sizing= 10;
+  param.m_file_sizing= 10;
+  param.m_file_handle_sizing= 10;
+  param.m_events_waits_history_sizing= 10;
+  param.m_events_waits_history_long_sizing= 1000;
+
+  PSI_bootstrap *boot;
+  boot= initialize_performance_schema(& param);
+  ok(boot != NULL, "boot");
+  ok(boot->get_interface != NULL, "boot->get_interface");
+
+  PSI_server= (PSI*) boot->get_interface(PSI_CURRENT_VERSION);
+  ok(PSI_server != NULL, "current version");
+
+  PSI_server->register_mutex("unittest", all_bench_mutexes, 1);
+  PSI_server->register_thread("unittest", all_bench_threads, 1);
+
+  PSI_thread *psi= PSI_server->new_thread(key_thread_main, NULL, 0);
+  ok(psi != NULL, "main thread");
+  PSI_server->set_thread(psi);
+
+  mysql_mutex_init(bench_mutex_key, & bench_mutex, MY_MUTEX_INIT_FAST);
+  bench_mutex_class= find_mutex_class(bench_mutex_key);
+  ok(bench_mutex_class != NULL, "mutex class");
+}
+
+static void teardown()
+{
+  mysql_mutex_destroy(& bench_mutex);
+  shutdown_performance_schema();
+}
+
+void benchmark_mutex(bool timed, uint count, const char *test)
+{
+  ulonglong timer_start;
+  ulonglong timer_end;
+  ulonglong timer_cycles;
+  
+  mysql_mutex_t *that= & bench_mutex;
+
+  timer_start= get_timer_value(TIMER_NAME_CYCLE);
+
+  uint i;
+  for (i= 0 ; i<count; i++)
+  {
+    /* MYSQL_MUTEX_LOCK */
+    {
+      int result;
+      struct PSI_mutex_locker *locker= NULL;
+      if (likely(PSI_server && that->m_psi))
+      {
+        locker= PSI_server->get_thread_mutex_locker(that->m_psi, PSI_MUTEX_LOCK);
+        if (likely(locker != NULL))
+          PSI_server->start_mutex_wait(locker, __FILE__, __LINE__);
+      }
+      result= 0;
+      if (likely(locker != NULL))
+        PSI_server->end_mutex_wait(locker, result);
+    }
+
+    /* MYSQL_MUTEX_UNLOCK */    
+    {
+      struct PSI_thread *thread;
+      if (likely(PSI_server && that->m_psi))
+      {
+        thread= PSI_server->get_thread();
+        if (likely(thread != NULL))
+          PSI_server->unlock_mutex(thread, that->m_psi);
+      }
+    }
+  }
+
+  timer_end= get_timer_value(TIMER_NAME_CYCLE);
+  timer_cycles= timer_end-timer_start;
+
+  diag("MUTEX benchmark: %s (%s), %d calls, %13llu cycles, %13llu avg",
+       test, (timed ? "timed" : "counted"),
+       count, timer_cycles, timer_cycles/count);
+}
+
+void test_mutexes(bool timed)
+{
+  flag_events_waits_current= true;
+  flag_events_waits_history= true;
+  flag_events_waits_history_long= true;
+  flag_events_waits_summary_by_thread_by_event_name= true;
+  flag_events_waits_summary_by_event_name= true;
+  flag_events_waits_summary_by_instance= true;
+  flag_file_summary_by_event_name= true;
+  flag_file_summary_by_instance= true;
+
+  bench_mutex_class->m_timed= timed;
+
+  benchmark_mutex(timed, 1, "bigbang");
+  benchmark_mutex(timed, 1000, "bigbang");
+  benchmark_mutex(timed, 1000000, "bigbang");
+  benchmark_mutex(timed, 10000000, "bigbang");
+
+  flag_events_waits_history= false;
+  flag_events_waits_history_long= false;
+
+  benchmark_mutex(timed, 1, "no history");
+  benchmark_mutex(timed, 1000, "no history");
+  benchmark_mutex(timed, 1000000, "no history");
+  benchmark_mutex(timed, 10000000, "no history");
+
+  flag_events_waits_summary_by_thread_by_event_name= false;
+  flag_events_waits_summary_by_event_name= false;
+  flag_events_waits_summary_by_instance= false;
+  flag_file_summary_by_event_name= false;
+  flag_file_summary_by_instance= false;
+
+  benchmark_mutex(timed, 1, "current");
+  benchmark_mutex(timed, 1000, "current");
+  benchmark_mutex(timed, 1000000, "current");
+  benchmark_mutex(timed, 10000000, "current");
+
+  flag_events_waits_current= false;
+
+  benchmark_mutex(timed, 1, "nothing");
+  benchmark_mutex(timed, 1000, "nothing");
+  benchmark_mutex(timed, 1000000, "nothing");
+  benchmark_mutex(timed, 10000000, "nothing");
+}
+
+void do_all_tests()
+{
+  test_mutexes(true);
+  test_mutexes(false);
+}
+
+int main(int, char **)
+{
+  plan(5);
+  MY_INIT("pfs_benchmark-t");
+  setup();
+  do_all_tests();
+  teardown();
+  return 0;
+}
+


Attachment: [text/bzr-bundle] bzr/marc.alff@oracle.com-20100524071314-twglszhpfhw7dlqm.bundle
Thread
bzr commit into mysql-next-mr branch (marc.alff:3146) Marc Alff24 May