-
Notifications
You must be signed in to change notification settings - Fork 0
/
BedrockConflictManager.cpp
66 lines (57 loc) · 2.56 KB
/
BedrockConflictManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "BedrockConflictManager.h"
#include <libstuff/libstuff.h>
BedrockConflictManager::BedrockConflictManager() {
}
void BedrockConflictManager::recordTables(const string& commandName, const set<string>& tables) {
{
lock_guard<mutex> lock(m);
auto commandInfoIt = _commandInfo.find(commandName);
if (commandInfoIt == _commandInfo.end()) {
commandInfoIt = _commandInfo.emplace(make_pair(commandName, BedrockConflictManagerCommandInfo())).first;
}
BedrockConflictManagerCommandInfo& commandInfo = commandInfoIt->second;
// Increase the count of the command in general.
commandInfo.count++;
// And for each table (that's not a journal).
for (auto& table : tables) {
// Skip journals, they change on every instance of a command running and thus aren't useful for profiling which commands access which tables most frequently.
if (SStartsWith(table, "journal")) {
continue;
}
if (table == "json_each") {
continue;
}
// Does this command already have this table?
auto tableInfoIt = commandInfo.tableUseCounts.find(table);
if (tableInfoIt == commandInfo.tableUseCounts.end()) {
tableInfoIt = commandInfo.tableUseCounts.emplace(make_pair(table, 1)).first;
} else {
// tableInfoIt is an iterator into a map<string, size_t> (tableUseCounts), where the key is the table name and the value is the count of uses for this command.
// Incrementing `second` increases the count.
tableInfoIt->second++;
}
}
}
// And increase the count for each used table.
SINFO("Command " << commandName << " used tables: " << SComposeList(tables));
}
string BedrockConflictManager::generateReport() {
stringstream out;
{
lock_guard<mutex> lock(m);
for (auto& p : _commandInfo) {
const string& commandName = p.first;
const BedrockConflictManagerCommandInfo& commandInfo = p.second;
out << "Command: " << commandName << endl;
out << "Total Count: " << commandInfo.count << endl;
out << "Table usage" << endl;
for (const auto& table : commandInfo.tableUseCounts) {
const string& tableName = table.first;
const size_t& count = table.second;
out << " " << tableName << ": " << count << endl;
}
out << endl;
}
}
return out.str();
}