1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6 
7 
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9 
10     PerconaFT is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License, version 2,
12     as published by the Free Software Foundation.
13 
14     PerconaFT is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
21 
22 ----------------------------------------
23 
24     PerconaFT is free software: you can redistribute it and/or modify
25     it under the terms of the GNU Affero General Public License, version 3,
26     as published by the Free Software Foundation.
27 
28     PerconaFT is distributed in the hope that it will be useful,
29     but WITHOUT ANY WARRANTY; without even the implied warranty of
30     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31     GNU Affero General Public License for more details.
32 
33     You should have received a copy of the GNU Affero General Public License
34     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36 
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38 
39 #include "test.h"
40 #include <vector>
41 #include <db.h>
42 #include "toku_time.h"
43 
open_dbs(DB_ENV * env,int max_dbs)44 static void open_dbs(DB_ENV *env, int max_dbs) {
45     std::vector<DB *> dbs;
46 
47     uint64_t t_start = toku_current_time_microsec();
48     // open db's
49     {
50         uint64_t t0 = toku_current_time_microsec();
51         for (int i = 1; i <= max_dbs; i++) {
52             int r;
53             DB *db = NULL;
54             r = db_create(&db, env, 0);
55             assert(r == 0);
56             char db_name[32];
57             sprintf(db_name, "db%d", i);
58             r = db->open(db, NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0666);
59             assert(r == 0);
60             dbs.push_back(db);
61             if ((i % 100) == 0) {
62                 uint64_t t = toku_current_time_microsec();
63                 fprintf(stderr, "open %d %" PRIu64 "\n", i, t - t0);
64                 t0 = t;
65             }
66         }
67     }
68     uint64_t t_end = toku_current_time_microsec();
69     fprintf(stderr, "%" PRIu64 "\n", t_end - t_start);
70 
71     // close db's
72     {
73         uint64_t t0 = toku_current_time_microsec();
74         int i = 1;
75         for (std::vector<DB *>::iterator dbi = dbs.begin(); dbi != dbs.end(); dbi++, i++) {
76             DB *db = *dbi;
77             int r = db->close(db, 0);
78             assert(r == 0);
79             if ((i % 100) == 0) {
80                 uint64_t t = toku_current_time_microsec();
81                 printf("close %d %" PRIu64 "\n", i, t - t0);
82                 t0 = t;
83             }
84         }
85     }
86 }
87 
test_main(int argc,char * const argv[])88 int test_main (int argc, char * const argv[]) {
89     int r;
90     int max_dbs = 1;
91 
92     // parse_args(argc, argv);
93     for (int i = 1; i < argc; i++) {
94         if (strcmp(argv[i], "-v") == 0) {
95             verbose++;
96             continue;
97         }
98         if (strcmp(argv[i], "-q") == 0) {
99             if (verbose > 0) verbose--;
100             continue;
101         }
102         max_dbs = atoi(argv[i]);
103         continue;
104     }
105 
106     toku_os_recursive_delete(TOKU_TEST_FILENAME);
107     r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
108 
109     DB_ENV *env = NULL;
110     r = db_env_create(&env, 0);
111     assert(r == 0);
112     env->set_errfile(env, stderr);
113     r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_LOCK+DB_INIT_MPOOL+DB_INIT_TXN+DB_INIT_LOG + DB_CREATE + DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO);
114     assert(r == 0);
115 
116     open_dbs(env, max_dbs);
117 
118     r = env->close(env, 0);
119     assert(r == 0);
120 
121     return 0;
122 }
123