~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2010-11-02 18:22:00 UTC
  • mfrom: (1897.2.3 merge)
  • Revision ID: brian@tangent.org-20101102182200-7wlu3j0ckb6invtj
Rollup of slap, and pbms

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
#include "stats.h"
79
79
#include "thread_context.h"
80
80
#include "conclusions.h"
 
81
#include "wakeup.h"
81
82
 
82
83
#include <signal.h>
83
84
#include <stdarg.h>
94
95
#include <iostream>
95
96
#include <fstream>
96
97
#include <drizzled/configmake.h>
 
98
 
97
99
/* Added this for string translation. */
98
100
#include <drizzled/gettext.h>
99
101
 
120
122
uint32_t thread_counter;
121
123
boost::mutex counter_mutex;
122
124
boost::condition_variable_any count_threshhold;
123
 
bool master_wakeup;
124
 
boost::mutex sleeper_mutex;
125
 
boost::condition_variable_any sleep_threshhold;
 
125
 
 
126
client::Wakeup master_wakeup;
126
127
 
127
128
/* Global Thread timer */
128
129
static bool timer_alarm= false;
169
170
  num_char_cols_opt,
170
171
  num_int_cols_opt;
171
172
string opt_label;
172
 
static unsigned int opt_set_random_seed;
 
173
static uint32_t opt_set_random_seed;
173
174
 
174
175
string auto_generate_selected_columns_opt;
175
176
 
176
177
/* Yes, we do set defaults here */
177
 
static unsigned int num_int_cols= 1;
178
 
static unsigned int num_char_cols= 1;
179
 
static unsigned int num_blob_cols= 0;
180
 
static unsigned int num_blob_cols_size;
181
 
static unsigned int num_blob_cols_size_min;
182
 
static unsigned int num_int_cols_index= 0;
183
 
static unsigned int num_char_cols_index= 0;
 
178
static uint32_t num_int_cols= 1;
 
179
static uint32_t num_char_cols= 1;
 
180
static uint32_t num_blob_cols= 0;
 
181
static uint32_t num_blob_cols_size;
 
182
static uint32_t num_blob_cols_size_min;
 
183
static uint32_t num_int_cols_index= 0;
 
184
static uint32_t num_char_cols_index= 0;
184
185
static uint32_t iterations;
185
186
static uint64_t actual_queries= 0;
186
187
static uint64_t auto_actual_queries;
193
194
string create_string;
194
195
std::vector <uint32_t> concurrency;
195
196
 
196
 
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
197
197
std::string opt_csv_str;
198
198
int csv_file;
199
199
 
207
207
static Statement *create_statements= NULL;
208
208
 
209
209
static std::vector <Statement *> query_statements;
210
 
static unsigned int query_statements_count;
 
210
static uint32_t query_statements_count;
211
211
 
212
212
 
213
213
/* Prototypes */
214
 
void print_conclusions(Conclusions *con);
215
 
void print_conclusions_csv(Conclusions *con);
 
214
void print_conclusions(Conclusions &con);
 
215
void print_conclusions_csv(Conclusions &con);
216
216
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr);
217
217
uint32_t parse_comma(const char *string, std::vector <uint32_t> &range);
218
218
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm);
219
219
uint32_t parse_option(const char *origin, OptionString **stmt, char delm);
220
 
static int drop_schema(drizzle_con_st *con, const char *db);
 
220
static void drop_schema(drizzle_con_st &con, const char *db);
221
221
uint32_t get_random_string(char *buf, size_t size);
222
222
static Statement *build_table_string(void);
223
223
static Statement *build_insert_string(void);
224
224
static Statement *build_update_string(void);
225
225
static Statement * build_select_string(bool key);
226
 
static int generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt);
227
 
static int create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
228
 
                         OptionString *engine_stmt, Stats *sptr);
229
 
static int run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur,
230
 
                         uint64_t limit);
 
226
static int generate_primary_key_list(drizzle_con_st &con, OptionString *engine_stmt);
 
227
static void create_schema(drizzle_con_st &con, const char *db, Statement *stmt, OptionString *engine_stmt, Stats *sptr);
 
228
static void run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit);
231
229
void statement_cleanup(Statement *stmt);
232
230
void option_cleanup(OptionString *stmt);
233
 
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr);
234
 
static int run_statements(drizzle_con_st *con, Statement *stmt);
235
 
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
236
 
void slap_close(drizzle_con_st *con);
237
 
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
238
 
void standard_deviation (Conclusions *con, Stats *sptr);
 
231
void concurrency_loop(drizzle_con_st &con, uint32_t current, OptionString *eptr);
 
232
static void run_statements(drizzle_con_st &con, Statement *stmt);
 
233
void slap_connect(drizzle_con_st &con, bool connect_to_schema);
 
234
void slap_close(drizzle_con_st &con);
 
235
static int run_query(drizzle_con_st &con, drizzle_result_st *result, const char *query, int len);
 
236
void standard_deviation(Conclusions &con, Stats *sptr);
239
237
 
240
238
static const char ALPHANUMERICS[]=
241
239
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
271
269
{
272
270
  uint64_t counter= 0, queries;
273
271
  uint64_t detach_counter;
274
 
  unsigned int commit_counter;
 
272
  uint32_t commit_counter;
275
273
  drizzle_con_st con;
276
274
  drizzle_result_st result;
277
275
  drizzle_row_t row;
278
276
  Statement *ptr;
279
277
 
280
 
  sleeper_mutex.lock();
281
 
  while (master_wakeup)
282
 
  {
283
 
    sleep_threshhold.wait(sleeper_mutex);
284
 
  }
285
 
  sleeper_mutex.unlock();
 
278
  master_wakeup.wait();
286
279
 
287
 
  slap_connect(&con, true);
 
280
  slap_connect(con, true);
288
281
 
289
282
  if (verbose >= 3)
290
283
    printf("connected!\n");
292
285
 
293
286
  commit_counter= 0;
294
287
  if (commit_rate)
295
 
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
288
    run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
296
289
 
297
290
limit_not_met:
298
291
  for (ptr= ctx->getStmt(), detach_counter= 0;
299
292
       ptr && ptr->getLength();
300
293
       ptr= ptr->getNext(), detach_counter++)
301
294
  {
302
 
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
295
    if (not opt_only_print && detach_rate && !(detach_counter % detach_rate))
303
296
    {
304
 
      slap_close(&con);
305
 
      slap_connect(&con, true);
 
297
      slap_close(con);
 
298
      slap_connect(con, true);
306
299
    }
307
300
 
308
301
    /*
312
305
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
313
306
    {
314
307
      int length;
315
 
      unsigned int key_val;
 
308
      uint32_t key_val;
316
309
      char buffer[HUGE_STRING_LENGTH];
317
310
 
318
311
      /*
325
318
      assert(primary_keys.size());
326
319
      if (primary_keys.size())
327
320
      {
328
 
        key_val= (unsigned int)(random() % primary_keys.size());
 
321
        key_val= (uint32_t)(random() % primary_keys.size());
329
322
        const char *key;
330
323
        key= primary_keys[key_val].c_str();
331
324
 
334
327
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
335
328
                         (int)ptr->getLength(), ptr->getString(), key);
336
329
 
337
 
        if (run_query(&con, &result, buffer, length))
 
330
        if (run_query(con, &result, buffer, length))
338
331
        {
339
332
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
340
333
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
341
 
          exit(1);
 
334
          abort();
342
335
        }
343
336
      }
344
337
    }
345
338
    else
346
339
    {
347
 
      if (run_query(&con, &result, ptr->getString(), ptr->getLength()))
 
340
      if (run_query(con, &result, ptr->getString(), ptr->getLength()))
348
341
      {
349
342
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
350
343
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
351
 
        exit(1);
 
344
        abort();
352
345
      }
353
346
    }
354
347
 
355
 
    if (!opt_only_print)
 
348
    if (not opt_only_print)
356
349
    {
357
350
      while ((row = drizzle_row_next(&result)))
358
351
        counter++;
363
356
    if (commit_rate && (++commit_counter == commit_rate))
364
357
    {
365
358
      commit_counter= 0;
366
 
      run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
359
      run_query(con, NULL, "COMMIT", strlen("COMMIT"));
367
360
    }
368
361
 
369
362
    /* If the timer is set, and the alarm is not active then end */
384
377
 
385
378
end:
386
379
  if (commit_rate)
387
 
    run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
380
    run_query(con, NULL, "COMMIT", strlen("COMMIT"));
388
381
 
389
 
  slap_close(&con);
 
382
  slap_close(con);
390
383
 
391
384
  {
392
385
    boost::mutex::scoped_lock scopedLock(counter_mutex);
571
564
    po::notify(vm);
572
565
 
573
566
    if (process_options())
574
 
      exit(1);
 
567
      abort();
575
568
 
576
569
    if ( vm.count("help") || vm.count("info"))
577
570
    {
584
577
           "license\n");
585
578
      puts("Run a query multiple times against the server\n");
586
579
      cout << long_options << endl;
587
 
      exit(0);
 
580
      abort();
588
581
    }   
589
582
 
590
583
    if (vm.count("protocol"))
599
592
      else
600
593
      {
601
594
        cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
602
 
        exit(-1);
 
595
        abort();
603
596
      }
604
597
    }
605
598
    if (vm.count("port")) 
609
602
      if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
610
603
      {
611
604
        fprintf(stderr, _("Value supplied for port is not valid.\n"));
612
 
        exit(1);
 
605
        abort();
613
606
      }
614
607
      else
615
608
      {
619
612
 
620
613
  if ( vm.count("password") )
621
614
  {
622
 
    if (!opt_password.empty())
 
615
    if (not opt_password.empty())
623
616
      opt_password.erase();
624
617
    if (password == PASSWORD_SENTINEL)
625
618
    {
642
635
    {
643
636
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
644
637
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
645
 
      exit(0);
 
638
      abort();
646
639
    }
647
640
 
648
641
    /* Seed the random number generator if we will be using it. */
649
642
    if (auto_generate_sql)
650
643
    {
651
644
      if (opt_set_random_seed == 0)
652
 
        opt_set_random_seed= (unsigned int)time(NULL);
 
645
        opt_set_random_seed= (uint32_t)time(NULL);
653
646
      srandom(opt_set_random_seed);
654
647
    }
655
648
 
656
649
    /* globals? Yes, so we only have to run strlen once */
657
650
    delimiter_length= delimiter.length();
658
651
 
659
 
    slap_connect(&con, false);
 
652
    slap_connect(con, false);
660
653
 
661
654
    /* Main iterations loop */
662
655
burnin:
672
665
      if (concurrency.size())
673
666
      {
674
667
        for (current= &concurrency[0]; current && *current; current++)
675
 
          concurrency_loop(&con, *current, eptr);
 
668
          concurrency_loop(con, *current, eptr);
676
669
      }
677
670
      else
678
671
      {
679
672
        uint32_t infinite= 1;
680
673
        do {
681
 
          concurrency_loop(&con, infinite, eptr);
 
674
          concurrency_loop(con, infinite, eptr);
682
675
        }
683
676
        while (infinite++);
684
677
      }
685
678
 
686
 
      if (!opt_preserve)
687
 
        drop_schema(&con, create_schema_string.c_str());
 
679
      if (not opt_preserve)
 
680
        drop_schema(con, create_schema_string.c_str());
688
681
 
689
682
    } while (eptr ? (eptr= eptr->getNext()) : 0);
690
683
 
691
684
    if (opt_burnin)
692
685
      goto burnin;
693
686
 
694
 
    slap_close(&con);
 
687
    slap_close(con);
695
688
 
696
689
    /* now free all the strings we created */
697
 
    if (!opt_password.empty())
 
690
    if (not opt_password.empty())
698
691
      opt_password.erase();
699
692
 
700
693
    concurrency.clear();
726
719
  return 0;
727
720
}
728
721
 
729
 
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr)
 
722
void concurrency_loop(drizzle_con_st &con, uint32_t current, OptionString *eptr)
730
723
{
731
724
  Stats *head_sptr;
732
725
  Stats *sptr;
737
730
  if (head_sptr == NULL)
738
731
  {
739
732
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
740
 
    exit(1);
 
733
    abort();
741
734
  }
742
735
 
743
736
  if (auto_actual_queries)
774
767
    if (commit_rate)
775
768
      run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
776
769
 
777
 
    if (!pre_system.empty())
 
770
    if (not pre_system.empty())
778
771
    {
779
772
      int ret= system(pre_system.c_str());
780
773
      assert(ret != -1);
793
786
    if (post_statements)
794
787
      run_statements(con, post_statements);
795
788
 
796
 
    if (!post_system.empty())
 
789
    if (not post_system.empty())
797
790
    {
798
791
      int ret=  system(post_system.c_str());
799
792
      assert(ret !=-1);
809
802
 
810
803
  generate_stats(&conclusion, eptr, head_sptr);
811
804
 
812
 
  if (!opt_silent)
813
 
    print_conclusions(&conclusion);
814
 
  if (!opt_csv_str.empty())
815
 
    print_conclusions_csv(&conclusion);
 
805
  if (not opt_silent)
 
806
    print_conclusions(conclusion);
 
807
  if (not opt_csv_str.empty())
 
808
    print_conclusions_csv(conclusion);
816
809
 
817
810
  delete [] head_sptr;
818
811
}
819
812
 
820
813
 
821
 
uint
822
 
get_random_string(char *buf, size_t size)
 
814
uint32_t get_random_string(char *buf, size_t size)
823
815
{
824
816
  char *buf_ptr= buf;
825
817
 
839
831
build_table_string(void)
840
832
{
841
833
  char       buf[HUGE_STRING_LENGTH];
842
 
  unsigned int        col_count;
 
834
  uint32_t        col_count;
843
835
  Statement *ptr;
844
836
  string table_string;
845
837
 
865
857
 
866
858
  if (auto_generate_sql_secondary_indexes)
867
859
  {
868
 
    unsigned int count;
869
 
 
870
 
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
 
860
    for (uint32_t count= 0; count < auto_generate_sql_secondary_indexes; count++)
871
861
    {
872
862
      if (count) /* Except for the first pass we add a comma */
873
863
        table_string.append(",");
876
866
          > HUGE_STRING_LENGTH)
877
867
      {
878
868
        fprintf(stderr, "Memory Allocation error in create table\n");
879
 
        exit(1);
 
869
        abort();
880
870
      }
881
871
      table_string.append(buf);
882
872
    }
894
884
                     col_count, col_count) > HUGE_STRING_LENGTH)
895
885
        {
896
886
          fprintf(stderr, "Memory Allocation error in create table\n");
897
 
          exit(1);
 
887
          abort();
898
888
        }
899
889
      }
900
890
      else
903
893
            > HUGE_STRING_LENGTH)
904
894
        {
905
895
          fprintf(stderr, "Memory Allocation error in create table\n");
906
 
          exit(1);
 
896
          abort();
907
897
        }
908
898
      }
909
899
      table_string.append(buf);
922
912
                     col_count, col_count) > HUGE_STRING_LENGTH)
923
913
        {
924
914
          fprintf(stderr, "Memory Allocation error in creating table\n");
925
 
          exit(1);
 
915
          abort();
926
916
        }
927
917
      }
928
918
      else
931
921
                     col_count) > HUGE_STRING_LENGTH)
932
922
        {
933
923
          fprintf(stderr, "Memory Allocation error in creating table\n");
934
 
          exit(1);
 
924
          abort();
935
925
        }
936
926
      }
937
927
      table_string.append(buf);
947
937
                   col_count) > HUGE_STRING_LENGTH)
948
938
      {
949
939
        fprintf(stderr, "Memory Allocation error in creating table\n");
950
 
        exit(1);
 
940
        abort();
951
941
      }
952
942
      table_string.append(buf);
953
943
 
961
951
  if (ptr->getString()==NULL)
962
952
  {
963
953
    fprintf(stderr, "Memory Allocation error in creating table\n");
964
 
    exit(1);
 
954
    abort();
965
955
  }
966
956
  ptr->setType(CREATE_TABLE_TYPE);
967
957
  strcpy(ptr->getString(), table_string.c_str());
978
968
build_update_string(void)
979
969
{
980
970
  char       buf[HUGE_STRING_LENGTH];
981
 
  unsigned int        col_count;
 
971
  uint32_t        col_count;
982
972
  Statement *ptr;
983
973
  string update_string;
984
974
 
993
983
                   random()) > HUGE_STRING_LENGTH)
994
984
      {
995
985
        fprintf(stderr, "Memory Allocation error in creating update\n");
996
 
        exit(1);
 
986
        abort();
997
987
      }
998
988
      update_string.append(buf);
999
989
 
1012
1002
          > HUGE_STRING_LENGTH)
1013
1003
      {
1014
1004
        fprintf(stderr, "Memory Allocation error in creating update\n");
1015
 
        exit(1);
 
1005
        abort();
1016
1006
      }
1017
1007
      update_string.append(buf);
1018
1008
 
1030
1020
  if (ptr->getString() == NULL)
1031
1021
  {
1032
1022
    fprintf(stderr, "Memory Allocation error in creating update\n");
1033
 
    exit(1);
 
1023
    abort();
1034
1024
  }
1035
1025
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1036
1026
    ptr->setType(UPDATE_TYPE_REQUIRES_PREFIX);
1051
1041
build_insert_string(void)
1052
1042
{
1053
1043
  char       buf[HUGE_STRING_LENGTH];
1054
 
  unsigned int        col_count;
 
1044
  uint32_t        col_count;
1055
1045
  Statement *ptr;
1056
1046
  string insert_string;
1057
1047
 
1077
1067
 
1078
1068
  if (auto_generate_sql_secondary_indexes)
1079
1069
  {
1080
 
    unsigned int count;
 
1070
    uint32_t count;
1081
1071
 
1082
1072
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1083
1073
    {
1097
1087
      if (snprintf(buf, HUGE_STRING_LENGTH, "%ld", random()) > HUGE_STRING_LENGTH)
1098
1088
      {
1099
1089
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1100
 
        exit(1);
 
1090
        abort();
1101
1091
      }
1102
1092
      insert_string.append(buf);
1103
1093
 
1125
1115
 
1126
1116
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1127
1117
    {
1128
 
      unsigned int buf_len;
1129
 
      unsigned int size;
1130
 
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
 
1118
      uint32_t buf_len;
 
1119
      uint32_t size;
 
1120
      uint32_t difference= num_blob_cols_size - num_blob_cols_size_min;
1131
1121
 
1132
1122
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1133
1123
        num_blob_cols_size;
1150
1140
  if (ptr->getString()==NULL)
1151
1141
  {
1152
1142
    fprintf(stderr, "Memory Allocation error in creating select\n");
1153
 
    exit(1);
 
1143
    abort();
1154
1144
  }
1155
1145
  ptr->setType(INSERT_TYPE);
1156
1146
  strcpy(ptr->getString(), insert_string.c_str());
1168
1158
build_select_string(bool key)
1169
1159
{
1170
1160
  char       buf[HUGE_STRING_LENGTH];
1171
 
  unsigned int        col_count;
 
1161
  uint32_t        col_count;
1172
1162
  Statement *ptr;
1173
1163
  string query_string;
1174
1164
 
1175
1165
  query_string.reserve(HUGE_STRING_LENGTH);
1176
1166
 
1177
1167
  query_string.append("SELECT ", 7);
1178
 
  if (!auto_generate_selected_columns_opt.empty())
 
1168
  if (not auto_generate_selected_columns_opt.empty())
1179
1169
  {
1180
1170
    query_string.append(auto_generate_selected_columns_opt.c_str());
1181
1171
  }
1187
1177
          > HUGE_STRING_LENGTH)
1188
1178
      {
1189
1179
        fprintf(stderr, "Memory Allocation error in creating select\n");
1190
 
        exit(1);
 
1180
        abort();
1191
1181
      }
1192
1182
      query_string.append(buf);
1193
1183
 
1201
1191
          > HUGE_STRING_LENGTH)
1202
1192
      {
1203
1193
        fprintf(stderr, "Memory Allocation error in creating select\n");
1204
 
        exit(1);
 
1194
        abort();
1205
1195
      }
1206
1196
      query_string.append(buf);
1207
1197
 
1215
1205
          > HUGE_STRING_LENGTH)
1216
1206
      {
1217
1207
        fprintf(stderr, "Memory Allocation error in creating select\n");
1218
 
        exit(1);
 
1208
        abort();
1219
1209
      }
1220
1210
      query_string.append(buf);
1221
1211
 
1234
1224
  if (ptr->getString() == NULL)
1235
1225
  {
1236
1226
    fprintf(stderr, "Memory Allocation error in creating select\n");
1237
 
    exit(1);
 
1227
    abort();
1238
1228
  }
1239
1229
  if ((key) &&
1240
1230
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1250
1240
{
1251
1241
  struct stat sbuf;
1252
1242
  OptionString *sql_type;
1253
 
  unsigned int sql_type_count= 0;
 
1243
  uint32_t sql_type_count= 0;
1254
1244
  ssize_t bytes_read= 0;
1255
1245
  
1256
1246
  if (user.empty())
1259
1249
  verbose= opt_verbose.length();
1260
1250
 
1261
1251
  /* If something is created we clean it up, otherwise we leave schemas alone */
1262
 
  if ( (!create_string.empty()) || auto_generate_sql)
 
1252
  if ( (not create_string.empty()) || auto_generate_sql)
1263
1253
    opt_preserve= false;
1264
1254
 
1265
 
  if (auto_generate_sql && (!create_string.empty() || !user_supplied_query.empty()))
 
1255
  if (auto_generate_sql && (not create_string.empty() || !user_supplied_query.empty()))
1266
1256
  {
1267
1257
    fprintf(stderr,
1268
1258
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1269
1259
            internal::my_progname);
1270
 
    exit(1);
 
1260
    abort();
1271
1261
  }
1272
1262
 
1273
1263
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1276
1266
    fprintf(stderr,
1277
1267
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1278
1268
            internal::my_progname);
1279
 
    exit(1);
 
1269
    abort();
1280
1270
  }
1281
1271
 
1282
1272
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1284
1274
    fprintf(stderr,
1285
1275
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1286
1276
            internal::my_progname);
1287
 
    exit(1);
 
1277
    abort();
1288
1278
  }
1289
1279
 
1290
 
  parse_comma(!concurrency_str.empty() ? concurrency_str.c_str() : "1", concurrency);
 
1280
  parse_comma(not concurrency_str.empty() ? concurrency_str.c_str() : "1", concurrency);
1291
1281
 
1292
 
  if (!opt_csv_str.empty())
 
1282
  if (not opt_csv_str.empty())
1293
1283
  {
1294
1284
    opt_silent= true;
1295
1285
 
1304
1294
      {
1305
1295
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1306
1296
                internal::my_progname, opt_csv_str.c_str());
1307
 
        exit(1);
 
1297
        abort();
1308
1298
      }
1309
1299
    }
1310
1300
  }
1312
1302
  if (opt_only_print)
1313
1303
    opt_silent= true;
1314
1304
 
1315
 
  if (!num_int_cols_opt.empty())
 
1305
  if (not num_int_cols_opt.empty())
1316
1306
  {
1317
1307
    OptionString *str;
1318
1308
    parse_option(num_int_cols_opt.c_str(), &str, ',');
1322
1312
    option_cleanup(str);
1323
1313
  }
1324
1314
 
1325
 
  if (!num_char_cols_opt.empty())
 
1315
  if (not num_char_cols_opt.empty())
1326
1316
  {
1327
1317
    OptionString *str;
1328
1318
    parse_option(num_char_cols_opt.c_str(), &str, ',');
1334
1324
    option_cleanup(str);
1335
1325
  }
1336
1326
 
1337
 
  if (!num_blob_cols_opt.empty())
 
1327
  if (not num_blob_cols_opt.empty())
1338
1328
  {
1339
1329
    OptionString *str;
1340
1330
    parse_option(num_blob_cols_opt.c_str(), &str, ',');
1419
1409
          fprintf(stderr,
1420
1410
                  "%s: Can't perform key test without a primary key!\n",
1421
1411
                  internal::my_progname);
1422
 
          exit(1);
 
1412
          abort();
1423
1413
        }
1424
1414
 
1425
1415
        query_statements[sql_type_count]= build_select_string(true);
1455
1445
          fprintf(stderr,
1456
1446
                  "%s: Can't perform update test without a primary key!\n",
1457
1447
                  internal::my_progname);
1458
 
          exit(1);
 
1448
          abort();
1459
1449
        }
1460
1450
 
1461
1451
        query_statements[sql_type_count]= build_update_string();
1496
1486
  }
1497
1487
  else
1498
1488
  {
1499
 
    if (!create_string.empty() && !stat(create_string.c_str(), &sbuf))
 
1489
    if (not create_string.empty() && !stat(create_string.c_str(), &sbuf))
1500
1490
    {
1501
1491
      int data_file;
1502
1492
      std::vector<char> tmp_string;
1503
 
      if (!S_ISREG(sbuf.st_mode))
 
1493
      if (not S_ISREG(sbuf.st_mode))
1504
1494
      {
1505
1495
        fprintf(stderr,"%s: Create file was not a regular file\n",
1506
1496
                internal::my_progname);
1507
 
        exit(1);
 
1497
        abort();
1508
1498
      }
1509
1499
      if ((data_file= open(create_string.c_str(), O_RDWR)) == -1)
1510
1500
      {
1511
1501
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
1512
 
        exit(1);
 
1502
        abort();
1513
1503
      }
1514
1504
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1515
1505
      {
1516
1506
        fprintf(stderr, "Request for more memory than architecture supports\n");
1517
 
        exit(1);
 
1507
        abort();
1518
1508
      }
1519
1509
      tmp_string.resize(sbuf.st_size + 1);
1520
1510
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1526
1516
      }
1527
1517
      parse_delimiter(&tmp_string[0], &create_statements, delimiter[0]);
1528
1518
    }
1529
 
    else if (!create_string.empty())
 
1519
    else if (not create_string.empty())
1530
1520
    {
1531
1521
      parse_delimiter(create_string.c_str(), &create_statements, delimiter[0]);
1532
1522
    }
1533
1523
 
1534
1524
    /* Set this up till we fully support options on user generated queries */
1535
 
    if (!user_supplied_query.empty())
 
1525
    if (not user_supplied_query.empty())
1536
1526
    {
1537
1527
      query_statements_count=
1538
1528
        parse_option("default", &query_options, ',');
1540
1530
      query_statements.resize(query_statements_count);
1541
1531
    }
1542
1532
 
1543
 
    if (!user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
 
1533
    if (not user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
1544
1534
    {
1545
1535
      int data_file;
1546
1536
      std::vector<char> tmp_string;
1547
1537
 
1548
 
      if (!S_ISREG(sbuf.st_mode))
 
1538
      if (not S_ISREG(sbuf.st_mode))
1549
1539
      {
1550
1540
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1551
1541
                internal::my_progname);
1552
 
        exit(1);
 
1542
        abort();
1553
1543
      }
1554
1544
      if ((data_file= open(user_supplied_query.c_str(), O_RDWR)) == -1)
1555
1545
      {
1556
1546
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1557
 
        exit(1);
 
1547
        abort();
1558
1548
      }
1559
1549
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1560
1550
      {
1561
1551
        fprintf(stderr, "Request for more memory than architecture supports\n");
1562
 
        exit(1);
 
1552
        abort();
1563
1553
      }
1564
1554
      tmp_string.resize((size_t)(sbuf.st_size + 1));
1565
1555
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1569
1559
      {
1570
1560
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1571
1561
      }
1572
 
      if (!user_supplied_query.empty())
 
1562
      if (not user_supplied_query.empty())
1573
1563
        actual_queries= parse_delimiter(&tmp_string[0], &query_statements[0],
1574
1564
                                        delimiter[0]);
1575
1565
    }
1576
 
    else if (!user_supplied_query.empty())
 
1566
    else if (not user_supplied_query.empty())
1577
1567
    {
1578
1568
      actual_queries= parse_delimiter(user_supplied_query.c_str(), &query_statements[0],
1579
1569
                                      delimiter[0]);
1580
1570
    }
1581
1571
  }
1582
1572
 
1583
 
  if (!user_supplied_pre_statements.empty()
 
1573
  if (not user_supplied_pre_statements.empty()
1584
1574
      && !stat(user_supplied_pre_statements.c_str(), &sbuf))
1585
1575
  {
1586
1576
    int data_file;
1587
1577
    std::vector<char> tmp_string;
1588
1578
 
1589
 
    if (!S_ISREG(sbuf.st_mode))
 
1579
    if (not S_ISREG(sbuf.st_mode))
1590
1580
    {
1591
1581
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1592
1582
              internal::my_progname);
1593
 
      exit(1);
 
1583
      abort();
1594
1584
    }
1595
1585
    if ((data_file= open(user_supplied_pre_statements.c_str(), O_RDWR)) == -1)
1596
1586
    {
1597
1587
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1598
 
      exit(1);
 
1588
      abort();
1599
1589
    }
1600
1590
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1601
1591
    {
1602
1592
      fprintf(stderr, "Request for more memory than architecture supports\n");
1603
 
      exit(1);
 
1593
      abort();
1604
1594
    }
1605
1595
    tmp_string.resize((size_t)(sbuf.st_size + 1));
1606
1596
    bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1610
1600
    {
1611
1601
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1612
1602
    }
1613
 
    if (!user_supplied_pre_statements.empty())
 
1603
    if (not user_supplied_pre_statements.empty())
1614
1604
      (void)parse_delimiter(&tmp_string[0], &pre_statements,
1615
1605
                            delimiter[0]);
1616
1606
  }
1617
 
  else if (!user_supplied_pre_statements.empty())
 
1607
  else if (not user_supplied_pre_statements.empty())
1618
1608
  {
1619
1609
    (void)parse_delimiter(user_supplied_pre_statements.c_str(),
1620
1610
                          &pre_statements,
1621
1611
                          delimiter[0]);
1622
1612
  }
1623
1613
 
1624
 
  if (!user_supplied_post_statements.empty()
 
1614
  if (not user_supplied_post_statements.empty()
1625
1615
      && !stat(user_supplied_post_statements.c_str(), &sbuf))
1626
1616
  {
1627
1617
    int data_file;
1628
1618
    std::vector<char> tmp_string;
1629
1619
 
1630
 
    if (!S_ISREG(sbuf.st_mode))
 
1620
    if (not S_ISREG(sbuf.st_mode))
1631
1621
    {
1632
1622
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1633
1623
              internal::my_progname);
1634
 
      exit(1);
 
1624
      abort();
1635
1625
    }
1636
1626
    if ((data_file= open(user_supplied_post_statements.c_str(), O_RDWR)) == -1)
1637
1627
    {
1638
1628
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1639
 
      exit(1);
 
1629
      abort();
1640
1630
    }
1641
1631
 
1642
1632
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1643
1633
    {
1644
1634
      fprintf(stderr, "Request for more memory than architecture supports\n");
1645
 
      exit(1);
 
1635
      abort();
1646
1636
    }
1647
1637
    tmp_string.resize((size_t)(sbuf.st_size + 1));
1648
1638
 
1653
1643
    {
1654
1644
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1655
1645
    }
1656
 
    if (!user_supplied_post_statements.empty())
 
1646
    if (not user_supplied_post_statements.empty())
1657
1647
      (void)parse_delimiter(&tmp_string[0], &post_statements,
1658
1648
                            delimiter[0]);
1659
1649
  }
1660
 
  else if (!user_supplied_post_statements.empty())
 
1650
  else if (not user_supplied_post_statements.empty())
1661
1651
  {
1662
1652
    (void)parse_delimiter(user_supplied_post_statements.c_str(), &post_statements,
1663
1653
                          delimiter[0]);
1666
1656
  if (verbose >= 2)
1667
1657
    printf("Parsing engines to use.\n");
1668
1658
 
1669
 
  if (!default_engine.empty())
 
1659
  if (not default_engine.empty())
1670
1660
    parse_option(default_engine.c_str(), &engine_options, ',');
1671
1661
 
1672
1662
  if (tty_password)
1675
1665
}
1676
1666
 
1677
1667
 
1678
 
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
 
1668
static int run_query(drizzle_con_st &con, drizzle_result_st *result,
1679
1669
                     const char *query, int len)
1680
1670
{
1681
1671
  drizzle_return_t ret;
1693
1683
  if (result == NULL)
1694
1684
    result= &result_buffer;
1695
1685
 
1696
 
  result= drizzle_query(con, result, query, len, &ret);
 
1686
  result= drizzle_query(&con, result, query, len, &ret);
1697
1687
 
1698
1688
  if (ret == DRIZZLE_RETURN_OK)
1699
1689
    ret= drizzle_result_buffer(result);
1706
1696
 
1707
1697
 
1708
1698
static int
1709
 
generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt)
 
1699
generate_primary_key_list(drizzle_con_st &con, OptionString *engine_stmt)
1710
1700
{
1711
1701
  drizzle_result_st result;
1712
1702
  drizzle_row_t row;
1728
1718
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1729
1719
    {
1730
1720
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
1731
 
              drizzle_con_error(con));
1732
 
      exit(1);
 
1721
              drizzle_con_error(&con));
 
1722
      abort();
1733
1723
    }
1734
1724
 
1735
1725
    uint64_t num_rows_ret= drizzle_result_row_count(&result);
1736
1726
    if (num_rows_ret > SIZE_MAX)
1737
1727
    {
1738
1728
      fprintf(stderr, "More primary keys than than architecture supports\n");
1739
 
      exit(1);
 
1729
      abort();
1740
1730
    }
1741
1731
    size_t primary_keys_number_of;
1742
1732
    primary_keys_number_of= (size_t)num_rows_ret;
1761
1751
  return(0);
1762
1752
}
1763
1753
 
1764
 
static int
1765
 
create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
1766
 
              OptionString *engine_stmt, Stats *sptr)
 
1754
static void create_schema(drizzle_con_st &con, const char *db, Statement *stmt, OptionString *engine_stmt, Stats *sptr)
1767
1755
{
1768
1756
  char query[HUGE_STRING_LENGTH];
1769
1757
  Statement *ptr;
1770
1758
  Statement *after_create;
1771
1759
  int len;
1772
 
  uint64_t count;
1773
1760
  struct timeval start_time, end_time;
1774
1761
 
1775
1762
 
1783
1770
  if (run_query(con, NULL, query, len))
1784
1771
  {
1785
1772
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
1786
 
            drizzle_con_error(con));
1787
 
    exit(1);
 
1773
            drizzle_con_error(&con));
 
1774
    abort();
1788
1775
  }
1789
1776
  else
1790
1777
  {
1803
1790
    if (verbose >= 3)
1804
1791
      printf("%s;\n", query);
1805
1792
 
1806
 
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
 
1793
    if (drizzle_select_db(&con,  &result, db, &ret) == NULL ||
1807
1794
        ret != DRIZZLE_RETURN_OK)
1808
1795
    {
1809
1796
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
1810
1797
              ret == DRIZZLE_RETURN_ERROR_CODE ?
1811
 
              drizzle_result_error(&result) : drizzle_con_error(con));
1812
 
      exit(1);
 
1798
              drizzle_result_error(&result) : drizzle_con_error(&con));
 
1799
      abort();
1813
1800
    }
1814
1801
    drizzle_result_free(&result);
1815
1802
    sptr->setCreateCount(sptr->getCreateCount()+1);
1822
1809
    if (run_query(con, NULL, query, len))
1823
1810
    {
1824
1811
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
1825
 
              drizzle_con_error(con));
1826
 
      exit(1);
 
1812
              drizzle_con_error(&con));
 
1813
      abort();
1827
1814
    }
1828
1815
    sptr->setCreateCount(sptr->getCreateCount()+1);
1829
1816
  }
1830
1817
 
1831
 
  count= 0;
 
1818
  uint64_t count= 0;
1832
1819
  after_create= stmt;
1833
1820
 
1834
1821
limit_not_met:
1846
1833
      if (run_query(con, NULL, buffer, strlen(buffer)))
1847
1834
      {
1848
1835
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1849
 
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1850
 
        if (!opt_ignore_sql_errors)
1851
 
          exit(1);
 
1836
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1837
        if (not opt_ignore_sql_errors)
 
1838
          abort();
1852
1839
      }
1853
1840
      sptr->setCreateCount(sptr->getCreateCount()+1);
1854
1841
    }
1857
1844
      if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1858
1845
      {
1859
1846
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1860
 
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1861
 
        if (!opt_ignore_sql_errors)
1862
 
          exit(1);
 
1847
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1848
        if (not opt_ignore_sql_errors)
 
1849
          abort();
1863
1850
      }
1864
1851
      sptr->setCreateCount(sptr->getCreateCount()+1);
1865
1852
    }
1875
1862
  gettimeofday(&end_time, NULL);
1876
1863
 
1877
1864
  sptr->setCreateTiming(timedif(end_time, start_time));
1878
 
 
1879
 
  return(0);
1880
1865
}
1881
1866
 
1882
 
static int
1883
 
drop_schema(drizzle_con_st *con, const char *db)
 
1867
static void drop_schema(drizzle_con_st &con, const char *db)
1884
1868
{
1885
1869
  char query[HUGE_STRING_LENGTH];
1886
1870
  int len;
1890
1874
  if (run_query(con, NULL, query, len))
1891
1875
  {
1892
1876
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1893
 
            internal::my_progname, db, drizzle_con_error(con));
1894
 
    exit(1);
 
1877
            internal::my_progname, db, drizzle_con_error(&con));
 
1878
    abort();
1895
1879
  }
1896
 
 
1897
 
 
1898
 
 
1899
 
  return(0);
1900
1880
}
1901
1881
 
1902
 
static int
1903
 
run_statements(drizzle_con_st *con, Statement *stmt)
 
1882
static void run_statements(drizzle_con_st &con, Statement *stmt)
1904
1883
{
1905
 
  Statement *ptr;
1906
 
 
1907
 
  for (ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
 
1884
  for (Statement *ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
1908
1885
  {
1909
1886
    if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1910
1887
    {
1911
1888
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1912
 
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1913
 
      exit(1);
 
1889
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
1890
      abort();
1914
1891
    }
1915
1892
  }
1916
 
 
1917
 
  return(0);
1918
1893
}
1919
1894
 
1920
1895
 
1924
1899
    We lock around the initial call in case were we in a loop. This
1925
1900
    also keeps the value properly syncronized across call threads.
1926
1901
  */
1927
 
  sleeper_mutex.lock();
1928
 
  while (master_wakeup)
1929
 
  {
1930
 
    sleep_threshhold.wait(sleeper_mutex);
1931
 
  }
1932
 
  sleeper_mutex.unlock();
 
1902
  master_wakeup.wait();
1933
1903
 
1934
1904
  {
1935
1905
    boost::mutex::scoped_lock scopedLock(timer_alarm_mutex);
1947
1917
  }
1948
1918
}
1949
1919
 
1950
 
static int
1951
 
run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
 
1920
static void run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
1952
1921
{
1953
 
  unsigned int real_concurrency;
 
1922
  uint32_t real_concurrency;
1954
1923
  struct timeval start_time, end_time;
1955
1924
 
1956
1925
  {
1959
1928
    OptionString *sql_type;
1960
1929
    thread_counter= 0;
1961
1930
 
1962
 
    {
1963
 
      boost::mutex::scoped_lock scopedWakeup(sleeper_mutex);
1964
 
      master_wakeup= true;
1965
 
    }
 
1931
    master_wakeup.reset();
1966
1932
 
1967
1933
    real_concurrency= 0;
1968
1934
 
1971
1937
         y < query_statements_count;
1972
1938
         y++, sql_type= sql_type->getNext())
1973
1939
    {
1974
 
      unsigned int options_loop= 1;
 
1940
      uint32_t options_loop= 1;
1975
1941
 
1976
1942
      if (sql_type->getOption())
1977
1943
      {
1989
1955
          if (con == NULL)
1990
1956
          {
1991
1957
            fprintf(stderr, "Memory Allocation error in scheduler\n");
1992
 
            exit(1);
 
1958
            abort();
1993
1959
          }
1994
1960
          con->setStmt(stmts[y]);
1995
1961
          con->setLimit(limit);
2018
1984
    }
2019
1985
  }
2020
1986
 
2021
 
  {
2022
 
    boost::mutex::scoped_lock scopedSleeper(sleeper_mutex);
2023
 
    master_wakeup= false;
2024
 
  }
2025
 
  sleep_threshhold.notify_all();
 
1987
  master_wakeup.start();
2026
1988
 
2027
1989
  gettimeofday(&start_time, NULL);
2028
1990
 
2047
2009
  sptr->setUsers(concur);
2048
2010
  sptr->setRealUsers(real_concurrency);
2049
2011
  sptr->setRows(limit);
2050
 
 
2051
 
  return(0);
2052
2012
}
2053
2013
 
2054
2014
/*
2055
2015
  Parse records from comma seperated string. : is a reserved character and is used for options
2056
2016
  on variables.
2057
2017
*/
2058
 
uint
2059
 
parse_option(const char *origin, OptionString **stmt, char delm)
 
2018
uint32_t parse_option(const char *origin, OptionString **stmt, char delm)
2060
2019
{
2061
2020
  char *string;
2062
2021
  char *begin_ptr;
2106
2065
    if (tmp->getString() == NULL)
2107
2066
    {
2108
2067
      fprintf(stderr,"Error allocating memory while parsing options\n");
2109
 
      exit(1);
 
2068
      abort();
2110
2069
    }
2111
2070
 
2112
2071
    if (isspace(*begin_ptr))
2129
2088
  Raw parsing interface. If you want the slap specific parser look at
2130
2089
  parse_option.
2131
2090
*/
2132
 
uint
2133
 
parse_delimiter(const char *script, Statement **stmt, char delm)
 
2091
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm)
2134
2092
{
2135
2093
  char *retstr;
2136
2094
  char *ptr= (char *)script;
2147
2105
    if (tmp == NULL)
2148
2106
    {
2149
2107
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2150
 
      exit(1);
 
2108
      abort();
2151
2109
    }
2152
2110
 
2153
2111
    count++;
2156
2114
    if (tmp->getString() == NULL)
2157
2115
    {
2158
2116
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2159
 
      exit(1);
 
2117
      abort();
2160
2118
    }
2161
2119
 
2162
2120
    memcpy(tmp->getString(), ptr, tmp->getLength());
2171
2129
    if (tmp->getString() == NULL)
2172
2130
    {
2173
2131
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2174
 
      exit(1);
 
2132
      abort();
2175
2133
    }
2176
2134
    memcpy(tmp->getString(), ptr, tmp->getLength());
2177
2135
    count++;
2186
2144
  number ranges from a comma seperated string.
2187
2145
  In restrospect, this is a lousy name from this function.
2188
2146
*/
2189
 
uint
2190
 
parse_comma(const char *string, std::vector <uint32_t> &range)
 
2147
uint32_t parse_comma(const char *string, std::vector <uint32_t> &range)
2191
2148
{
2192
 
  unsigned int count= 1,x; /* We know that there is always one */
 
2149
  uint32_t count= 1; /* We know that there is always one */
2193
2150
  char *retstr;
2194
2151
  char *ptr= (char *)string;
2195
 
  unsigned int *nptr;
 
2152
  uint32_t *nptr;
2196
2153
 
2197
2154
  for (;*ptr; ptr++)
2198
2155
    if (*ptr == ',') count++;
2202
2159
  nptr= &range[0];
2203
2160
 
2204
2161
  ptr= (char *)string;
2205
 
  x= 0;
 
2162
  uint32_t x= 0;
2206
2163
  while ((retstr= strchr(ptr,',')))
2207
2164
  {
2208
2165
    nptr[x++]= atoi(ptr);
2213
2170
  return count;
2214
2171
}
2215
2172
 
2216
 
void
2217
 
print_conclusions(Conclusions *con)
 
2173
void print_conclusions(Conclusions &con)
2218
2174
{
2219
2175
  printf("Benchmark\n");
2220
 
  if (con->getEngine())
2221
 
    printf("\tRunning for engine %s\n", con->getEngine());
2222
 
  if (!opt_label.empty() || !opt_auto_generate_sql_type.empty())
 
2176
  if (con.getEngine())
 
2177
    printf("\tRunning for engine %s\n", con.getEngine());
 
2178
 
 
2179
  if (not opt_label.empty() || !opt_auto_generate_sql_type.empty())
2223
2180
  {
2224
2181
    const char *ptr= opt_auto_generate_sql_type.c_str() ? opt_auto_generate_sql_type.c_str() : "query";
2225
2182
    printf("\tLoad: %s\n", !opt_label.empty() ? opt_label.c_str() : ptr);
2226
2183
  }
2227
2184
  printf("\tAverage Time took to generate schema and initial data: %ld.%03ld seconds\n",
2228
 
         con->getCreateAvgTiming() / 1000, con->getCreateAvgTiming() % 1000);
 
2185
         con.getCreateAvgTiming() / 1000, con.getCreateAvgTiming() % 1000);
2229
2186
  printf("\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
2230
 
         con->getAvgTiming() / 1000, con->getAvgTiming() % 1000);
 
2187
         con.getAvgTiming() / 1000, con.getAvgTiming() % 1000);
2231
2188
  printf("\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
2232
 
         con->getMinTiming() / 1000, con->getMinTiming() % 1000);
 
2189
         con.getMinTiming() / 1000, con.getMinTiming() % 1000);
2233
2190
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2234
 
         con->getMaxTiming() / 1000, con->getMaxTiming() % 1000);
 
2191
         con.getMaxTiming() / 1000, con.getMaxTiming() % 1000);
2235
2192
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2236
 
         con->getSumOfTime() / 1000, con->getSumOfTime() % 1000);
2237
 
  printf("\tStandard Deviation: %ld.%03ld\n", con->getStdDev() / 1000, con->getStdDev() % 1000);
2238
 
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->getCreateCount());
 
2193
         con.getSumOfTime() / 1000, con.getSumOfTime() % 1000);
 
2194
  printf("\tStandard Deviation: %ld.%03ld\n", con.getStdDev() / 1000, con.getStdDev() % 1000);
 
2195
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con.getCreateCount());
2239
2196
  printf("\tNumber of clients running queries: %u/%u\n",
2240
 
         con->getUsers(), con->getRealUsers());
 
2197
         con.getUsers(), con.getRealUsers());
2241
2198
  printf("\tNumber of times test was run: %u\n", iterations);
2242
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->getAvgRows());
 
2199
  printf("\tAverage number of queries per client: %"PRIu64"\n", con.getAvgRows());
2243
2200
  printf("\n");
2244
2201
}
2245
2202
 
2246
 
void
2247
 
print_conclusions_csv(Conclusions *con)
 
2203
void print_conclusions_csv(Conclusions &con)
2248
2204
{
2249
 
  unsigned int x;
2250
2205
  char buffer[HUGE_STRING_LENGTH];
2251
2206
  char label_buffer[HUGE_STRING_LENGTH];
2252
2207
  size_t string_len;
2254
2209
 
2255
2210
  memset(label_buffer, 0, sizeof(label_buffer));
2256
2211
 
2257
 
  if (!opt_label.empty())
 
2212
  if (not opt_label.empty())
2258
2213
  {
2259
2214
    string_len= opt_label.length();
2260
2215
 
2261
 
    for (x= 0; x < string_len; x++)
 
2216
    for (uint32_t x= 0; x < string_len; x++)
2262
2217
    {
2263
2218
      if (temp_label[x] == ',')
2264
2219
        label_buffer[x]= '-';
2266
2221
        label_buffer[x]= temp_label[x] ;
2267
2222
    }
2268
2223
  }
2269
 
  else if (!opt_auto_generate_sql_type.empty())
 
2224
  else if (not opt_auto_generate_sql_type.empty())
2270
2225
  {
2271
2226
    string_len= opt_auto_generate_sql_type.length();
2272
2227
 
2273
 
    for (x= 0; x < string_len; x++)
 
2228
    for (uint32_t x= 0; x < string_len; x++)
2274
2229
    {
2275
2230
      if (opt_auto_generate_sql_type[x] == ',')
2276
2231
        label_buffer[x]= '-';
2286
2241
  snprintf(buffer, HUGE_STRING_LENGTH,
2287
2242
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2288
2243
           "%u,%u,%u,%"PRIu64"\n",
2289
 
           con->getEngine() ? con->getEngine() : "", /* Storage engine we ran against */
 
2244
           con.getEngine() ? con.getEngine() : "", /* Storage engine we ran against */
2290
2245
           label_buffer, /* Load type */
2291
 
           con->getAvgTiming() / 1000, con->getAvgTiming() % 1000, /* Time to load */
2292
 
           con->getMinTiming() / 1000, con->getMinTiming() % 1000, /* Min time */
2293
 
           con->getMaxTiming() / 1000, con->getMaxTiming() % 1000, /* Max time */
2294
 
           con->getSumOfTime() / 1000, con->getSumOfTime() % 1000, /* Total time */
2295
 
           con->getStdDev() / 1000, con->getStdDev() % 1000, /* Standard Deviation */
 
2246
           con.getAvgTiming() / 1000, con.getAvgTiming() % 1000, /* Time to load */
 
2247
           con.getMinTiming() / 1000, con.getMinTiming() % 1000, /* Min time */
 
2248
           con.getMaxTiming() / 1000, con.getMaxTiming() % 1000, /* Max time */
 
2249
           con.getSumOfTime() / 1000, con.getSumOfTime() % 1000, /* Total time */
 
2250
           con.getStdDev() / 1000, con.getStdDev() % 1000, /* Standard Deviation */
2296
2251
           iterations, /* Iterations */
2297
 
           con->getUsers(), /* Children used max_timing */
2298
 
           con->getRealUsers(), /* Children used max_timing */
2299
 
           con->getAvgRows()  /* Queries run */
 
2252
           con.getUsers(), /* Children used max_timing */
 
2253
           con.getRealUsers(), /* Children used max_timing */
 
2254
           con.getAvgRows()  /* Queries run */
2300
2255
           );
2301
2256
  size_t buff_len= strlen(buffer);
2302
2257
  ssize_t write_ret= write(csv_file, (unsigned char*) buffer, buff_len);
2309
2264
  }
2310
2265
}
2311
2266
 
2312
 
void
2313
 
generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
 
2267
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
2314
2268
{
2315
2269
  Stats *ptr;
2316
 
  unsigned int x;
 
2270
  uint32_t x;
2317
2271
 
2318
2272
  con->setMinTiming(sptr->getTiming());
2319
2273
  con->setMaxTiming(sptr->getTiming());
2343
2297
  else
2344
2298
    con->setEngine(NULL);
2345
2299
 
2346
 
  standard_deviation(con, sptr);
 
2300
  standard_deviation(*con, sptr);
2347
2301
 
2348
2302
  /* Now we do the create time operations */
2349
2303
  con->setCreateMinTiming(sptr->getCreateTiming());
2379
2333
  }
2380
2334
}
2381
2335
 
2382
 
void
2383
 
statement_cleanup(Statement *stmt)
 
2336
void statement_cleanup(Statement *stmt)
2384
2337
{
2385
2338
  Statement *ptr, *nptr;
2386
 
  if (!stmt)
 
2339
  if (not stmt)
2387
2340
    return;
2388
2341
 
2389
2342
  for (ptr= stmt; ptr; ptr= nptr)
2393
2346
  }
2394
2347
}
2395
2348
 
2396
 
void slap_close(drizzle_con_st *con)
 
2349
void slap_close(drizzle_con_st &con)
2397
2350
{
2398
2351
  if (opt_only_print)
2399
2352
    return;
2400
2353
 
2401
 
  drizzle_free(drizzle_con_drizzle(con));
 
2354
  drizzle_free(drizzle_con_drizzle(&con));
2402
2355
}
2403
2356
 
2404
 
void slap_connect(drizzle_con_st *con, bool connect_to_schema)
 
2357
void slap_connect(drizzle_con_st &con, bool connect_to_schema)
2405
2358
{
2406
2359
  /* Connect to server */
2407
2360
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2416
2369
    usleep(random()%opt_delayed_start);
2417
2370
 
2418
2371
  if ((drizzle= drizzle_create(NULL)) == NULL ||
2419
 
      drizzle_con_add_tcp(drizzle, con, host.c_str(), opt_drizzle_port,
 
2372
      drizzle_con_add_tcp(drizzle, &con, host.c_str(), opt_drizzle_port,
2420
2373
        user.c_str(),
2421
2374
        opt_password.c_str(),
2422
2375
        connect_to_schema ? create_schema_string.c_str() : NULL,
2423
2376
        use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
2424
2377
  {
2425
2378
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
2426
 
    exit(1);
 
2379
    abort();
2427
2380
  }
2428
2381
 
2429
2382
  for (uint32_t x= 0; x < 10; x++)
2430
2383
  {
2431
 
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
 
2384
    if ((ret= drizzle_con_connect(&con)) == DRIZZLE_RETURN_OK)
2432
2385
    {
2433
2386
      /* Connect suceeded */
2434
2387
      connect_error= 0;
2439
2392
  if (connect_error)
2440
2393
  {
2441
2394
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
2442
 
            ret, drizzle_con_error(con));
2443
 
    exit(1);
 
2395
            ret, drizzle_con_error(&con));
 
2396
    abort();
2444
2397
  }
2445
2398
}
2446
2399
 
2447
 
void
2448
 
standard_deviation (Conclusions *con, Stats *sptr)
 
2400
void standard_deviation(Conclusions &con, Stats *sptr)
2449
2401
{
2450
 
  unsigned int x;
2451
2402
  long int sum_of_squares;
2452
2403
  double the_catch;
2453
2404
  Stats *ptr;
2454
2405
 
2455
2406
  if (iterations == 1 || iterations == 0)
2456
2407
  {
2457
 
    con->setStdDev(0);
 
2408
    con.setStdDev(0);
2458
2409
    return;
2459
2410
  }
2460
2411
 
 
2412
  uint32_t x;
2461
2413
  for (ptr= sptr, x= 0, sum_of_squares= 0; x < iterations; ptr++, x++)
2462
2414
  {
2463
2415
    long int deviation;
2464
2416
 
2465
 
    deviation= ptr->getTiming() - con->getAvgTiming();
 
2417
    deviation= ptr->getTiming() - con.getAvgTiming();
2466
2418
    sum_of_squares+= deviation*deviation;
2467
2419
  }
2468
2420
 
2469
2421
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2470
 
  con->setStdDev((long int)the_catch);
 
2422
  con.setStdDev((long int)the_catch);
2471
2423
}