Skip to content

Commit daf6f55

Browse files
committed
Refactor utils, add silent option for basic db
1 parent 20497a4 commit daf6f55

28 files changed

Lines changed: 80 additions & 59 deletions

core/acknowledged_counter_generator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
#include "acknowledged_counter_generator.h"
9-
#include "utils.h"
9+
#include "utils/utils.h"
1010

1111
namespace ycsbc {
1212
void AcknowledgedCounterGenerator::Acknowledge(uint64_t value) {

core/basic_db.cc

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@
99
#include "basic_db.h"
1010
#include "core/db_factory.h"
1111

12-
using std::cout;
13-
using std::endl;
12+
namespace {
13+
const std::string PROP_SILENT = "basic.silent";
14+
const std::string PROP_SILENT_DEFAULT = "false";
15+
}
1416

1517
namespace ycsbc {
1618

1719
std::mutex BasicDB:: mutex_;
1820

1921
void BasicDB::Init() {
2022
std::lock_guard<std::mutex> lock(mutex_);
23+
if (props_->GetProperty(PROP_SILENT, PROP_SILENT_DEFAULT) == "true") {
24+
out_ = new std::ofstream;
25+
out_->setstate(std::ios_base::badbit);
26+
} else {
27+
out_ = &std::cout;
28+
}
2129
}
2230

2331
DB::Status BasicDB::Read(const std::string &table, const std::string &key,
2432
const std::vector<std::string> *fields, std::vector<Field> &result) {
2533
std::lock_guard<std::mutex> lock(mutex_);
26-
cout << "READ " << table << ' ' << key;
34+
*out_ << "READ " << table << ' ' << key;
2735
if (fields) {
28-
cout << " [ ";
36+
*out_ << " [ ";
2937
for (auto f : *fields) {
30-
cout << f << ' ';
38+
*out_ << f << ' ';
3139
}
32-
cout << ']' << endl;
40+
*out_ << ']' << std::endl;
3341
} else {
34-
cout << " < all fields >" << endl;
42+
*out_ << " < all fields >" << std::endl;
3543
}
3644
return kOK;
3745
}
@@ -40,44 +48,44 @@ DB::Status BasicDB::Scan(const std::string &table, const std::string &key, int l
4048
const std::vector<std::string> *fields,
4149
std::vector<std::vector<Field>> &result) {
4250
std::lock_guard<std::mutex> lock(mutex_);
43-
cout << "SCAN " << table << ' ' << key << " " << len;
51+
*out_ << "SCAN " << table << ' ' << key << " " << len;
4452
if (fields) {
45-
cout << " [ ";
53+
*out_ << " [ ";
4654
for (auto f : *fields) {
47-
cout << f << ' ';
55+
*out_ << f << ' ';
4856
}
49-
cout << ']' << endl;
57+
*out_ << ']' << std::endl;
5058
} else {
51-
cout << " < all fields >" << endl;
59+
*out_ << " < all fields >" << std::endl;
5260
}
5361
return kOK;
5462
}
5563

5664
DB::Status BasicDB::Update(const std::string &table, const std::string &key,
5765
std::vector<Field> &values) {
5866
std::lock_guard<std::mutex> lock(mutex_);
59-
cout << "UPDATE " << table << ' ' << key << " [ ";
67+
*out_ << "UPDATE " << table << ' ' << key << " [ ";
6068
for (auto v : values) {
61-
cout << v.name << '=' << v.value << ' ';
69+
*out_ << v.name << '=' << v.value << ' ';
6270
}
63-
cout << ']' << endl;
71+
*out_ << ']' << std::endl;
6472
return kOK;
6573
}
6674

6775
DB::Status BasicDB::Insert(const std::string &table, const std::string &key,
6876
std::vector<Field> &values) {
6977
std::lock_guard<std::mutex> lock(mutex_);
70-
cout << "INSERT " << table << ' ' << key << " [ ";
78+
*out_ << "INSERT " << table << ' ' << key << " [ ";
7179
for (auto v : values) {
72-
cout << v.name << '=' << v.value << ' ';
80+
*out_ << v.name << '=' << v.value << ' ';
7381
}
74-
cout << ']' << endl;
82+
*out_ << ']' << std::endl;
7583
return kOK;
7684
}
7785

7886
DB::Status BasicDB::Delete(const std::string &table, const std::string &key) {
7987
std::lock_guard<std::mutex> lock(mutex_);
80-
cout << "DELETE " << table << ' ' << key << endl;
88+
*out_ << "DELETE " << table << ' ' << key << std::endl;
8189
return kOK;
8290
}
8391

core/basic_db.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define YCSB_C_BASIC_DB_H_
1111

1212
#include "db.h"
13-
#include "properties.h"
13+
#include "utils/properties.h"
1414

1515
#include <iostream>
1616
#include <string>
@@ -20,6 +20,8 @@ namespace ycsbc {
2020

2121
class BasicDB : public DB {
2222
public:
23+
BasicDB() : out_(nullptr) {}
24+
2325
void Init();
2426

2527
Status Read(const std::string &table, const std::string &key,
@@ -36,6 +38,8 @@ class BasicDB : public DB {
3638

3739
private:
3840
static std::mutex mutex_;
41+
42+
std::ostream *out_;
3943
};
4044

4145
DB *NewBasicDB();

core/client.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#ifndef YCSB_C_CLIENT_H_
1010
#define YCSB_C_CLIENT_H_
1111

12+
#include <iostream>
1213
#include <string>
14+
1315
#include "db.h"
1416
#include "core_workload.h"
15-
#include "utils.h"
16-
#include "countdown_latch.h"
17+
#include "utils/countdown_latch.h"
18+
#include "utils/utils.h"
1719

1820
namespace ycsbc {
1921

core/core_workload.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
// Modifications Copyright 2023 Chengye YU <yuchengye2013 AT outlook.com>.
88
//
99

10-
#include "utils.h"
1110
#include "uniform_generator.h"
1211
#include "zipfian_generator.h"
1312
#include "scrambled_zipfian_generator.h"
1413
#include "skewed_latest_generator.h"
1514
#include "const_generator.h"
1615
#include "core_workload.h"
1716
#include "random_byte_generator.h"
17+
#include "utils/utils.h"
1818

1919
#include <algorithm>
2020
#include <random>

core/core_workload.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include <vector>
1414
#include <string>
1515
#include "db.h"
16-
#include "properties.h"
1716
#include "generator.h"
1817
#include "discrete_generator.h"
1918
#include "counter_generator.h"
2019
#include "acknowledged_counter_generator.h"
21-
#include "utils.h"
20+
#include "utils/properties.h"
21+
#include "utils/utils.h"
2222

2323
namespace ycsbc {
2424

core/db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef YCSB_C_DB_H_
1010
#define YCSB_C_DB_H_
1111

12-
#include "properties.h"
12+
#include "utils/properties.h"
1313

1414
#include <vector>
1515
#include <string>

core/db_factory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "db.h"
1313
#include "measurements.h"
14-
#include "properties.h"
14+
#include "utils/properties.h"
1515

1616
#include <string>
1717
#include <map>

core/db_wrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
#include "db.h"
1515
#include "measurements.h"
16-
#include "timer.h"
17-
#include "utils.h"
16+
#include "utils/timer.h"
17+
#include "utils/utils.h"
1818

1919
namespace ycsbc {
2020

core/discrete_generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <atomic>
1515
#include <cassert>
1616
#include <vector>
17-
#include "utils.h"
17+
#include "utils/utils.h"
1818

1919
namespace ycsbc {
2020

0 commit comments

Comments
 (0)