コード例 #1
0
ファイル: sb_threads.c プロジェクト: YannNayn/galera-msvc
int threads_init(void)
{
  thread_yields = sb_get_value_int("thread-yields");
  thread_locks = sb_get_value_int("thread-locks");
  req_performed = 0;
  
  return 0;
}
コード例 #2
0
ファイル: drv_mysql.c プロジェクト: Byronlee/linux_shell
int mysql_drv_init(void)
{
  char *s;
  
  args.hosts = sb_get_value_list("mysql-host");
  if (SB_LIST_IS_EMPTY(args.hosts))
  {
    log_text(LOG_FATAL, "No MySQL hosts specified, aborting");
    return 1;
  }
  hosts_pos = args.hosts;
  pthread_mutex_init(&hosts_mutex, NULL);
  
  args.port = sb_get_value_int("mysql-port");
  args.socket = sb_get_value_string("mysql-socket");
  args.user = sb_get_value_string("mysql-user");
  args.password = sb_get_value_string("mysql-password");
  args.db = sb_get_value_string("mysql-db");
  args.myisam_max_rows = sb_get_value_int("myisam-max-rows");
  args.use_ssl = sb_get_value_flag("mysql-ssl");
  args.create_options = sb_get_value_string("mysql-create-options");
  if (args.create_options == NULL)
    args.create_options = "";
  
  use_ps = 0;
#ifdef HAVE_PS
  mysql_drv_caps.prepared_statements = 1;
  if (db_globals.ps_mode != DB_PS_MODE_DISABLE)
    use_ps = 1;
#endif

  s = sb_get_value_string("mysql-engine-trx");
  if (s == NULL)
  {
    log_text(LOG_FATAL, "--mysql-engine-trx requires an argument");
    return 1;
  }
  if (!strcasecmp(s, "yes"))
    args.engine_trx = ENGINE_TRX_YES;
  else if (!strcasecmp(s, "no"))
    args.engine_trx = ENGINE_TRX_NO;
  else if (!strcasecmp(s, "auto"))
    args.engine_trx = ENGINE_TRX_AUTO;
  else
  {
    log_text(LOG_FATAL, "Invalid value for mysql-engine-trx: %s", s);
    return 1;
  }
  
  s = sb_get_value_string("mysql-table-engine");

  mysql_library_init(0, NULL, NULL);
  
  return parse_table_engine(s);
}
コード例 #3
0
ファイル: sb_fileio.c プロジェクト: Licenser/sysbench
int file_async_init(void)
{
  unsigned int i;

  if (file_io_mode != FILE_IO_MODE_ASYNC)
    return 0;
  
  file_async_backlog = sb_get_value_int("file-async-backlog");
  if (file_async_backlog <= 0) {
    log_text(LOG_FATAL, "Invalid value of file-async-backlog: %d",
             file_async_backlog);
    return 1;
  }

  aio_ctxts = (sb_aio_context_t *)calloc(sb_globals.num_threads,
                                         sizeof(sb_aio_context_t));
  for (i = 0; i < sb_globals.num_threads; i++)
  {
    if (io_queue_init(file_async_backlog, &aio_ctxts[i].io_ctxt))
    {
      log_errno(LOG_FATAL, "io_queue_init() failed!");
      return 1;
    }
      
    aio_ctxts[i].events = (struct io_event *)malloc(file_async_backlog *
                                                    sizeof(struct io_event));
    if (aio_ctxts[i].events == NULL)
    {
      log_errno(LOG_FATAL, "Failed to allocate async I/O context!");
      return 1;
    }
  }

  return 0;
}
コード例 #4
0
ファイル: sb_mutex.c プロジェクト: Alibaba-boonya/oceanbase
int mutex_init(void)
{
  unsigned int i;
  
  mutex_num = sb_get_value_int("mutex-num");
  mutex_loops = sb_get_value_int("mutex-loops");
  mutex_locks = sb_get_value_int("mutex-locks");

  thread_locks = (thread_lock *)malloc(mutex_num * sizeof(thread_lock));
  if (thread_locks == NULL)
  {
    log_text(LOG_FATAL, "Memory allocation failure!");
    return 1;
  }

  for (i = 0; i < mutex_num; i++)
    pthread_mutex_init(&thread_locks[i].mutex, NULL);
  
  return 0;
}
コード例 #5
0
ファイル: sb_cpu.c プロジェクト: bcliu430/Xen_Scripts
int cpu_init(void)
{
  int prime_option= sb_get_value_int("cpu-max-prime");
  if (prime_option <= 0)
  {
    log_text(LOG_FATAL, "Invalid value of cpu-max-prime: %d.", prime_option);
    return 1;
  }
  max_prime= (unsigned int)prime_option;

  req_performed = 0;

  return 0;
}
コード例 #6
0
ファイル: drv_attachsql.c プロジェクト: libattachsql/sysbench
int attachsql_drv_init(void)
{
  args.hosts = sb_get_value_list("attachsql-host");
  if (SB_LIST_IS_EMPTY(args.hosts))
  {
    log_text(LOG_FATAL, "No libAttachSQL hosts specified, aborting");
    return 1;
  }
  hosts_pos = args.hosts;
  pthread_mutex_init(&hosts_mutex, NULL);
  
  args.port = (unsigned int)sb_get_value_int("attachsql-port");
  args.socket = sb_get_value_string("attachsql-socket");
  args.user = sb_get_value_string("attachsql-user");
  args.password = sb_get_value_string("attachsql-password");
  args.db = sb_get_value_string("attachsql-db");
  attachsql_library_init();
  return 0;
}
コード例 #7
0
ファイル: sb_fileio.c プロジェクト: Licenser/sysbench
int parse_arguments(void)
{
  char         *mode;
  
  num_files = sb_get_value_int("file-num");

  if (num_files <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-num: %d", num_files);
    return 1;
  }
  total_size = sb_get_value_size("file-total-size");
  if (total_size <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-total-size: %lld",
             (long long)total_size);
    return 1;
  }
  file_size = total_size / num_files;
  
  mode = sb_get_value_string("file-test-mode");

  /* File test mode is necessary only for 'run' command */
  if (sb_globals.command == SB_COMMAND_RUN)
  {
    if (mode == NULL)
    {
      log_text(LOG_FATAL, "Missing required argument: --file-test-mode");
      sb_print_options(fileio_args);
      return 1;
    }
    if (!strcmp(mode, "seqwr"))
      test_mode = MODE_WRITE;
    else if (!strcmp(mode, "seqrewr"))
      test_mode = MODE_REWRITE;
    else if (!strcmp(mode, "seqrd"))
      test_mode = MODE_READ;
    else if (!strcmp(mode, "rndrd"))
      test_mode = MODE_RND_READ;
    else if (!strcmp(mode, "rndwr"))
      test_mode = MODE_RND_WRITE;
    else if (!strcmp(mode, "ag4"))
      test_mode = MODE_AG4_WRITE;
    else if (!strcmp(mode, "rndrw"))
      test_mode = MODE_RND_RW;
    else
    {
      log_text(LOG_FATAL, "Invalid IO operations mode: %s.", mode);
      return 1;
    }
  }
  
  mode  = sb_get_value_string("file-io-mode");
  if (mode == NULL)
    mode = "sync";
  if (!strcmp(mode, "sync"))
    file_io_mode = FILE_IO_MODE_SYNC;
  else if (!strcmp(mode, "async"))
  {
#ifdef HAVE_LIBAIO
    file_io_mode = FILE_IO_MODE_ASYNC;
#else
    log_text(LOG_FATAL,
             "asynchronous I/O mode is unsupported on this platform.");
    return 1;
#endif
  }
  else if (!strcmp(mode, "mmap"))
  {
#ifdef HAVE_MMAP
    file_io_mode = FILE_IO_MODE_MMAP;
#else
    log_text(LOG_FATAL,
             "mmap'ed I/O mode is unsupported on this platform.");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "unknown I/O mode: %s", mode);
    return 1;
  }
  
  file_merged_requests = sb_get_value_int("file-merged-requests");
  if (file_merged_requests < 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-merged-requests: %d.",
             file_merged_requests);
    return 1;
  }
  
  file_block_size = sb_get_value_size("file-block-size");
  if (file_block_size <= 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-block-size: %d.",
             file_block_size);
    return 1;
  }

  if (file_merged_requests > 0)
    file_max_request_size = file_block_size * file_merged_requests;
  else
    file_max_request_size = file_block_size;

  mode = sb_get_value_string("file-extra-flags");
  if (mode == NULL || !strlen(mode))
    file_extra_flags = 0;
  else if (!strcmp(mode, "sync"))
  {
#ifdef _WIN32
    file_extra_flags = FILE_FLAG_WRITE_THROUGH;
#else
    file_extra_flags = O_SYNC;
#endif
  }
  else if (!strcmp(mode, "dsync"))
  {
#ifdef O_DSYNC
    file_extra_flags = O_DSYNC;
#else
    log_text(LOG_FATAL, "O_DSYNC is not supported on this platform.");
    return 1;
#endif
  }
  else if (!strcmp(mode, "direct"))
  {
#ifdef _WIN32
    file_extra_flags = FILE_FLAG_NO_BUFFERING;
#elif defined(O_DIRECT)
    file_extra_flags = O_DIRECT;
#else
    log_text(LOG_FATAL, "O_DIRECT is not supported on this platform.");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "Invalid value for file-extra-flags: %s", mode);
    return 1;
  }
  
  file_fsync_freq = sb_get_value_int("file-fsync-freq");
  if (file_fsync_freq < 0)
  {
    log_text(LOG_FATAL, "Invalid value for file-fsync-freq: %d.",
             file_fsync_freq);
    return 1;
  }

  file_fsync_end = sb_get_value_flag("file-fsync-end");
  file_fsync_all = sb_get_value_flag("file-fsync-all");
  /* file-fsync-all overrides file-fsync-end and file-fsync-freq */
  if (file_fsync_all) {
    file_fsync_end = 0;
    file_fsync_freq = 0;
  }
  
  mode = sb_get_value_string("file-fsync-mode");
  if (!strcmp(mode, "fsync"))
    file_fsync_mode = FSYNC_ALL;
  else if (!strcmp(mode, "fdatasync"))
  {
#ifdef HAVE_FDATASYNC
    file_fsync_mode = FSYNC_DATA;
#else
    log_text(LOG_FATAL, "fdatasync() is unavailable on this platform");
    return 1;
#endif
  }
  else
  {
    log_text(LOG_FATAL, "Invalid fsync mode: %s.", mode);
    return 1;
  }

  file_rw_ratio = sb_get_value_float("file-rw-ratio");
  if (file_rw_ratio < 0)
  {
    log_text(LOG_FATAL, "Invalid value file file-rw-ratio: %f.", file_rw_ratio);
    return 1;
  }

  buffer = sb_memalign(file_max_request_size);

  return 0;
}
コード例 #8
0
ファイル: sb_mutex.c プロジェクト: Percona-QA/toku-qa
int mutex_init(void)
{
  unsigned int i;
  char *mutex_type_str;
  pthread_mutexattr_t mutex_attr;
 
  mutex_num = sb_get_value_int("mutex-num");
  mutex_loops = sb_get_value_int("mutex-loops");
  mutex_locks = sb_get_value_int("mutex-locks");
  mutex_type_str = sb_get_value_string("mutex-type");

  if (mutex_type_str == NULL)
  {
    log_text(LOG_FATAL, "Invalid value for --mutex-type");
    return 1;
  } 
  else if (!strcasecmp(mutex_type_str, "mutex"))
  {
    mutex_type = SB_MUTEX;
  }
  else if (!strcasecmp(mutex_type_str, "mutex-adaptive"))
  {
    mutex_type = SB_MUTEX_ADAPTIVE;
  }
  else if (!strcasecmp(mutex_type_str, "rwlock-read"))
  {
    mutex_type = SB_RWLOCK_READ;
  }
  else if (!strcasecmp(mutex_type_str, "rwlock-write"))
  {
    mutex_type = SB_RWLOCK_WRITE;
  }
  else
  {
    log_text(LOG_FATAL, "Invalid value for --mutex-type");
    return 1;
  }

  thread_locks = (thread_lock *)malloc(mutex_num * sizeof(thread_lock));
  if (thread_locks == NULL)
  {
    log_text(LOG_FATAL, "Memory allocation failure!");
    return 1;
  }

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
  pthread_mutexattr_init(&mutex_attr);
  pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ADAPTIVE_NP);
#else
  if (mutex_type == SB_MUTEX_ADAPTIVE)
  {
    log_text(LOG_FATAL, "Platform does not support mutex-adaptive");
    return 1;
  }
#endif

  for (i = 0; i < mutex_num; i++)
  {
    switch (mutex_type)
    {
      case SB_MUTEX:
        pthread_mutex_init(&thread_locks[i].mutex, NULL);
        break;
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
      case SB_MUTEX_ADAPTIVE:
        pthread_mutex_init(&thread_locks[i].mutex, &mutex_attr);
        break;
#endif
      case SB_RWLOCK_READ:
      case SB_RWLOCK_WRITE:
        pthread_rwlock_init(&thread_locks[i].rwlock, NULL);
        break;
    }
  }
  
  return 0;
}