Commit 3ca48bc6 authored by Philipp Götze's avatar Philipp Götze
Browse files

🔥 Removed manual profiling

parent 25ad6535
......@@ -14,7 +14,6 @@ if(NOT PROJECT_INSTALL_DIR)
endif()
option(ENABLE_LOG "enables log output for e.g. debugging" OFF)
option(ENABLE_PROFILING "enables profiling for some of the structures" OFF)
option(BUILD_TEST_CASES "build tests for functionality of structures" ON )
option(BUILD_GOOGLE_BENCH "build google benchmark" OFF)
option(BUILD_BENCHMARKS "build benchmarks for structures" ON )
......@@ -27,10 +26,6 @@ if(ENABLE_LOG)
add_definitions("-DENABLE_LOG")
endif()
if(ENABLE_PROFILING)
add_definitions("-DENABLE_PROFILING")
endif()
# Benchmark test requires benchmark library
if (BUILD_BENCHMARKS)
set(BUILD_GOOGLE_BENCH ON)
......
......@@ -103,7 +103,6 @@ int main(){
curr_test_size--;
keys[choosen_key] = keys[curr_test_size];
}
auto avg = std::accumulate(insert_measures.begin(), insert_measures.end(), 0) / insert_measures.size();
auto minmax = std::minmax_element(std::begin(insert_measures), std::end(insert_measures));
......@@ -111,9 +110,6 @@ int main(){
<< "\n\tAverage: \t" << avg
<< "\n\tMin: \t" << *minmax.first
<< "\n\tMax: \t" << *minmax.second << '\n';
#ifdef IDXPROFILE
pTable->printIdxProfile();
#endif
std::cout << "\n####################################\n";
//Lookup measures
......@@ -126,21 +122,18 @@ int main(){
std::cout << "Didn't find " << key << std::endl;
}
end = std::chrono::high_resolution_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
lookup_measures.push_back(diff);
}
avg = std::accumulate(lookup_measures.begin(), lookup_measures.end(), 0) / lookup_measures.size();
minmax = std::minmax_element(std::begin(lookup_measures), std::end(lookup_measures));
std::cout << "\nLookup Statistics in µs: "
<< "\n\tAverage: \t" << avg
<< "\n\tMin: \t" << *minmax.first
<< "\n\tMax: \t" << *minmax.second << '\n';
#ifdef IDXPROFILE
pTable->printIdxProfile();
#endif
std::cout << "\n####################################\n";
//Delete measures
......@@ -161,18 +154,14 @@ int main(){
if(i==3*TEST_SIZE/4){std::cout<<"Fortschritt: 75%"<<std::endl;}
curr_test_size--;
keys[choosen_key] = keys[curr_test_size];
}
avg = std::accumulate(delete_measures.begin(), delete_measures.end(), 0) / delete_measures.size();
minmax = std::minmax_element(std::begin(delete_measures), std::end(delete_measures));
std::cout << "\nDelete Statistics in µs: "
<< "\n\tAverage: \t" << avg
<< "\n\tMin: \t" << *minmax.first
<< "\n\tMax: \t" << *minmax.second << '\n';
#ifdef IDXPROFILE
pTable->printIdxProfile();
#endif
pop.close();
}
......
......@@ -8,26 +8,6 @@
#define LOG(msg)
#endif
#ifdef ENABLE_PROFILING
#include <memory>
#include <IdxProfile.hpp>
#define PROFILE_DECL std::unique_ptr<IdxProfile> profile;
#define PROFILE_INIT profile = std::make_unique<IdxProfile>();
#define PROFILE_READ(n) profile->read(n);
#define PROFILE_WRITE(n) profile->write(n);
#define PROFILE_SPLIT profile->split();
#define PROFILE_UNDERFLOW profile->underflow();
#define PROFILE_PRINT void printIdxProfile() { profile->print(); }
#else
#define PROFILE_DECL
#define PROFILE_INIT
#define PROFILE_READ(n)
#define PROFILE_WRITE(n)
#define PROFILE_SPLIT
#define PROFILE_UNDERFLOW
#define PROFILE_PRINT
#endif
namespace dbis {
const std::string gPmemPath("@PMEM_MNT_PATH@/");
}
......
......@@ -167,7 +167,6 @@ class FPTree {
return newNode;
}
void deleteLeafNode(persistent_ptr<LeafNode> node) {
auto pop = pmem::obj::pool_by_vptr(this);
transaction::run(pop, [&] {
......@@ -201,8 +200,6 @@ class FPTree {
Node rootNode; //< pointer to the root node
persistent_ptr<LeafNode> leafList; //<Pointer to the leaf at the most left position. Neccessary for recovery
PROFILE_DECL
public:
/**
* Typedef for a function passed to the scan method.
......@@ -266,7 +263,6 @@ class FPTree {
rootNode = newLeafNode();
leafList = rootNode.leaf;
depth = 0;
PROFILE_INIT
LOG("created new FPTree with sizeof(BranchNode) = " << sizeof(BranchNode)
<< ", sizeof(LeafNode) = " << sizeof(LeafNode));
}
......@@ -357,7 +353,6 @@ class FPTree {
auto node = rootNode.branch;
assert(node != nullptr);
result=eraseFromBranchNode(node, depth, key);
}
});
return result;
......@@ -412,8 +407,6 @@ class FPTree {
}
}
PROFILE_PRINT
/**
* Perform a scan over all key-value pairs stored in the tree.
* For each entry the given function @func is called.
......@@ -509,7 +502,6 @@ class FPTree {
else
insertInLeafNodeAtPosition(sibling, sibRef.search.get_ro().getFreeZero(), key, val);
/* inform the caller about the split */
splitRef.key = sibRef.keys.get_ro()[findMinKeyAtLeafNode(sibling)];
split = true;
......@@ -569,7 +561,6 @@ class FPTree {
splitRef.key = splitKey;
}
/**
* Insert a (key, value) pair at the given position @c pos into the leaf node
* @c node. The caller has to ensure that
......@@ -766,7 +757,6 @@ class FPTree {
return pos;
}
/**
* Delete the element with the given key from the given leaf node.
*
......@@ -945,14 +935,12 @@ class FPTree {
BranchNode *witnessNode = nullptr;
auto ppos = pos;
if (prevKeys > 0) {
mergeBranchNodes(lSibling, node->keys[pos - 1], child);
ppos = pos - 1;
witnessNode = child;
newChild = lSibling;
// pos -= 1;
} else if (nextKeys > 0) {
mergeBranchNodes(child, node->keys[pos], rSibling);
witnessNode = rSibling;
} else
......@@ -961,19 +949,15 @@ class FPTree {
// remove node->keys.get_ro()[pos] from node
for (auto i = ppos; i < node->numKeys - 1; i++) {
node->keys[i] = node->keys[i + 1];
}
if (pos == 0) pos++;
for (auto i = pos; i < node->numKeys; i++) {
if (i + 1 <= node->numKeys) {
node->children[i] = node->children[i + 1];
}
}
node->numKeys--;
deleteBranchNode(witnessNode);
return newChild;
}
......@@ -1314,7 +1298,6 @@ class FPTree {
auto child = node->children[k].leaf;
if (child != nullptr) printLeafNode(d + 1, child);
}
}
}
......
......@@ -217,8 +217,6 @@ class PTree {
LeafOrBranchNode rootNode; //< pointer to the root node
persistent_ptr<LeafNode> leafList; //<Pointer to the leaf at the most left position. Neccessary for recovery
PROFILE_DECL
public:
/**
* Typedef for a function passed to the scan method.
......@@ -284,7 +282,6 @@ class PTree {
rootNode = newLeafNode();
leafList = rootNode.leaf;
depth = 0;
PROFILE_INIT
}
/**
......@@ -340,7 +337,6 @@ class PTree {
root->numKeys = root->numKeys + 1;
rootNode.branch = root;
depth = depth + 1;
}
}
});
......@@ -397,7 +393,6 @@ class PTree {
auto node = rootNode.branch;
assert(node != nullptr);
result=eraseFromBranchNode(node, depth, key);
}
});
return result;
......@@ -441,7 +436,6 @@ class PTree {
}
}
PROFILE_PRINT
/**
* Perform a scan over all key-value pairs stored in the tree.
......@@ -788,7 +782,6 @@ class PTree {
const unsigned int num = node->numKeys.get_ro();
for (; pos < num && node->keys.get_ro()[pos] < key; pos++) {
};
return pos;
}
......@@ -812,7 +805,6 @@ class PTree {
unsigned int pos = 0;
const unsigned int num = node->numKeys;
for (; pos < num && node->keys[pos] <= key; pos++) {
};
return pos;
}
......@@ -836,7 +828,6 @@ class PTree {
unsigned int pos = 0;
const unsigned int num = node->numKeys;
for (; pos < num && node->keys[pos] <= key; pos++) {
};
return pos;
}
......@@ -1612,7 +1603,6 @@ class PTree {
auto child = node->children[k].lowestbranch;
if (child != nullptr) printLowestBranchNode(d + 1, child);
}
}
}
......
......@@ -175,7 +175,6 @@ class BitPBPTree {
/// traverse to left-most key
auto node = root;
while (d-- > 0) {
PROFILE_READ(1)
node = node.branch->children.get_ro()[0];
}
currentNode = node.leaf;
......@@ -191,13 +190,10 @@ class BitPBPTree {
currentPosition = 0;
if (currentNode == nullptr) return *this;
const auto &nodeRef = *currentNode;
PROFILE_READ(1)
while(!nodeRef.bits.get_ro().test(currentPosition)) {
PROFILE_READ(1)
++currentPosition;
};
} else {
PROFILE_READ(1)
if (!currentNode->bits.get_ro().test(++currentPosition)) ++(*this);
}
return *this;
......@@ -216,7 +212,6 @@ class BitPBPTree {
bool operator!=(iterator other) const { return !(*this == other); }
std::pair<KeyType, ValueType> operator*() {
PROFILE_READ(2)
return std::make_pair(currentNode->keys.get_ro()[currentPosition],
currentNode->values.get_ro()[currentPosition]);
}
......@@ -233,7 +228,6 @@ class BitPBPTree {
iterator end() { return iterator(); }
PROFILE_DECL
/**
* Alias for a function passed to the scan method.
......@@ -245,7 +239,6 @@ class BitPBPTree {
*/
BitPBPTree() : depth(0) {
rootNode = newLeafNode();
PROFILE_INIT
LOG("created new tree with sizeof(BranchNode) = " << sizeof(BranchNode) <<
", sizeof(LeafNode) = " << sizeof(LeafNode));
}
......@@ -281,8 +274,6 @@ class BitPBPTree {
/// we had an overflow in the node and therefore the node is split
auto root = newBranchNode();
auto &rootRef = *root;
PROFILE_READ(1)
PROFILE_WRITE(5)
rootRef.keys.get_rw()[0] = splitInfo.key;
rootRef.children.get_rw()[0] = splitInfo.leftChild;
rootRef.children.get_rw()[N] = splitInfo.rightChild;
......@@ -307,7 +298,6 @@ class BitPBPTree {
const auto pos = lookupPositionInLeafNode(leafNode, key);
if (pos < M) {
/// we found it
PROFILE_READ(1)
*val = leafNode->values.get_ro()[pos];
return true;
}
......@@ -351,7 +341,6 @@ class BitPBPTree {
else printBranchNode(0u, rootNode.branch);
}
PROFILE_PRINT
/**
* Perform a scan over all key-value pairs stored in the B+ tree.
......@@ -362,11 +351,9 @@ class BitPBPTree {
void scan(ScanFunc func) const {
/// we traverse to the leftmost leaf node
auto node = rootNode;
PROFILE_READ(1)
auto d = depth.get_ro();
while (d-- > 0) {
/// as long as we aren't at the leaf level we follow the path down
PROFILE_READ(1)
node = node.branch->children.get_ro()[0];
}
auto leaf = node.leaf;
......@@ -374,9 +361,7 @@ class BitPBPTree {
const auto &leafRef = *leaf;
/// for each key-value pair call func
for (auto i = 0u; i < M; i++) {
PROFILE_READ(1)
if (!leafRef.bits.get_ro().test(i)) continue;
PROFILE_READ(2)
const auto &key = leafRef.keys.get_ro()[i];
const auto &val = leafRef.values.get_ro()[i];
func(key, val);
......@@ -402,15 +387,12 @@ class BitPBPTree {
/// for each key-value pair within the range call func
const auto &leafRef = *leaf;
for (auto i = 0u; i < M; i++) {
PROFILE_READ(1)
if (leafRef.bits.get_ro().test(i)) continue;
PROFILE_READ(1)
const auto &key = leafRef.keys.get_ro()[i];
if (key < minKey) continue;
if (key > maxKey) { higherThanMax = true; continue; };
PROFILE_READ(1)
const auto &val = leafRef.values.get_ro()[i];
func(key, val);
}
......@@ -436,10 +418,7 @@ class BitPBPTree {
bool eraseFromLeafNode(const pptr<LeafNode> &node, const KeyType &key) {
auto pos = lookupPositionInLeafNode(node, key);
auto &nodeRef = *node;
PROFILE_READ(1)
if (nodeRef.keys.get_ro()[pos] == key) {
PROFILE_READ(1)
PROFILE_WRITE(1)
/// simply reset bit
nodeRef.bits.get_rw().reset(pos);
return true;
......@@ -462,7 +441,6 @@ class BitPBPTree {
assert(pos <= M);
auto &nodeRef = *node;
const auto &leafRef = *leaf;
PROFILE_READ(1)
const auto prevNumKeys = leafRef.prevLeaf->bits.get_ro().count();
constexpr auto middle = (M + 1) / 2;
......@@ -471,8 +449,6 @@ class BitPBPTree {
if (pos > 0 && prevNumKeys > middle) {
/// we have a sibling at the left for rebalancing the keys
balanceLeafNodes(leafRef.prevLeaf, leaf);
PROFILE_READ(1)
PROFILE_WRITE(1)
const auto newMin = leafRef.keys.get_ro()[findMinKeyInNode(leaf)];
const auto prevPos = findMinKeyGreaterThan(leaf, newMin);
nodeRef.keys.get_rw()[prevPos] = newMin;
......@@ -480,8 +456,6 @@ class BitPBPTree {
leafRef.nextLeaf->bits.get_ro().count() > middle) {
/// we have a sibling at the right for rebalancing the keys
balanceLeafNodes(leafRef.nextLeaf, leaf);
PROFILE_READ(1)
PROFILE_WRITE(1)
nodeRef.keys.get_rw()[pos] =
leafRef.nextLeaf->keys.get_ro()[findMinKeyInNode(leafRef.nextLeaf)];
} else {
......@@ -494,17 +468,12 @@ class BitPBPTree {
/// merge left
survivor = mergeLeafNodes(leafRef.prevLeaf, leaf);
deleteLeafNode(leaf);
PROFILE_READ(1)
PROFILE_WRITE(1)
nodeRef.children.get_rw()[pos] = survivor;
if (pos == N) {
PROFILE_READ(1)
PROFILE_WRITE(2)
const auto prevPos = findMaxKeyInNode(node);
nodeRef.bits.get_rw().reset(prevPos);
nodeRef.children.get_rw()[N] = nodeRef.children.get_ro()[prevPos];
} else {
PROFILE_WRITE(1)
const auto prevPos = findMaxKeySmallerThan(node, nodeRef.keys.get_ro()[pos]);
nodeRef.bits.get_rw().reset(prevPos);
}
......@@ -513,7 +482,6 @@ class BitPBPTree {
/// because we update the pointers in mergeLeafNodes we keep it here
survivor = mergeLeafNodes(leaf, leafRef.nextLeaf);
deleteLeafNode(leafRef.nextLeaf);
PROFILE_WRITE(1)
nodeRef.bits.get_rw().reset(pos);
} else {
/// this shouldn't happen?!
......@@ -523,8 +491,6 @@ class BitPBPTree {
/// This is a special case that happens only if the current node is the root node. Now, we
/// have to replace the branch root node by a leaf node.
rootNode = survivor;
PROFILE_READ(1)
PROFILE_WRITE(1)
depth.get_rw() = depth.get_ro() - 1;
}
}
......@@ -546,10 +512,7 @@ class BitPBPTree {
/// we move all keys/values from node2 to node1
for (auto i = 0u; i < M; i++) {
PROFILE_READ(1)
if (node2Ref.bits.get_ro().test(i)) {
PROFILE_READ(3)
PROFILE_WRITE(3)
const auto u = getFreeZero(node1Ref.bits.get_ro());
node1Ref.keys.get_rw()[u] = node2Ref.keys.get_ro()[i];
node1Ref.values.get_rw()[u] = node2Ref.values.get_ro()[i];
......@@ -572,7 +535,6 @@ class BitPBPTree {
void balanceLeafNodes(const pptr<LeafNode> &donor, const pptr<LeafNode> &receiver) {
auto &donorRef = *donor;
auto &receiverRef = *receiver;
PROFILE_READ(2)
const auto dNumKeys = donorRef.bits.get_ro().count();
const auto rNumKeys = receiverRef.bits.get_ro().count();
assert(dNumKeys > rNumKeys);
......@@ -581,12 +543,9 @@ class BitPBPTree {
const auto toMove = dNumKeys - balancedNum;
if (toMove == 0) return;
PROFILE_READ(2)
if (donorRef.keys.get_ro()[0] < receiverRef.keys.get_ro()[0]) {
/// move from one node to a node with larger keys
for (auto i = 0u; i < toMove; i++) {
PROFILE_READ(3)
PROFILE_WRITE(4)
const auto max = findMaxKeyInNode(donor);
const auto u = getFreeZero(receiverRef.bits.get_ro());
/// move the donor's maximum key to the receiver
......@@ -601,8 +560,6 @@ class BitPBPTree {
const auto min = findMinKeyInNode(donor);
const auto u = getFreeZero(receiverRef.bits.get_ro());
/// move the donor's minimum key to the receiver
PROFILE_READ(3)
PROFILE_WRITE(4)
receiverRef.keys.get_rw()[u] = donorRef.keys.get_ro()[min];
receiverRef.values.get_rw()[u] = donorRef.values.get_ro()[min];
receiverRef.bits.get_rw().set(u);
......@@ -629,7 +586,6 @@ class BitPBPTree {
bool deleted = false;
/// try to find the branch
auto pos = lookupPositionInBranchNode(node, key);
PROFILE_READ(1)
const auto n = nodeRef.children.get_ro()[pos];
if (d == 1) {
/// the next level is the leaf level
......@@ -638,7 +594,6 @@ class BitPBPTree {
constexpr auto middle = (M + 1) / 2;
if (leaf->bits.get_ro().count() < middle) {
/// handle underflow
PROFILE_UNDERFLOW
underflowAtLeafLevel(node, pos, leaf);
}
} else {
......@@ -649,13 +604,10 @@ class BitPBPTree {
constexpr auto middle = (N + 1) / 2;
if (child->bits.get_ro().count() < middle) {
/// handle underflow
PROFILE_UNDERFLOW
child = underflowAtBranchLevel(node, pos, child);
if (d == depth && nodeRef.bits.get_ro().count() == 0) {
/// special case: the root node is empty now
rootNode = child;
PROFILE_READ(1)
PROFILE_WRITE(1)
depth.get_rw() = depth.get_ro() - 1;
}
}
......@@ -677,29 +629,21 @@ class BitPBPTree {
assert(node != nullptr);
const auto &nodeRef = *node;
auto &sibRef = *sibling;
PROFILE_READ(2)
assert(key <= nodeRef.keys.get_ro()[findMinKeyInNode(node)]);
assert(sibRef.keys.get_ro()[findMaxKeyInNode(sibling)] < key);
PROFILE_READ(3)
PROFILE_WRITE(3)
const auto u = getFreeZero(sibRef.bits.get_ro());
sibRef.keys.get_rw()[u] = key;
sibRef.children.get_rw()[u] = sibRef.children.get_ro()[N];
sibRef.bits.get_rw().set(u);
for (auto i = 0u; i < M; i++) {
PROFILE_READ(1)
if (nodeRef.bits.get_ro().test(i)) {
PROFILE_READ(3)
PROFILE_WRITE(3)
const auto u = getFreeZero(sibRef.bits.get_ro());
sibRef.keys.get_rw()[u] = nodeRef.keys.get_ro()[i];
sibRef.children.get_rw()[u] = nodeRef.children.get_ro()[i];
sibRef.bits.get_rw().set(u);
}
}
PROFILE_READ(1)
PROFILE_WRITE(1)
sibRef.children.get_rw()[N] = nodeRef.children.get_ro()[N];
}
......@@ -720,7 +664,6 @@ class BitPBPTree {
assert(node != nullptr);
assert(child != nullptr);
auto &nodeRef = *node;
PROFILE_READ(5)
const auto &nNumKeys = nodeRef.bits.get_ro().count();
const auto prevPos = findMaxKeySmallerThan(node, nodeRef.keys.get_ro()[pos]);
const auto prevNumKeys = nodeRef.children.get_ro()[prevPos].branch->bits.get_ro().count();
......@@ -732,17 +675,14 @@ class BitPBPTree {
/// 1. we check whether we can rebalance with one of the siblings
if (pos > 0 && prevNumKeys > middle) {
/// we have a sibling at the left for rebalancing the keys
PROFILE_READ(1)
const auto sibling = (nodeRef.children.get_ro()[prevPos]).branch;
balanceBranchNodes(sibling, child, node, pos);
return newChild;
} else if (pos < nNumKeys) {
PROFILE_READ(3)
nextPos = findMinKeyGreaterThan(node, nodeRef.keys.get_ro()[pos]);
nextNumKeys = nodeRef.children.get_ro()[nextPos].branch->bits.get_ro().count();
/// we have a sibling at the right for rebalancing the keys
if (nextNumKeys > middle) {
PROFILE_READ(1)
auto sibling = (nodeRef.children.get_ro()[nextPos]).branch;
balanceBranchNodes(sibling, child, node, pos);
return newChild;
......@@ -753,30 +693,25 @@ class BitPBPTree {
auto prevKeys = 0u, nextKeys = 0u;
if (pos > 0) {
PROFILE_READ(1)
lSibling = (nodeRef.children.get_ro()[prevPos]).branch;
prevKeys = prevNumKeys;
}
if (pos < nNumKeys) {
PROFILE_READ(1)
rSibling = (nodeRef.children.get_ro()[nextPos]).branch;
nextKeys = nextNumKeys;
}
pptr<BranchNode> witnessNode = nullptr;
if (prevKeys > 0) {
PROFILE_READ(1)
mergeBranchNodes(lSibling, nodeRef.keys.get_ro()[pos], child);
witnessNode = child;
newChild = lSibling;
} else if (nextKeys > 0) {
PROFILE_READ(1)
mergeBranchNodes(child, nodeRef.keys.get_ro()[pos], rSibling);
witnessNode = rSibling;
} else assert(false); ///< shouldn't happen
/// cleanup node
PROFILE_WRITE(2)
nodeRef.bits.get_rw().reset(pos);
if (pos == nNumKeys) nodeRef.children.get_rw()[N] = child; ///< new rightmost child
......@@ -799,7 +734,6 @@ class BitPBPTree {
auto &donorRef = *donor;
auto &receiverRef = *receiver;
auto &parentRef = *parent;
PROFILE_READ(2)
const auto dNumKeys = donorRef.bits.get_ro().count();
const auto rNumKeys = receiverRef.bits.get_ro().count();
assert(dNumKeys > rNumKeys);
......@@ -809,10 +743,7 @@ class BitPBPTree {
if (toMove == 0) return;
/// 1. move from one node to a node with larger keys
PROFILE_READ(2)
if (donorRef.keys.get_ro()[0] < receiverRef.keys.get_ro()[0]) { //TODO: bit check necessary?
PROFILE_READ(3 * toMove + 2)
PROFILE_WRITE(4 * toMove + 2)
/// 1.1. copy parent key and rightmost child of receiver
const auto u = getFreeZero(receiverRef.bits.get_ro());
receiverRef.keys.get_rw()[u] = parentRef.keys.get_ro()[pos];
......@@ -835,8 +766,6 @@ class BitPBPTree {